Search in sources :

Example 11 with PropertyDefinitionImpl

use of org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl in project jackrabbit by apache.

the class NodeTypeManagerImpl method getPropertyDefinition.

/**
 * Retrieve the <code>PropertyDefinition</code> for the given
 * <code>QPropertyDefinition</code>.
 *
 * @param def
 * @return
 */
@Override
public PropertyDefinition getPropertyDefinition(QPropertyDefinition def) {
    synchronized (pdCache) {
        PropertyDefinition pdi = pdCache.get(def);
        if (pdi == null) {
            pdi = new PropertyDefinitionImpl(def, this, getNamePathResolver(), valueFactory);
            pdCache.put(def, pdi);
        }
        return pdi;
    }
}
Also used : PropertyDefinitionImpl(org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl) QPropertyDefinition(org.apache.jackrabbit.spi.QPropertyDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 12 with PropertyDefinitionImpl

use of org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl 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) Name(org.apache.jackrabbit.spi.Name) LinkedHashMap(java.util.LinkedHashMap) 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

PropertyDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.PropertyDefinitionImpl)12 RepositoryException (javax.jcr.RepositoryException)7 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)6 NodeState (org.apache.jackrabbit.core.state.NodeState)6 Name (org.apache.jackrabbit.spi.Name)6 PropertyId (org.apache.jackrabbit.core.id.PropertyId)5 NodeDefinitionImpl (org.apache.jackrabbit.spi.commons.nodetype.NodeDefinitionImpl)5 HashSet (java.util.HashSet)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)4 NodeTypeConflictException (org.apache.jackrabbit.core.nodetype.NodeTypeConflictException)4 NodeTypeManagerImpl (org.apache.jackrabbit.core.nodetype.NodeTypeManagerImpl)4 NodeTypeRegistry (org.apache.jackrabbit.core.nodetype.NodeTypeRegistry)4 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)4 PropertyState (org.apache.jackrabbit.core.state.PropertyState)4 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)4 InvalidItemStateException (javax.jcr.InvalidItemStateException)3 Value (javax.jcr.Value)3 ValueFormatException (javax.jcr.ValueFormatException)3 NodeDefinition (javax.jcr.nodetype.NodeDefinition)3