Search in sources :

Example 1 with QueryManagerImpl

use of org.apache.jackrabbit.core.query.QueryManagerImpl in project jackrabbit by apache.

the class WorkspaceImpl method getQueryManager.

/**
     * {@inheritDoc}
     */
public synchronized QueryManager getQueryManager() throws RepositoryException {
    // check state of this instance
    sanityCheck();
    if (queryManager == null) {
        SearchManager searchManager;
        try {
            searchManager = context.getRepository().getSearchManager(wspConfig.getName());
            if (searchManager == null) {
                String msg = "no search manager configured for this workspace";
                log.debug(msg);
                throw new RepositoryException(msg);
            }
        } catch (NoSuchWorkspaceException nswe) {
            // should never get here
            String msg = "internal error: failed to instantiate query manager";
            log.debug(msg);
            throw new RepositoryException(msg, nswe);
        }
        queryManager = new QueryManagerImpl(context, searchManager);
    }
    return queryManager;
}
Also used : NoSuchWorkspaceException(javax.jcr.NoSuchWorkspaceException) RepositoryException(javax.jcr.RepositoryException) QueryManagerImpl(org.apache.jackrabbit.core.query.QueryManagerImpl)

Example 2 with QueryManagerImpl

use of org.apache.jackrabbit.core.query.QueryManagerImpl in project jackrabbit by apache.

the class NodeImpl method getWeakReferences.

/**
     * {@inheritDoc}
     */
public PropertyIterator getWeakReferences() throws RepositoryException {
    // check state of this instance
    sanityCheck();
    // shortcut if node isn't referenceable
    if (!isNodeType(NameConstants.MIX_REFERENCEABLE)) {
        return PropertyIteratorAdapter.EMPTY;
    }
    Value ref = getSession().getValueFactory().createValue(this, true);
    List<Property> props = new ArrayList<Property>();
    QueryManagerImpl qm = (QueryManagerImpl) getSession().getWorkspace().getQueryManager();
    for (Node n : qm.getWeaklyReferringNodes(this)) {
        for (PropertyIterator it = n.getProperties(); it.hasNext(); ) {
            Property p = it.nextProperty();
            if (p.getType() == PropertyType.WEAKREFERENCE) {
                Collection<Value> refs;
                if (p.isMultiple()) {
                    refs = Arrays.asList(p.getValues());
                } else {
                    refs = Collections.singleton(p.getValue());
                }
                if (refs.contains(ref)) {
                    props.add(p);
                }
            }
        }
    }
    return new PropertyIteratorAdapter(props);
}
Also used : JackrabbitNode(org.apache.jackrabbit.api.JackrabbitNode) Node(javax.jcr.Node) PropertyIteratorAdapter(org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter) Value(javax.jcr.Value) InternalValue(org.apache.jackrabbit.core.value.InternalValue) ArrayList(java.util.ArrayList) PropertyIterator(javax.jcr.PropertyIterator) Property(javax.jcr.Property) QueryManagerImpl(org.apache.jackrabbit.core.query.QueryManagerImpl)

Aggregations

QueryManagerImpl (org.apache.jackrabbit.core.query.QueryManagerImpl)2 ArrayList (java.util.ArrayList)1 NoSuchWorkspaceException (javax.jcr.NoSuchWorkspaceException)1 Node (javax.jcr.Node)1 Property (javax.jcr.Property)1 PropertyIterator (javax.jcr.PropertyIterator)1 RepositoryException (javax.jcr.RepositoryException)1 Value (javax.jcr.Value)1 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)1 PropertyIteratorAdapter (org.apache.jackrabbit.commons.iterator.PropertyIteratorAdapter)1 InternalValue (org.apache.jackrabbit.core.value.InternalValue)1