本文整理了Java中javax.jcr.Node.addNode()
方法的一些代码示例,展示了Node.addNode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.addNode()
方法的具体详情如下:
包路径:javax.jcr.Node
类名称:Node
方法名:addNode
[英]Creates a new node at relPath
.
This is session-write method, meaning that the addition of the new node is dispatch upon Session#save.
The relPath
provided must not have an index on its final element, otherwise a Repository
If ordering is supported by the node type of the parent node of the new node then the new node is appended to the end of the child node list.
The new node's primary node type will be determined by the child node definitions in the node types of its parent. This may occur either immediately, on dispatch (save, whether within or without transactions) or on persist (save without transactions, commit within a transaction), depending on the implementation.
An ItemExistsException
will be thrown either immediately, on dispatch (save, whether within or without transactions) or on persist (save without transactions, commit within a transaction), if an item at the specified path already exists and same-name siblings are not allowed. Implementations may differ on when this validation is performed.
A PathNotFoundException
will be thrown either immediately, on dispatch (save, whether within or without transactions) or on persist (save without transactions, commit within a transaction), if the specified path implies intermediary nodes that do not exist. Implementations may differ on when this validation is performed.
A ConstraintViolationException
will be thrown either immediately, on dispatch (save, whether within or without transactions) or on persist (save without transactions, commit within a transaction), if adding the node would violate a node type or implementation-specific constraint or if an attempt is made to add a node as the child of a property. Implementations may differ on when this validation is performed.
A VersionException
will be thrown either immediately, on dispatch (save, whether within or without transactions) or on persist (save without transactions, commit within a transaction), if the node to which the new child is being added is read-only due to a checked-in node. Implementations may differ on when this validation is performed.
A LockException
will be thrown either immediately, on dispatch (save, whether within or without transactions) or on persist (save without transactions, commit within a transaction), if a lock prevents the addition of the node. Implementations may differ on when this validation is performed.
[中]在[$0$]处创建一个新节点。
这是会话写入方法,意味着新节点的添加是在会话#保存时分派。
提供的relPath
不能在其最后一个元素上有索引,否则将创建一个存储库
如果新节点的父节点的节点类型支持排序,则新节点将附加到子节点列表的末尾。
新节点的主节点类型将由其父节点类型中的子节点定义确定。这可能会立即发生,在分派时(保存,无论是否包含事务)或在持久化时(保存而不包含事务,在事务中提交),具体取决于实现。
如果指定路径上的项目已存在且不允许同名同级,则在分派(保存,无论是否包含事务)或持久化(保存,不包含事务,在事务中提交)时会立即抛出ItemExistsException
。执行此验证的时间可能会有所不同。
如果指定的路径暗示中间节点不存在,则在分派时(保存,无论是否包含事务)或在持久化时(保存而不包含事务,在事务中提交),将立即抛出PathNotFoundException
。执行此验证的时间可能会有所不同。
如果添加节点会违反节点类型或特定于实现的约束,或者尝试将节点添加为属性的子级,则在分派(保存,无论是否包含事务)或持久化(保存,不包含事务,在事务中提交)时,会立即抛出ConstraintViolationException
。执行此验证的时间可能会有所不同。
如果要添加新子节点的节点由于签入节点而为只读,则在分派(保存,无论是否包含事务)或持久化(保存,不包含事务,在事务中提交)时,会立即抛出VersionException
。执行此验证的时间可能会有所不同。
如果锁阻止添加节点,则LockException
将在分派时(保存,无论是否包含事务)或持久化时(保存而不包含事务,在事务中提交)立即抛出。执行此验证的时间可能会有所不同。
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public MgnlRole doExec(Session session) throws RepositoryException {
String parentPath = StringUtils.defaultString(path, "/");
Node roleNode = session.getNode(parentPath).addNode(name, NodeTypes.Role.NAME);
final Node acls = roleNode.addNode(NODE_ACLROLES, NodeTypes.ContentNode.NAME);
// read only access to the role itself
Node acl = acls.addNode(nodeNameHelper.getUniqueName(session, acls.getPath(), "0"), NodeTypes.ContentNode.NAME);
acl.setProperty("path", roleNode.getPath());
acl.setProperty("permissions", Permission.READ);
session.save();
return newRoleInstance(roleNode);
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test
public void testWorkspaceReturnsLogicalName4() throws RepositoryException {
// GIVEN
Node root = MgnlContext.getJCRSession("magnolia-mgnlSystem").getRootNode();
root.addNode("test", NodeTypes.ContentNode.NAME).setProperty("testProp", "testVal");
root.getSession().save();
// WHEN
String name = root.getNode("test").getProperty("testProp").getParent().getSession().getWorkspace().getName();
// THEN
assertTrue(name.equals("magnolia-mgnlSystem"));
}
代码示例来源:origin: info.magnolia/magnolia-core
@Test
public void testWorkspaceReturnsLogicalName3() throws RepositoryException {
// GIVEN
Node root = MgnlContext.getJCRSession("magnolia-mgnlSystem").getRootNode();
root.addNode("test", NodeTypes.ContentNode.NAME).setProperty("testProp", "testVal");
root.getSession().save();
// WHEN
String name = root.getNode("test").getProperty("testProp").getSession().getWorkspace().getName();
// THEN
assertTrue(name.equals("magnolia-mgnlSystem"));
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests if the path of the created node is correct.
*/
public void testPath() throws RepositoryException {
Node n1 = testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
String expected = testRootNode.getPath() + "/" + nodeName1;
assertEquals("Wrong path for created node.", expected, n1.getPath());
}
代码示例来源:origin: apache/jackrabbit-oak
public TestContext() throws RepositoryException {
dump = session.getRootNode()
.addNode(nextNodeName(), NT_OAK_UNSTRUCTURED)
.addNode(nextNodeName(), NT_OAK_UNSTRUCTURED);
session.save();
paths.add(dump.getPath());
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests if text() node test is equivalent with jcr:xmltext.
* @throws NotExecutableException
*/
public void testTextNodeTest() throws RepositoryException, NotExecutableException {
Node text1 = testRootNode.addNode(jcrXMLText);
text1.setProperty(jcrXMLCharacters, "foo");
testRootNode.getSession().save();
String xpath = "/" + jcrRoot + testRoot + "/text()";
executeXPathQuery(superuser, xpath, new Node[]{text1});
}
代码示例来源:origin: info.magnolia/magnolia-core
private Node addWrite(String parentPath, String property, Node acls) throws PathNotFoundException, RepositoryException, AccessDeniedException {
Node acl = acls.addNode(nodeNameHelper.getUniqueName(acls.getSession(), acls.getPath(), "0"), NodeTypes.ContentNode.NAME);
acl.setProperty("path", parentPath + "/" + property);
acl.setProperty("permissions", Permission.ALL);
return acl;
}
代码示例来源:origin: apache/jackrabbit
protected void setUp() throws Exception {
super.setUp();
adminSession = superuser;
readOnlySession = getHelper().getReadOnlySession();
removeNode = testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
nPath = removeNode.getPath();
}
代码示例来源:origin: apache/jackrabbit-oak
@Override
protected void beforeSuite() throws Exception {
session = loginWriter();
testRoot = session.getRootNode().addNode(
getClass().getSimpleName() + TEST_ID, "nt:unstructured");
Node n = testRoot.addNode("node1");
path = n.getPath();
addAccessControlEntry(session, n.getPath(),
EveryonePrincipal.getInstance(), new String[] { JCR_READ },
true);
session.save();
testRoot = loginWriter().getNode(testRoot.getPath());
acm = testRoot.getSession().getAccessControlManager();
}
代码示例来源:origin: apache/jackrabbit
/**
* Test if Item.isNew() returns false after a NodeItem is added and
* the node is saved (persistent).
*
* @see javax.jcr.Item#isNew()
*/
public void testPersistentNodeItemIsNew () throws RepositoryException {
Node testNode = testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
Item testNodeItem = superuser.getItem(testNode.getPath());
// check testNodeItem is new after save
assertFalse("Item.isNew() must return false after a new NodeItem is added and the parent Node is saved", testNodeItem.isNew());
}
代码示例来源:origin: apache/jackrabbit
protected void setUp() throws Exception {
super.setUp();
// check for lock support
if (Boolean.FALSE.toString().equals(superuser.getRepository().getDescriptor(Repository.OPTION_LOCKING_SUPPORTED))) {
throw new NotExecutableException();
}
testNode = testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
testPath = testNode.getPath();
openScopedLockMultiple = Boolean.TRUE.toString()
.equals(getProperty(RepositoryStub.PROP_OPEN_SCOPED_LOCK_MULTIPLE, Boolean.FALSE.toString()));
lockMgr = getLockManager(superuser);
}
代码示例来源:origin: apache/jackrabbit
/**
* @throws RepositoryException
*/
public void testFrozenChildNodeUUUID() throws RepositoryException {
versionableNode.addNode("child");
versionableNode.getSession().save();
VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
String path = versionableNode.getPath();
Version v = versionManager.checkin(path);
Node n = v.getFrozenNode().getNode("child");
String puuid = n.getProperty(jcrUUID).getValue().getString();
String nuuid = n.getIdentifier();
assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid);
}
代码示例来源:origin: apache/jackrabbit
protected void setUp() throws Exception {
super.setUp();
Node n = testRootNode.addNode(nodeName1, testNodeType);
testNodePath = n.getPath();
Value v = getJcrValue(superuser, RepositoryStub.PROP_PROP_VALUE1, RepositoryStub.PROP_PROP_TYPE1, "test");
Property p = n.setProperty(propertyName1, v);
testPropertyPath = p.getPath();
testRootNode.getSession().save();
readOnlySession = getHelper().getReadOnlySession();
}
代码示例来源:origin: apache/jackrabbit
@Override
public void setUp() throws Exception {
super.setUp();
Node folder1 = testRootNode.addNode("folder1");
folder1Path = folder1.getPath();
Node folder2 = testRootNode.addNode("folder2");
folder2Path = folder2.getPath();
folder1.addNode("node");
testRootNode.getSession().save();
}
代码示例来源:origin: apache/jackrabbit
/**
* @throws RepositoryException
*/
public void testFrozenChildNodeUUUID() throws RepositoryException {
versionableNode.addNode("child");
versionableNode.getSession().save();
VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
String path = versionableNode.getPath();
Version v = versionManager.checkin(path);
Node n = v.getFrozenNode().getNode("child");
String puuid = n.getProperty(jcrUUID).getValue().getString();
String nuuid = n.getIdentifier();
assertEquals("jcr:uuid needs to be equal to the getIdentifier() return value.", nuuid, puuid);
}
代码示例来源:origin: apache/jackrabbit
@Override
public void setUp() throws Exception {
super.setUp();
Node folder1 = testRootNode.addNode("folder1");
folder1Path = folder1.getPath();
Node folder2 = testRootNode.addNode("folder2");
folder2Path = folder2.getPath();
folder1.addNode("node1");
testRootNode.getSession().save();
}
代码示例来源:origin: info.magnolia/magnolia-core
private void prepareGroupData() throws Exception {
String peopleGroup = "people";
String employeesGroup = "employees";
String developersGroup = "developers";
// Create a group (developers) which has an assigned group (employees) which again has an assigned group (people)
final Node developersNode = session.getRootNode().addNode(developersGroup, NodeTypes.Group.NAME);
final Node employeesNode = session.getRootNode().addNode(employeesGroup, NodeTypes.Group.NAME);
final Node peopleNode = session.getRootNode().addNode(peopleGroup, NodeTypes.Group.NAME);
developersNode.addNode(RepositoryBackedSecurityManager.GROUPS_NODE_NAME, NodeTypes.ContentNode.NAME).setProperty("0", employeesNode.getIdentifier());
employeesNode.addNode(RepositoryBackedSecurityManager.GROUPS_NODE_NAME, NodeTypes.ContentNode.NAME).setProperty("0", peopleNode.getIdentifier());
session.save();
}
代码示例来源:origin: apache/jackrabbit
public void testNodeMoved() throws RepositoryException {
final Node n = testRootNode.addNode(nodeName1, testNodeType);
testRootNode.getSession().save();
Event[] events = getEvents(new Callable(){
public void call() throws RepositoryException {
superuser.getWorkspace().move(n.getPath(), testRoot + "/" + nodeName2);
}
}, Event.NODE_MOVED);
String path = testRootNode.getNode(nodeName2).getPath();
assertEquals(n.getIdentifier(), getEventByPath(events, path).getIdentifier());
}
代码示例来源:origin: apache/jackrabbit
/**
* @throws RepositoryException
*/
public void testFrozenChildNodeNodeType() throws RepositoryException {
versionableNode.addNode("child");
versionableNode.getSession().save();
VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
String path = versionableNode.getPath();
Version v = versionManager.checkin(path);
Node n = v.getFrozenNode().getNode("child");
String puuid = n.getProperty(jcrPrimaryType).getValue().getString();
String nuuid = n.getPrimaryNodeType().getName();
assertEquals("jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.", nuuid, puuid);
}
代码示例来源:origin: apache/jackrabbit
/**
* @throws RepositoryException
*/
public void testFrozenChildNodeNodeType() throws RepositoryException {
versionableNode.addNode("child");
versionableNode.getSession().save();
VersionManager versionManager = versionableNode.getSession().getWorkspace().getVersionManager();
String path = versionableNode.getPath();
Version v = versionManager.checkin(path);
Node n = v.getFrozenNode().getNode("child");
String puuid = n.getProperty(jcrPrimaryType).getValue().getString();
String nuuid = n.getPrimaryNodeType().getName();
assertEquals("jcr:primaryType needs to be equal to the getPrimaryNodeType() return value.", nuuid, puuid);
}
内容来源于网络,如有侵权,请联系作者删除!