Search in sources :

Example 41 with SessionImpl

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);
        }
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) SessionImpl(org.apache.jackrabbit.core.SessionImpl) ClusterOperation(org.apache.jackrabbit.core.cluster.ClusterOperation) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap)

Example 42 with SessionImpl

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();
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) SessionImpl(org.apache.jackrabbit.core.SessionImpl) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 43 with SessionImpl

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);
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 44 with SessionImpl

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;
}
Also used : LockException(javax.jcr.lock.LockException) NodeId(org.apache.jackrabbit.core.id.NodeId) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 45 with SessionImpl

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()]);
}
Also used : NodeTypeImpl(org.apache.jackrabbit.core.nodetype.NodeTypeImpl) LocationStepQueryNode(org.apache.jackrabbit.spi.commons.query.LocationStepQueryNode) PropertyDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl) RepositoryException(javax.jcr.RepositoryException) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) LinkedHashMap(java.util.LinkedHashMap) Name(org.apache.jackrabbit.spi.Name) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) SessionImpl(org.apache.jackrabbit.core.SessionImpl) QueryObjectModelFactory(javax.jcr.query.qom.QueryObjectModelFactory) ColumnImpl(org.apache.jackrabbit.spi.commons.query.qom.ColumnImpl) DefaultQueryNodeVisitor(org.apache.jackrabbit.spi.commons.query.DefaultQueryNodeVisitor) NodeTypeQueryNode(org.apache.jackrabbit.spi.commons.query.NodeTypeQueryNode) AndQueryNode(org.apache.jackrabbit.spi.commons.query.AndQueryNode)

Aggregations

SessionImpl (org.apache.jackrabbit.core.SessionImpl)63 RepositoryException (javax.jcr.RepositoryException)16 Node (javax.jcr.Node)12 Value (javax.jcr.Value)11 Name (org.apache.jackrabbit.spi.Name)11 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Session (javax.jcr.Session)9 NodeImpl (org.apache.jackrabbit.core.NodeImpl)8 NodeId (org.apache.jackrabbit.core.id.NodeId)8 Principal (java.security.Principal)7 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)7 NodeIterator (javax.jcr.NodeIterator)6 Privilege (javax.jcr.security.Privilege)6 UserManager (org.apache.jackrabbit.api.security.user.UserManager)6 Path (org.apache.jackrabbit.spi.Path)6 JackrabbitAccessControlList (org.apache.jackrabbit.api.security.JackrabbitAccessControlList)5 PathMap (org.apache.jackrabbit.spi.commons.name.PathMap)5 InvalidItemStateException (javax.jcr.InvalidItemStateException)4 LockException (javax.jcr.lock.LockException)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4