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());
}
}
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;
}
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());
}
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());
}
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());
}
}
Aggregations