use of javax.jcr.Node in project jackrabbit by apache.
the class ServerNode method getVersionByUUID.
//---------- Implementation helper -----------------------------------------
/**
* Returns the {@link Version} instance for the given UUID.
*
* @param versionUUID The UUID of the version.
*
* @return The version node.
*
* @throws RepositoryException if an error occurrs accessing the version
* node or if the UUID does not denote a version.
*/
protected Version getVersionByUUID(String versionUUID) throws RepositoryException {
// get the version node by its UUID from the version history's session
Session session = node.getSession();
Node versionNode = session.getNodeByUUID(versionUUID);
// the correct type).
if (versionNode instanceof Version) {
return (Version) versionNode;
}
// otherwise fail
throw new RepositoryException("Cannot find version " + versionUUID);
}
use of javax.jcr.Node in project jackrabbit by apache.
the class SerializationTest method doTestLockException.
// ----------------< locking exceptions tests >----------------------------
/**
* Tests whether importing a tree respects locking.
*/
public void doTestLockException(boolean useWorkspace, boolean useHandler) throws Exception {
exportRepository(SKIPBINARY, RECURSE);
if (isSupported(Repository.OPTION_LOCKING_SUPPORTED)) {
//A LockException is thrown if a lock prevents the addition of the subtree.
Node lNode = testRootNode.addNode(nodeName1);
ensureMixinType(lNode, mixLockable);
testRootNode.getSession().save();
Lock lock = lNode.lock(true, true);
//remove the token, so the lock is for me, too
session.removeLockToken(lock.getLockToken());
FileInputStream in = new FileInputStream(file);
try {
doImport(lNode.getPath(), in, useWorkspace, useHandler);
} catch (LockException e) {
// success
} finally {
try {
in.close();
} catch (IOException ignore) {
}
}
} else {
log.println("Locking not supported.");
}
}
use of javax.jcr.Node in project jackrabbit by apache.
the class SerializationTest method doTestOverwriteException.
// ---------------< Overwrite existing target node tests >------------------------------
// ---------------< in case same name siblings not supported >------------------------------
/**
* Tries to overwrite an existing node. This only works for nodes that do
* not allow same-name siblings.
*/
public void doTestOverwriteException(boolean useWorkspace, boolean useHandler) throws Exception {
//If deserialization would overwrite an existing item,
// an ItemExistsException respective a SAXException is thrown.
Node folder = testRootNode.addNode("myFolder", treeComparator.sc.sameNameSibsFalseChildNodeDefinition);
Node subfolder = folder.addNode("subfolder");
session.save();
FileOutputStream out = new FileOutputStream(file);
try {
session.exportSystemView(subfolder.getPath(), out, true, true);
} finally {
out.close();
}
FileInputStream in = new FileInputStream(file);
try {
if (useHandler) {
try {
doImport(folder.getPath(), in, useWorkspace, useHandler);
fail("Overwriting an existing node during import must throw a SAXException");
} catch (SAXException e) {
// success
}
} else {
try {
doImport(folder.getPath(), in, useWorkspace, useHandler);
fail("Overwriting an existing node during import must throw an ItemExistsException");
} catch (ItemExistsException e) {
// success
}
}
} finally {
try {
in.close();
} catch (IOException ignore) {
}
}
}
use of javax.jcr.Node in project jackrabbit by apache.
the class PropertyTypeTest method typeCheckChildren.
private void typeCheckChildren(Node parentNode) throws RepositoryException {
NodeIterator nodes = parentNode.getNodes();
while (nodes.hasNext()) {
Node node = nodes.nextNode();
PropertyIterator props = node.getProperties();
while (props.hasNext()) {
Property prop = props.nextProperty();
int reqType = prop.getDefinition().getRequiredType();
int type = PropertyType.UNDEFINED;
boolean isEmptyMultipleArray = false;
if (prop.getDefinition().isMultiple()) {
if (prop.getValues().length > 0) {
type = prop.getValues()[0].getType();
} else {
isEmptyMultipleArray = true;
}
} else {
type = prop.getValue().getType();
}
if (!isEmptyMultipleArray && reqType != PropertyType.UNDEFINED) {
assertFalse("The type of a property must not " + "be UNDEFINED", type == PropertyType.UNDEFINED);
assertEquals("The type of a property has to match " + "the type of the property definition.", type, reqType);
}
}
typeCheckChildren(node);
}
}
use of javax.jcr.Node in project jackrabbit by apache.
the class PropertyTest method testIsSameMustNotCompareStates.
/**
* Tests if <code>Item.isSame(Item otherItem)</code> will return true when
* two <code>Property</code> objects representing the same actual repository
* item have been retrieved through two different sessions and one has been
* modified.
*
* @since JCR 2.0
*/
public void testIsSameMustNotCompareStates() throws RepositoryException {
// create a node, add a property and save it
Node testNode1 = testRootNode.addNode(nodeName1, testNodeType);
Property prop1 = testNode1.setProperty(propertyName1, "value1");
testRootNode.getSession().save();
// accuire the same property through a different session
Session session = getHelper().getSuperuserSession();
try {
Property prop2 = session.getProperty(prop1.getPath());
// change the value of prop2
prop2.setValue("value2");
assertTrue("Two references of same property must return true for " + "property1.isSame(property2)", prop1.isSame(prop2));
} finally {
session.logout();
}
}
Aggregations