本文整理了Java中javax.jcr.query.Query.storeAsNode
方法的一些代码示例,展示了Query.storeAsNode
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.storeAsNode
方法的具体详情如下:
包路径:javax.jcr.query.Query
类名称:Query
方法名:storeAsNode
[英]Creates a node of type nt:query
holding this query at absPath
and returns that node.
This is a session-write method and therefore requires a Session.save()
to dispatch the change.
The absPath
provided must not have an index on its final element. If ordering is supported by the node type of the parent node then the new node is appended to the end of the child node list.
An ItemExistsException
will be thrown either immediately, on dispatch or on persists, 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 or on persists, 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 or on persists, 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 or on persists, 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 or on persists, if a lock prevents the addition of the node. Implementations may differ on when this validation is performed.
[中]创建类型为nt:query
的节点,将此查询保存在absPath
并返回该节点。
这是一种会话写入方法,因此需要Session.save()
来分派更改。
提供的absPath
不能在其最后一个元素上有索引。如果父节点的节点类型支持排序,则新节点将附加到子节点列表的末尾。
如果指定路径上的项目已经存在,并且不允许使用同名同级,则在分派时或持续存在时会立即抛出ItemExistsException
。执行此验证的时间可能会有所不同。
如果指定的路径意味着不存在中间节点,则在分派或持久化时会立即抛出PathNotFoundException
。执行此验证的时间可能会有所不同。
如果添加节点会违反节点类型或特定于实现的约束,或者尝试将节点添加为属性的子级,则ConstraintViolationException
将立即在分派时或在持续时抛出。执行此验证的时间可能会有所不同。
如果要向其添加新子节点的节点由于签入节点而为只读,则VersionException
将在分派时或持续时立即抛出。执行此验证的时间可能会有所不同。
如果锁阻止添加节点,则在分派或持续时会立即抛出LockException
。执行此验证的时间可能会有所不同。
代码示例来源:origin: info.magnolia/magnolia-core
@Override
public Node storeAsNode(String s) throws ItemExistsException, PathNotFoundException, VersionException,
ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
return this.query.storeAsNode(s);
}
}
代码示例来源:origin: org.onehippo.cms7/hippo-repository-connector
/**
* @inheritDoc
*/
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException,
ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
Node node = query.storeAsNode(absPath);
return node;
}
代码示例来源:origin: apache/jackrabbit
/** {@inheritDoc} */
public RemoteNode storeAsNode(String absPath)
throws RepositoryException, RemoteException {
return getRemoteNode(query.storeAsNode(absPath));
}
代码示例来源:origin: brix-cms/brix-cms
public JcrNode execute() throws Exception {
return JcrNode.Wrapper.wrap(getDelegate().storeAsNode(absPath), getJcrSession());
}
});
代码示例来源:origin: apache/jackrabbit
/**
* Tests if a {@link javax.jcr.nodetype.ConstraintViolationException} is
* thrown if a query is stored under a node which does not allow child nodes.
* <p>
* The test creates a node <code>nodeName1</code> of type <code>testNodeType</code>
* under <code>testRoot</code>. Then the test tries to store a query as
* <code>nodeName2</code> under <code>nodeName1</code>.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testConstraintViolationException() throws RepositoryException, NotExecutableException {
checkNtQuery();
Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
testRootNode.addNode(nodeName1, testNodeTypeNoChildren);
try {
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
superuser.save();
fail("Query.storeAsNode() must throw ConstraintViolationException, parent node does not allow child nodes.");
} catch (ConstraintViolationException e) {
// expected behaviour
}
}
代码示例来源:origin: brix-cms/brix-cms
public Node storeAsNode(String absPath) throws RepositoryException {
return NodeWrapper.wrap(getDelegate().storeAsNode(absPath), getSessionWrapper());
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests if a {@link javax.jcr.PathNotFoundException} is thrown when a query
* is stored to a non existent path.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testPathNotFoundException() throws RepositoryException, NotExecutableException {
checkNtQuery();
Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
try {
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName1);
fail("Query.storeAsNode() must throw PathNotFoundException on invalid path");
} catch (PathNotFoundException e) {
// expected behaviour
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests if the a {@link javax.jcr.RepositoryException} is thrown when
* an malformed path is passed in {@link javax.jcr.query.Query#storeAsNode(String)}.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testRepositoryException() throws RepositoryException, NotExecutableException {
checkNtQuery();
Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
try {
query.storeAsNode(testRoot + "/invalid[42]");
fail("Query.storeAsNode() must throw RepositoryException on malformed path.");
} catch (RepositoryException e) {
// expected behaviour
}
}
代码示例来源:origin: apache/jackrabbit
/**
* Stores a {@link javax.jcr.query.Query#XPATH} query at:
* <code>testRoot + "/" + nodeName1</code>.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testSave() throws RepositoryException, NotExecutableException {
checkNtQuery();
Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
query.storeAsNode(testRoot + "/" + nodeName1);
assertTrue("Node has not been stored", testRootNode.hasNode(nodeName1));
Node queryNode = testRootNode.getNode(nodeName1);
assertTrue("Query node is not of type nt:query", queryNode.isNodeType(ntQuery));
Query query2 = superuser.getWorkspace().getQueryManager().getQuery(queryNode);
assertEquals("Persisted query does not match initial query.", query.getStatement(), query2.getStatement());
}
代码示例来源:origin: apache/jackrabbit
/**
* Tests if {@link Query#getStoredQueryPath()} returns the correct path
* where the query had been saved.
*
* @throws NotExecutableException if the repository does not support the
* node type nt:query.
*/
public void testGetPersistentQueryPath() throws RepositoryException, NotExecutableException {
try {
superuser.getWorkspace().getNodeTypeManager().getNodeType(ntQuery);
} catch (NoSuchNodeTypeException e) {
// not supported
throw new NotExecutableException("repository does not support nt:query");
}
String statement = "/" + jcrRoot;
Query q = superuser.getWorkspace().getQueryManager().createQuery(statement, qsXPATH);
String path = testRoot + "/" + nodeName1;
q.storeAsNode(path);
assertEquals("Query.getPersistentQueryPath() does not return the correct path.",
path,
q.getStoredQueryPath());
}
}
代码示例来源:origin: apache/jackrabbit
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
fail("Query.storeAsNode() must throw VersionException, parent node is checked in.");
} catch (VersionException e) {
代码示例来源:origin: apache/jackrabbit
/**
* Tests if an {@link javax.jcr.ItemExistsException} is thrown when a query
* is stored on an existing node and same name siblings are not allowed.
* @throws NotExecutableException if nt:query is not supported.
*/
public void testItemExistsException() throws RepositoryException, NotExecutableException {
checkNtQuery();
Query query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
Node qNode = query.storeAsNode(testRoot + "/" + nodeName1);
// create another one
query = superuser.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
try {
query.storeAsNode(testRoot + "/" + nodeName1);
if (!qNode.getDefinition().allowsSameNameSiblings()) {
// must throw if same name siblings are not allowed
fail("Query.storeAsNode() did not throw ItemExistsException");
}
} catch (ItemExistsException e) {
if (qNode.getDefinition().allowsSameNameSiblings()) {
fail("Query.storeAsNode() must not throw ItemExistsException " +
"when same name siblings are allowed");
} else {
// expected behaviour
}
}
}
代码示例来源:origin: apache/jackrabbit
try {
Query query = readWrite.getWorkspace().getQueryManager().createQuery(statement, Query.XPATH);
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2);
fail("Query.storeAsNode() must throw LockException, parent node is locked.");
} catch (LockException e) {
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldStoreQueryAsNode() throws Exception {
String statement = "SELECT * FROM [nt:unstructured]";
QueryManager queryManager = workspace.getQueryManager();
Query query = queryManager.createQuery(statement, Query.JCR_SQL2);
Node node = query.storeAsNode("/storedQuery");
assertThat(node, is(notNullValue()));
assertThat(node.getPrimaryNodeType().getName(), is("nt:query"));
assertThat(node.getProperty("jcr:language").getString(), is(Query.JCR_SQL2));
assertThat(node.getProperty("jcr:statement").getString(), is(statement));
}
代码示例来源:origin: apache/jackrabbit
checkResult(q.execute(), new Node[]{n});
Node stored = q.storeAsNode(testRoot + "/storedQuery");
q = qm.getQuery(stored);
assertEquals("language of stored query does not match", lang, q.getLanguage());
代码示例来源:origin: org.onehippo.cms7/hippo-cms-editor-frontend
((HippoQuery) query).storeAsNode(parentNode.getPath() + "/" + nodeName, HippoNodeType.NT_QUERY);
} else {
query.storeAsNode(parentNode.getPath() + "/" + nodeName);
代码示例来源:origin: apache/jackrabbit
q.storeAsNode(itemPath);
} catch (RepositoryException e) {
代码示例来源:origin: ModeShape/modeshape
@Test
public void shouldLoadStoredQuery() throws Exception {
String statement = "SELECT * FROM [nt:unstructured]";
QueryManager queryManager = workspace.getQueryManager();
Query query = queryManager.createQuery(statement, Query.JCR_SQL2);
Node node = query.storeAsNode("/storedQuery");
Query loaded = queryManager.getQuery(node);
assertThat(loaded, is(notNullValue()));
assertThat(loaded.getLanguage(), is(Query.JCR_SQL2));
assertThat(loaded.getStatement(), is(statement));
assertThat(loaded.getStoredQueryPath(), is(node.getPath()));
}
内容来源于网络,如有侵权,请联系作者删除!