@Override public Node storeAsNode(String s) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException { return this.query.storeAsNode(s); } }
/** * @inheritDoc */ public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException { Node node = query.storeAsNode(absPath); return node; }
/** {@inheritDoc} */ public RemoteNode storeAsNode(String absPath) throws RepositoryException, RemoteException { return getRemoteNode(query.storeAsNode(absPath)); }
public JcrNode execute() throws Exception { return JcrNode.Wrapper.wrap(getDelegate().storeAsNode(absPath), getJcrSession()); } });
/** * 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 } }
public Node storeAsNode(String absPath) throws RepositoryException { return NodeWrapper.wrap(getDelegate().storeAsNode(absPath), getSessionWrapper()); }
/** * 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 } }
/** * 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 } }
/** * 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()); }
/** * 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()); } }
query.storeAsNode(testRoot + "/" + nodeName1 + "/" + nodeName2); fail("Query.storeAsNode() must throw VersionException, parent node is checked in."); } catch (VersionException e) {
/** * 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 } } }
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) {
@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)); }
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());
((HippoQuery) query).storeAsNode(parentNode.getPath() + "/" + nodeName, HippoNodeType.NT_QUERY); } else { query.storeAsNode(parentNode.getPath() + "/" + nodeName);
q.storeAsNode(itemPath); } catch (RepositoryException e) {
@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())); }