use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class LockManagerImpl method internalLock.
/**
* Internal <code>lock</code> implementation that takes the same parameters
* as the public method.
*
* @param node node to lock
* @param isDeep whether the lock applies to this node only
* @param isSessionScoped whether the lock is session scoped
* @param timeoutHint
* @param ownerInfo
* @return lock
* @throws LockException if the node is already locked
* @throws RepositoryException if another error occurs
*/
LockInfo internalLock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeoutHint, String ownerInfo) throws LockException, RepositoryException {
SessionImpl session = (SessionImpl) node.getSession();
String lockOwner = (ownerInfo != null) ? ownerInfo : session.getUserID();
InternalLockInfo info = new InternalLockInfo(node.getNodeId(), isSessionScoped, isDeep, lockOwner, timeoutHint);
ClusterOperation operation = null;
boolean successful = false;
// Cluster is only informed about open-scoped locks
if (eventChannel != null && !isSessionScoped) {
operation = eventChannel.create(node.getNodeId(), isDeep, lockOwner);
}
acquire();
try {
// check whether node is already locked
Path path = getPath(session, node.getId());
PathMap.Element<LockInfo> element = lockMap.map(path, false);
LockInfo other = element.get();
if (other != null) {
if (element.hasPath(path)) {
other.throwLockException("Node already locked: " + node, session);
} else if (other.isDeep()) {
other.throwLockException("Parent node has a deep lock: " + node, session);
}
}
if (info.isDeep() && element.hasPath(path) && element.getChildrenCount() > 0) {
info.throwLockException("Some child node is locked", session);
}
// create lock token
info.setLockHolder(session);
info.setLive(true);
session.addListener(info);
if (!info.isSessionScoped()) {
getSessionLockManager(session).lockTokenAdded(info.getLockToken());
}
lockMap.put(path, info);
if (!info.isSessionScoped()) {
save();
successful = true;
}
return info;
} finally {
release();
if (operation != null) {
operation.ended(successful);
}
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class LockManagerImpl method isLocked.
/**
* {@inheritDoc}
*/
public boolean isLocked(NodeImpl node) throws RepositoryException {
acquire();
try {
SessionImpl session = (SessionImpl) node.getSession();
Path path = getPath(session, node.getId());
PathMap.Element<LockInfo> element = lockMap.map(path, false);
LockInfo info = element.get();
if (info == null) {
return false;
}
if (element.hasPath(path)) {
return true;
} else {
return info.isDeep();
}
} catch (ItemNotFoundException e) {
return false;
} finally {
release();
}
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class LockManagerImpl method checkLock.
/**
* {@inheritDoc}
*/
public void checkLock(NodeImpl node) throws LockException, RepositoryException {
SessionImpl session = (SessionImpl) node.getSession();
checkLock(getPath(session, node.getId()), session);
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class XAEnvironment method lock.
/**
* Lock some node.
* @param node node to lock
* @param isDeep <code>true</code> to deep lock this node;
* <code>false</code> otherwise
* @param isSessionScoped <code>true</code> if lock should be session scoped;
* <code>false</code> otherwise
* @param timeoutHint
* @param ownerInfo
* @throws LockException if node is already locked
* @throws RepositoryException if an error occurs
*/
public LockInfo lock(NodeImpl node, boolean isDeep, boolean isSessionScoped, long timeoutHint, String ownerInfo) throws LockException, RepositoryException {
NodeId id = node.getNodeId();
// check negative set first
XALockInfo info = unlockedNodesMap.get(id);
if (info != null) {
// if settings are compatible, this is effectively a no-op
if (info.isDeep() == isDeep && info.isSessionScoped() == isSessionScoped) {
unlockedNodesMap.remove(id);
operations.remove(info);
return lockMgr.getLockInfo(id);
}
}
// verify node is not already locked.
if (isLocked(node)) {
throw new LockException("Node locked.");
}
// create a new lock info for this node
String lockOwner = (ownerInfo != null) ? ownerInfo : node.getSession().getUserID();
info = new XALockInfo(node, isSessionScoped, isDeep, timeoutHint, lockOwner);
SessionImpl session = (SessionImpl) node.getSession();
info.setLockHolder(session);
info.setLive(true);
LockManagerImpl.getSessionLockManager(session).lockTokenAdded(info.getLockToken());
lockedNodesMap.put(id, info);
operations.add(info);
return info;
}
use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.
the class QueryImpl method getColumns.
/**
* Returns the columns for this query.
*
* @return array of columns.
* @throws RepositoryException if an error occurs.
*/
protected ColumnImpl[] getColumns() throws RepositoryException {
SessionImpl session = sessionContext.getSessionImpl();
QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
// get columns
Map<Name, ColumnImpl> columns = new LinkedHashMap<Name, ColumnImpl>();
for (Name name : root.getSelectProperties()) {
String pn = sessionContext.getJCRName(name);
ColumnImpl col = (ColumnImpl) qomFactory.column(sessionContext.getJCRName(DEFAULT_SELECTOR_NAME), pn, pn);
columns.put(name, col);
}
if (columns.size() == 0) {
// use node type constraint
LocationStepQueryNode[] steps = root.getLocationNode().getPathSteps();
final Name[] ntName = new Name[1];
steps[steps.length - 1].acceptOperands(new DefaultQueryNodeVisitor() {
public Object visit(AndQueryNode node, Object data) throws RepositoryException {
return node.acceptOperands(this, data);
}
public Object visit(NodeTypeQueryNode node, Object data) {
ntName[0] = node.getValue();
return data;
}
}, null);
if (ntName[0] == null) {
ntName[0] = NameConstants.NT_BASE;
}
NodeTypeImpl nt = session.getNodeTypeManager().getNodeType(ntName[0]);
PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
for (PropertyDefinition pd : propDefs) {
QPropertyDefinition propDef = ((PropertyDefinitionImpl) pd).unwrap();
if (!propDef.definesResidual() && !propDef.isMultiple()) {
columns.put(propDef.getName(), columnForName(propDef.getName()));
}
}
}
// add jcr:path and jcr:score if not selected already
if (!columns.containsKey(NameConstants.JCR_PATH)) {
columns.put(NameConstants.JCR_PATH, columnForName(NameConstants.JCR_PATH));
}
if (!columns.containsKey(NameConstants.JCR_SCORE)) {
columns.put(NameConstants.JCR_SCORE, columnForName(NameConstants.JCR_SCORE));
}
return columns.values().toArray(new ColumnImpl[columns.size()]);
}
Aggregations