use of javax.jcr.Node in project jackrabbit by apache.
the class VersionManagerImpl method setActivity.
/**
* {@inheritDoc}
*/
public Node setActivity(Node activity) throws RepositoryException {
Node oldActivity = getActivity();
if (activity == null) {
currentActivity = null;
} else {
NodeImpl actNode = (NodeImpl) activity;
if (!actNode.isNodeType(NameConstants.NT_ACTIVITY)) {
String msg = "Given node is not an activity: " + actNode.safeGetJCRPath();
log.error(msg);
throw new UnsupportedRepositoryOperationException(msg);
}
currentActivity = actNode.getNodeId();
}
return oldActivity;
}
use of javax.jcr.Node in project jackrabbit by apache.
the class QueryImpl method storeAsNode.
/**
* {@inheritDoc}
*/
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
checkInitialized();
try {
Path p = sessionContext.getQPath(absPath).getNormalizedPath();
if (!p.isAbsolute()) {
throw new RepositoryException(absPath + " is not an absolute path");
}
String relPath = sessionContext.getJCRPath(p).substring(1);
Node queryNode = sessionContext.getSessionImpl().getRootNode().addNode(relPath, sessionContext.getJCRName(NT_QUERY));
// set properties
queryNode.setProperty(sessionContext.getJCRName(JCR_LANGUAGE), language);
queryNode.setProperty(sessionContext.getJCRName(JCR_STATEMENT), statement);
node = queryNode;
return node;
} catch (NameException e) {
throw new RepositoryException(e.getMessage(), e);
}
}
use of javax.jcr.Node in project jackrabbit by apache.
the class VersionHistoryImpl method getAllLinearVersions.
/**
* @see VersionHistory#getAllLinearVersions()
*/
@SuppressWarnings("deprecation")
public VersionIterator getAllLinearVersions() throws RepositoryException {
// get base version. this can certainly be optimized
SessionImpl session = sessionContext.getSessionImpl();
InternalVersionHistory vh = getInternalVersionHistory();
Node vn = session.getNodeById(vh.getVersionableId());
InternalVersion base = ((VersionImpl) vn.getBaseVersion()).getInternalVersion();
return new VersionIteratorImpl(getSession(), vh.getRootVersion(), base);
}
use of javax.jcr.Node in project jackrabbit by apache.
the class NodeCorruptionTest method testCopyMultiSingleValue.
public void testCopyMultiSingleValue() throws Exception {
Node root = superuser.getRootNode();
String nodeName = "testCopyMulti" + System.currentTimeMillis();
if (root.hasNode(nodeName)) {
root.getNode(nodeName).remove();
superuser.save();
}
Node test = root.addNode(nodeName);
test.setProperty("x", "Hi");
superuser.save();
String wsp = superuser.getWorkspace().getName();
String workspace2 = getAlternativeWorkspaceName();
if (workspace2 == null) {
throw new NotExecutableException();
}
Session s2 = getHelper().getSuperuserSession(workspace2);
s2.getWorkspace().clone(wsp, "/" + nodeName, "/" + nodeName, true);
Node test2 = s2.getRootNode().getNode(nodeName);
test2.setProperty("x", (Value) null);
test2.setProperty("x", new String[] {});
s2.save();
test.update(workspace2);
try {
Value[] values = test.getProperty("x").getValues();
assertEquals(0, values.length);
} catch (RepositoryException e) {
// if we get here, it's a bug, as it is a multi-valued property now
// anyway, let's see what happens if we try to read it as a single valued property
test.getProperty("x").getValue();
// even if that works: it's still a bug
throw e;
}
}
use of javax.jcr.Node in project jackrabbit by apache.
the class VersionEventsTest method testXACheckin.
/**
* Test if checkin of a node in an XA transaction creates two add node
* events: one for the version and one for the frozen node.
*/
public void testXACheckin() throws Exception {
// create versionable node
Node n1 = testRootNode.addNode(nodeName1);
n1.addMixin(mixVersionable);
testRootNode.save();
EventResult listener = new EventResult(log);
addEventListener(listener, Event.NODE_ADDED);
// use a transaction
UserTransaction utx = new UserTransactionImpl(superuser);
// start transaction
utx.begin();
Version v = n1.checkin();
// commit transaction
utx.commit();
removeEventListener(listener);
Event[] events = listener.getEvents(1000);
Set paths = new HashSet();
for (int i = 0; i < events.length; i++) {
paths.add(events[i].getPath());
}
assertTrue("missing 'node added' event: " + v.getPath(), paths.contains(v.getPath()));
String frozenPath = v.getPath() + "/" + jcrFrozenNode;
assertTrue("missing 'node added' event: " + frozenPath, paths.contains(frozenPath));
}
Aggregations