Search in sources :

Example 61 with Property

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

the class ConcurrentReadWriteTest method testReadWrite.

public void testReadWrite() throws RepositoryException {
    final List uuids = new ArrayList();
    for (int i = 0; i < NUM_NODES; i++) {
        Node n = testRootNode.addNode("node" + i);
        n.addMixin(mixReferenceable);
        uuids.add(n.getUUID());
    }
    final List exceptions = Collections.synchronizedList(new ArrayList());
    final long[] numReads = new long[] { 0 };
    testRootNode.save();
    Thread t = new Thread(new Runnable() {

        public void run() {
            try {
                runTask(new Task() {

                    public void execute(Session session, Node test) throws RepositoryException {
                        Random rand = new Random();
                        long start = System.currentTimeMillis();
                        long reads = 0;
                        while (System.currentTimeMillis() < start + RUN_NUM_SECONDS * 1000) {
                            String uuid = (String) uuids.get(rand.nextInt(uuids.size()));
                            Node n = session.getNodeByUUID(uuid);
                            try {
                                for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
                                    Property p = it.nextProperty();
                                    if (p.isMultiple()) {
                                        p.getValues();
                                    } else {
                                        p.getValue();
                                    }
                                }
                            } catch (InvalidItemStateException e) {
                            // ignore
                            }
                            reads++;
                        }
                        synchronized (numReads) {
                            numReads[0] += reads;
                        }
                    }
                }, NUM_THREADS, testRoot);
            } catch (RepositoryException e) {
                exceptions.add(e);
            }
        }
    });
    t.start();
    long numWrites = 0;
    while (t.isAlive()) {
        Random rand = new Random();
        String uuid = (String) uuids.get(rand.nextInt(uuids.size()));
        Node n = superuser.getNodeByUUID(uuid);
        if (n.hasProperty("test")) {
            n.getProperty("test").remove();
        } else {
            n.setProperty("test", "hello world");
        }
        n.save();
        numWrites++;
    }
    log.println("#writes performed: " + numWrites);
    log.println("#reads performed: " + numReads[0]);
    if (!exceptions.isEmpty()) {
        fail(((RepositoryException) exceptions.get(0)).getMessage());
    }
}
Also used : InvalidItemStateException(javax.jcr.InvalidItemStateException) Node(javax.jcr.Node) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) Random(java.util.Random) List(java.util.List) ArrayList(java.util.ArrayList) Property(javax.jcr.Property) Session(javax.jcr.Session)

Example 62 with Property

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

the class VersionItemCollection method getProperty.

@Override
public DavProperty<?> getProperty(DavPropertyName name) {
    DavProperty prop = super.getProperty(name);
    if (prop == null && exists()) {
        Version v = (Version) item;
        try {
            if (VERSION_NAME.equals(name)) {
                // required, protected DAV:version-name property
                prop = new DefaultDavProperty<String>(VERSION_NAME, v.getName(), true);
            } else if (VERSION_HISTORY.equals(name)) {
                // required DAV:version-history (computed) property
                String vhHref = getLocatorFromItem(getVersionHistoryItem()).getHref(true);
                prop = new HrefProperty(VERSION_HISTORY, vhHref, true);
            } else if (PREDECESSOR_SET.equals(name)) {
                // required DAV:predecessor-set (protected) property
                prop = getHrefProperty(VersionResource.PREDECESSOR_SET, v.getPredecessors(), true);
            } else if (SUCCESSOR_SET.equals(name)) {
                // required DAV:successor-set (computed) property
                prop = getHrefProperty(SUCCESSOR_SET, v.getSuccessors(), true);
            } else if (LABEL_NAME_SET.equals(name)) {
                // required, protected DAV:label-name-set property
                String[] labels = getVersionHistoryItem().getVersionLabels(v);
                prop = new LabelSetProperty(labels);
            } else if (CHECKOUT_SET.equals(name)) {
                // required DAV:checkout-set (computed) property
                PropertyIterator it = v.getReferences();
                List<Node> nodeList = new ArrayList<Node>();
                while (it.hasNext()) {
                    Property p = it.nextProperty();
                    if (JcrConstants.JCR_BASEVERSION.equals(p.getName())) {
                        Node n = p.getParent();
                        if (n.isCheckedOut()) {
                            nodeList.add(n);
                        }
                    }
                }
                prop = getHrefProperty(CHECKOUT_SET, nodeList.toArray(new Node[nodeList.size()]), true);
            }
        } catch (RepositoryException e) {
            log.error(e.getMessage());
        }
    }
    return prop;
}
Also used : LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) Node(javax.jcr.Node) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty) PropertyIterator(javax.jcr.PropertyIterator) RepositoryException(javax.jcr.RepositoryException) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) Version(javax.jcr.version.Version) ArrayList(java.util.ArrayList) List(java.util.List) Property(javax.jcr.Property) DefaultDavProperty(org.apache.jackrabbit.webdav.property.DefaultDavProperty) HrefProperty(org.apache.jackrabbit.webdav.property.HrefProperty) LabelSetProperty(org.apache.jackrabbit.webdav.version.LabelSetProperty) DavProperty(org.apache.jackrabbit.webdav.property.DavProperty)

Example 63 with Property

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

the class GetIdentifierTest method testPropertyAdded.

public void testPropertyAdded() throws RepositoryException {
    Event[] events = getEvents(new Callable() {

        public void call() throws RepositoryException {
            testRootNode.addNode(nodeName1, testNodeType).setProperty(propertyName1, "test");
            testRootNode.getSession().save();
        }
    }, Event.PROPERTY_ADDED);
    Node n = testRootNode.getNode(nodeName1);
    Property prop = n.getProperty(propertyName1);
    assertEquals(n.getIdentifier(), getEventByPath(events, prop.getPath()).getIdentifier());
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 64 with Property

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

the class GetIdentifierTest method testPropertyRemoved.

public void testPropertyRemoved() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    final Property prop = n.setProperty(propertyName1, "test");
    String propPath = prop.getPath();
    testRootNode.getSession().save();
    Event[] events = getEvents(new Callable() {

        public void call() throws RepositoryException {
            prop.remove();
            testRootNode.getSession().save();
        }
    }, Event.PROPERTY_REMOVED);
    assertEquals(n.getIdentifier(), getEventByPath(events, propPath).getIdentifier());
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException) Property(javax.jcr.Property)

Example 65 with Property

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

the class GetInfoTest method testPropertyChanged.

public void testPropertyChanged() throws RepositoryException {
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    final Property prop = n.setProperty(propertyName1, "test");
    testRootNode.getSession().save();
    Event[] events = getEvents(new Callable() {

        public void call() throws RepositoryException {
            prop.setValue("modified");
            prop.getSession().save();
        }
    }, Event.PROPERTY_CHANGED);
    for (int i = 0; i < events.length; i++) {
        Set<?> unexpectedKeys = getUnexpectedKeys(events[i].getInfo());
        assertEquals("info map must be empty: " + unexpectedKeys, 0, unexpectedKeys.size());
    }
}
Also used : Node(javax.jcr.Node) Event(javax.jcr.observation.Event) RepositoryException(javax.jcr.RepositoryException) 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