Search in sources :

Example 76 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class VersionTest method testGetProperties.

/**
     * Tests if <code>Version.getProperties()</code> and
     * <code>Version.getProperties(String)</code> return the right property
     */
public void testGetProperties() throws Exception {
    PropertyIterator pi = version.getProperties();
    boolean hasPropertyCreated = false;
    while (pi.hasNext()) {
        if (pi.nextProperty().getName().equals(jcrCreated)) {
            hasPropertyCreated = true;
        }
    }
    assertTrue("Version.getProperties() does not return property jcr:created", hasPropertyCreated);
    pi = version.getProperties(superuser.getNamespacePrefix(NS_JCR_URI) + ":*");
    hasPropertyCreated = false;
    while (pi.hasNext()) {
        if (pi.nextProperty().getName().equals(jcrCreated)) {
            hasPropertyCreated = true;
        }
    }
    assertTrue("Version.getProperties(String) does not return property jcr:created", hasPropertyCreated);
}
Also used : PropertyIterator(javax.jcr.PropertyIterator)

Example 77 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class Dump method dump.

/**
     * Dumps the given <code>Node</code> to the given <code>PrintWriter</code>
     * @param out
     *        the <code>PrintWriter</code>
     * @param n
     *        the <code>Node</code>
     * @throws RepositoryException
     */
public void dump(PrintWriter out, Node n) throws RepositoryException {
    out.println(n.getPath());
    PropertyIterator pit = n.getProperties();
    while (pit.hasNext()) {
        Property p = pit.nextProperty();
        out.print(p.getPath() + "=");
        if (p.getDefinition().isMultiple()) {
            Value[] values = p.getValues();
            for (int i = 0; i < values.length; i++) {
                if (i > 0)
                    out.println(",");
                out.println(values[i].getString());
            }
        } else {
            out.print(p.getString());
        }
        out.println();
    }
    NodeIterator nit = n.getNodes();
    while (nit.hasNext()) {
        Node cn = nit.nextNode();
        dump(out, cn);
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Value(javax.jcr.Value) Property(javax.jcr.Property)

Example 78 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit by apache.

the class LsReferences method execute.

/**
     * {@inheritDoc}
     */
public boolean execute(Context ctx) throws Exception {
    String path = (String) ctx.get(this.pathKey);
    Node n = CommandHelper.getNode(ctx, path);
    // header
    int[] width = new int[] { 60 };
    String[] header = new String[] { bundle.getString("word.path") };
    // print header
    PrintHelper.printRow(ctx, width, header);
    // print separator
    PrintHelper.printSeparatorRow(ctx, width, '-');
    PropertyIterator iter = n.getReferences();
    while (iter.hasNext()) {
        Property p = iter.nextProperty();
        // print header
        PrintHelper.printRow(ctx, width, new String[] { p.getPath() });
    }
    CommandHelper.getOutput(ctx).println();
    CommandHelper.getOutput(ctx).println(iter.getSize() + " " + bundle.getString("word.references"));
    return false;
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 79 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.

the class ConcurrentReadRandomNodeAndItsPropertiesTest method randomRead.

protected void randomRead(Session testSession, List<String> allPaths, int cnt) throws RepositoryException {
    boolean logout = false;
    if (testSession == null) {
        testSession = getTestSession();
        logout = true;
    }
    try {
        int nodeCnt = 0;
        int propertyCnt = 0;
        int noAccess = 0;
        int size = allPaths.size();
        long start = System.currentTimeMillis();
        for (int i = 0; i < cnt; i++) {
            double rand = size * Math.random();
            int index = (int) Math.floor(rand);
            String path = allPaths.get(index);
            if (testSession.itemExists(path)) {
                Item item = testSession.getItem(path);
                if (item.isNode()) {
                    nodeCnt++;
                    Node n = (Node) item;
                    PropertyIterator it = n.getProperties();
                    while (it.hasNext()) {
                        Property p = it.nextProperty();
                        propertyCnt++;
                    }
                }
            } else {
                noAccess++;
            }
        }
        long end = System.currentTimeMillis();
        if (doReport) {
            System.out.println("Session " + testSession.getUserID() + " reading " + (cnt - noAccess) + " (Nodes: " + nodeCnt + "; Properties: " + propertyCnt + ") completed in " + (end - start));
        }
    } finally {
        if (logout) {
            logout(testSession);
        }
    }
}
Also used : Item(javax.jcr.Item) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 80 with PropertyIterator

use of javax.jcr.PropertyIterator in project jackrabbit-oak by apache.

the class ConcurrentReadIT method concurrentPropertyIteration.

@Test
public void concurrentPropertyIteration() throws RepositoryException, InterruptedException, ExecutionException {
    final Session session = createAdminSession();
    try {
        final Node testRoot = session.getRootNode().addNode("test-root");
        for (int k = 0; k < 50; k++) {
            testRoot.setProperty("p" + k, k);
        }
        session.save();
        ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
        List<ListenableFuture<?>> futures = Lists.newArrayList();
        for (int k = 0; k < 20; k++) {
            futures.add(executorService.submit(new Callable<Void>() {

                @Override
                public Void call() throws Exception {
                    for (int k = 0; k < 100000; k++) {
                        session.refresh(false);
                        PropertyIterator properties = testRoot.getProperties();
                        properties.hasNext();
                    }
                    return null;
                }
            }));
        }
        // Throws ExecutionException if any of the submitted task failed
        Futures.allAsList(futures).get();
        executorService.shutdown();
        executorService.awaitTermination(1, TimeUnit.DAYS);
    } finally {
        session.logout();
    }
}
Also used : Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Callable(java.util.concurrent.Callable) Session(javax.jcr.Session) Test(org.junit.Test)

Aggregations

PropertyIterator (javax.jcr.PropertyIterator)96 Property (javax.jcr.Property)68 Node (javax.jcr.Node)57 NodeIterator (javax.jcr.NodeIterator)28 Value (javax.jcr.Value)23 Test (org.junit.Test)16 RepositoryException (javax.jcr.RepositoryException)15 Session (javax.jcr.Session)15 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)10 PathNotFoundException (javax.jcr.PathNotFoundException)8 HashMap (java.util.HashMap)5 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)5 NodeImpl (org.apache.jackrabbit.core.NodeImpl)5 PropertyImpl (org.apache.jackrabbit.core.PropertyImpl)5 NoSuchElementException (java.util.NoSuchElementException)3 AccessDeniedException (javax.jcr.AccessDeniedException)3 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 ValueFormatException (javax.jcr.ValueFormatException)3 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)3