Search in sources :

Example 46 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)

Example 47 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class ChildNodeConstraint method evaluate.

/**
     * {@inheritDoc}
     */
public boolean evaluate(ScoreNode[] row, Name[] selectorNames, EvaluationContext context) throws IOException {
    ScoreNode sn = row[getSelectorIndex(selectorNames)];
    if (sn == null) {
        return false;
    }
    SessionImpl session = context.getSession();
    NodeImpl parent;
    try {
        parent = (NodeImpl) session.getNodeById(sn.getNodeId()).getParent();
    } catch (RepositoryException e) {
        return false;
    }
    return parent.getId().equals(getBaseNodeId(context));
}
Also used : ScoreNode(org.apache.jackrabbit.core.query.lucene.ScoreNode) ChildNodeImpl(org.apache.jackrabbit.spi.commons.query.qom.ChildNodeImpl) NodeImpl(org.apache.jackrabbit.core.NodeImpl) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 48 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class DescendantNodeConstraint method evaluate.

/**
     * {@inheritDoc}
     */
public boolean evaluate(ScoreNode[] row, Name[] selectorNames, EvaluationContext context) throws IOException {
    NodeId baseId = getBaseNodeId(context);
    if (baseId == null) {
        return false;
    }
    ScoreNode sn = row[getSelectorIndex(selectorNames)];
    if (sn == null) {
        return false;
    }
    NodeId id = sn.getNodeId();
    SessionImpl session = context.getSession();
    try {
        NodeImpl parent = session.getNodeById(id);
        for (; ; ) {
            // throws exception if there is no parent
            parent = (NodeImpl) parent.getParent();
            if (parent.getId().equals(baseId)) {
                return true;
            }
        }
    } catch (RepositoryException e) {
        return false;
    }
}
Also used : ScoreNode(org.apache.jackrabbit.core.query.lucene.ScoreNode) NodeImpl(org.apache.jackrabbit.core.NodeImpl) DescendantNodeImpl(org.apache.jackrabbit.spi.commons.query.qom.DescendantNodeImpl) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 49 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class DefaultLoginModule method doInit.

//------------------------------------------------< AbstractLoginModule >---
/**
     * Retrieves the user manager from the specified session. If this fails
     * this login modules initialization must fail.
     *
     * @see AbstractLoginModule#doInit(CallbackHandler, Session, Map)
     */
@Override
protected void doInit(CallbackHandler callbackHandler, Session session, Map options) throws LoginException {
    if (!(session instanceof SessionImpl)) {
        throw new LoginException("Unable to initialize LoginModule: SessionImpl expected.");
    }
    try {
        this.session = (SessionImpl) session;
        userManager = this.session.getUserManager();
        log.debug("- UserManager -> '" + userManager.getClass().getName() + "'");
    } catch (RepositoryException e) {
        throw new LoginException("Unable to initialize LoginModule: " + e.getMessage());
    }
    // configuration options related to token based authentication
    if (options.containsKey(PARAM_DISABLE_TOKEN_AUTH)) {
        disableTokenAuth = Boolean.parseBoolean(options.get(PARAM_DISABLE_TOKEN_AUTH).toString());
        log.debug("- Token authentication disabled -> '" + disableTokenAuth + "'");
    }
    if (options.containsKey(PARAM_TOKEN_EXPIRATION)) {
        try {
            tokenExpiration = Long.parseLong(options.get(PARAM_TOKEN_EXPIRATION).toString());
            log.debug("- Token expiration -> '" + tokenExpiration + "'");
        } catch (NumberFormatException e) {
            log.warn("Unabled to parse token expiration: {}", e.getMessage());
        }
    }
}
Also used : LoginException(javax.security.auth.login.LoginException) FailedLoginException(javax.security.auth.login.FailedLoginException) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl)

Example 50 with SessionImpl

use of org.apache.jackrabbit.core.SessionImpl in project jackrabbit by apache.

the class GCConcurrentTest method testConcurrentDelete.

public void testConcurrentDelete() throws Exception {
    Node root = testRootNode;
    Session session = root.getSession();
    final String testNodeName = "testConcurrentDelete";
    node(root, testNodeName);
    session.save();
    DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
    gc.setPersistenceManagerScan(false);
    gc.setMarkEventListener(new MarkEventListener() {

        public void beforeScanning(Node n) throws RepositoryException {
            if (n.getName().equals(testNodeName)) {
                n.remove();
                n.getSession().save();
            }
        }
    });
    gc.mark();
    gc.close();
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) MarkEventListener(org.apache.jackrabbit.api.management.MarkEventListener) Session(javax.jcr.Session) DataStoreGarbageCollector(org.apache.jackrabbit.api.management.DataStoreGarbageCollector)

Aggregations

SessionImpl (org.apache.jackrabbit.core.SessionImpl)66 RepositoryException (javax.jcr.RepositoryException)17 Node (javax.jcr.Node)12 Value (javax.jcr.Value)12 Name (org.apache.jackrabbit.spi.Name)12 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)11 Session (javax.jcr.Session)10 NodeImpl (org.apache.jackrabbit.core.NodeImpl)9 NodeId (org.apache.jackrabbit.core.id.NodeId)9 Principal (java.security.Principal)8 NodeIterator (javax.jcr.NodeIterator)7 Privilege (javax.jcr.security.Privilege)7 DataStoreGarbageCollector (org.apache.jackrabbit.api.management.DataStoreGarbageCollector)7 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 ArrayList (java.util.ArrayList)4 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)4 GarbageCollector (org.apache.jackrabbit.core.gc.GarbageCollector)4