Search in sources :

Example 31 with Property

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

the class ItemStateHierarchyManagerDeadlockTest method retrieveNodesUnderInvRootNode.

public void retrieveNodesUnderInvRootNode() {
    System.out.println("Start retrieveNodesUnderInvRootNode ");
    Session session = null;
    try {
        session = login();
        // start from the bottom of the tree and move up
        Node inventoryRoot = getInvRootNode(session);
        NodeIterator nodes = inventoryRoot.getNodes();
        while (nodes.hasNext()) {
            Node node = nodes.nextNode();
            // System.out.println("   Node: " + node.getName());
            PropertyIterator properties = node.getProperties();
            while (properties.hasNext()) {
                Property prop = properties.nextProperty();
            // System.out.println("      Prop: " + prop.getName() + " - " + prop.getString());
            }
        }
        session.save();
        System.out.println("End retrieveNodesUnderInvRootNode");
    } catch (Exception e) {
        System.err.println("Exception in retrieveNodesUnderInvRootNode:" + e.getMessage());
    } finally {
        if (session != null)
            session.logout();
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) IOException(java.io.IOException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session)

Example 32 with Property

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

the class ItemSequenceTest method checkTreeProperty.

private static void checkTreeProperty(Node root, int minChildren, int maxChildren, Comparator<String> order) throws RepositoryException {
    int depth = -1;
    for (Node node : new TreeTraverser(root)) {
        String parentName = node.getName();
        if (node.hasNodes()) {
            int childCount = 0;
            for (NodeIterator nodes = node.getNodes(); nodes.hasNext(); ) {
                Node child = nodes.nextNode();
                childCount++;
                if (!root.isSame(node)) {
                    assertTrue("Mismatching order: node " + node + " contains child " + child, order.compare(parentName, child.getName()) <= 0);
                }
            }
            if (!root.isSame(node)) {
                assertTrue("Node " + node + " should have at least " + minChildren + " child nodes", minChildren <= childCount);
            }
            assertTrue("Node " + node + " should have no more than " + maxChildren + " child nodes", maxChildren >= childCount);
        } else {
            if (depth == -1) {
                depth = node.getDepth();
            } else {
                assertEquals("Node " + node + " has depth " + node.getDepth() + " instead of " + depth, depth, node.getDepth());
            }
            int propCount = 0;
            for (PropertyIterator properties = node.getProperties(); properties.hasNext(); ) {
                Property property = properties.nextProperty();
                String propertyName = property.getName();
                if (!JcrConstants.JCR_PRIMARYTYPE.equals(propertyName)) {
                    propCount++;
                    assertTrue("Mismatching order: node " + node + " contains property " + property, order.compare(parentName, propertyName) <= 0);
                }
            }
            if (propCount > 0) {
                assertTrue("Node " + node + " should have at least " + minChildren + " properties", minChildren <= propCount);
                assertTrue("Node" + node + " should have no more than " + maxChildren + " properties", maxChildren >= propCount);
            }
        }
    }
}
Also used : NodeIterator(javax.jcr.NodeIterator) Node(javax.jcr.Node) TreeTraverser(org.apache.jackrabbit.commons.flat.TreeTraverser) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property)

Example 33 with Property

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

the class ItemSequenceTest method testSingletonPropertySequence.

public void testSingletonPropertySequence() throws RepositoryException {
    Comparator<String> order = Rank.<String>comparableComparator();
    TreeManager treeManager = new BTreeManager(testNode, 2, 4, order, true);
    PropertySequence properties = ItemSequence.createPropertySequence(treeManager, errorHandler);
    ValueFactory vFactory = testNode.getSession().getValueFactory();
    properties.addProperty("key", vFactory.createValue("key_"));
    assertTrue(properties.hasItem("key"));
    Iterator<Property> propertyIt = properties.iterator();
    assertTrue(propertyIt.hasNext());
    assertEquals("key", propertyIt.next().getName());
    assertFalse(propertyIt.hasNext());
    properties.removeProperty("key");
    assertEmpty(properties);
}
Also used : PropertySequence(org.apache.jackrabbit.commons.flat.PropertySequence) TreeManager(org.apache.jackrabbit.commons.flat.TreeManager) BTreeManager(org.apache.jackrabbit.commons.flat.BTreeManager) ValueFactory(javax.jcr.ValueFactory) Property(javax.jcr.Property) BTreeManager(org.apache.jackrabbit.commons.flat.BTreeManager)

Example 34 with Property

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

the class GetOrNullTest method testGetItemOrNullExistingProperty.

public void testGetItemOrNullExistingProperty() throws RepositoryException {
    JackrabbitSession js = (JackrabbitSession) superuser;
    Item item = js.getItemOrNull(PATH_EXISTING_PROPERTY);
    assertNotNull(item);
    assertTrue(item instanceof Property);
    assertEquals(item.getPath(), PATH_EXISTING_PROPERTY);
}
Also used : Item(javax.jcr.Item) JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Property(javax.jcr.Property)

Example 35 with Property

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

the class GetOrNullTest method testGetPropertyOrNullNonExisting.

public void testGetPropertyOrNullNonExisting() throws RepositoryException {
    JackrabbitSession js = (JackrabbitSession) superuser;
    Property property = js.getPropertyOrNull(PATH_NON_EXISTING_PROPERTY);
    assertNull(property);
}
Also used : JackrabbitSession(org.apache.jackrabbit.api.JackrabbitSession) Property(javax.jcr.Property)

Aggregations

Property (javax.jcr.Property)445 Node (javax.jcr.Node)252 Value (javax.jcr.Value)99 Test (org.junit.Test)87 Session (javax.jcr.Session)78 PropertyIterator (javax.jcr.PropertyIterator)68 RepositoryException (javax.jcr.RepositoryException)64 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)47 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)37 ValueFormatException (javax.jcr.ValueFormatException)34 QValue (org.apache.jackrabbit.spi.QValue)29 ArrayList (java.util.ArrayList)24 NodeIterator (javax.jcr.NodeIterator)24 QValueValue (org.apache.jackrabbit.spi.commons.value.QValueValue)23 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)20 Item (javax.jcr.Item)19 PathNotFoundException (javax.jcr.PathNotFoundException)17 InvalidItemStateException (javax.jcr.InvalidItemStateException)16 Version (javax.jcr.version.Version)16 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)15