Search in sources :

Example 11 with QueryModelException

use of org.alfresco.repo.search.impl.querymodel.QueryModelException in project alfresco-repository by Alfresco.

the class DbOrIndexSwitchingQueryLanguage method executeQuery.

public ResultSet executeQuery(SearchParameters searchParameters) {
    QueryConsistency consistency = searchParameters.getQueryConsistency();
    if (consistency == QueryConsistency.DEFAULT) {
        consistency = queryConsistency;
    }
    switch(consistency) {
        case EVENTUAL:
            if (indexQueryLanguage != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters);
                }
                StopWatch stopWatch = new StopWatch("index only");
                stopWatch.start();
                ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
                stopWatch.stop();
                if (logger.isDebugEnabled()) {
                    logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                }
                return results;
            } else {
                throw new QueryModelException("No query language available");
            }
        case TRANSACTIONAL:
            if (dbQueryLanguage != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters);
                }
                StopWatch stopWatch = new StopWatch("database only");
                stopWatch.start();
                ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters));
                stopWatch.stop();
                if (logger.isDebugEnabled()) {
                    logger.debug("DB returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                }
                return results;
            } else {
                throw new QueryModelException("No query language available");
            }
        case HYBRID:
            if (!hybridEnabled) {
                throw new DisabledFeatureException("Hybrid query is disabled.");
            }
            return executeHybridQuery(searchParameters);
        case DEFAULT:
        case TRANSACTIONAL_IF_POSSIBLE:
        default:
            StopWatch stopWatch = new StopWatch("DB if possible");
            // SEARCH-347, exclude TMDQ calls if faceting present.
            if (dbQueryLanguage != null && !searchParameters.hasFaceting()) {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Trying db query for " + dbQueryLanguage.getName() + " for " + searchParameters);
                    }
                    stopWatch.start();
                    ResultSet results = dbQueryLanguage.executeQuery(flattenDBQuery(searchParameters));
                    stopWatch.stop();
                    if (logger.isDebugEnabled()) {
                        logger.debug("DB returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                    }
                    return results;
                } catch (QueryModelException qme) {
                    if (stopWatch.isRunning()) {
                        stopWatch.stop();
                    }
                    // MNT-10323: Logging configuration on JBoss leads to clogging of the log with a lot of these errors because of INFO level when WQS module is installed
                    if (logger.isDebugEnabled()) {
                        logger.debug("DB query failed for " + dbQueryLanguage.getName() + " for " + searchParameters, qme);
                    }
                    if (indexQueryLanguage != null) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Using SOLR query: " + dbQueryLanguage.getName() + " for " + searchParameters);
                        }
                        stopWatch.start();
                        ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
                        stopWatch.stop();
                        if (logger.isDebugEnabled()) {
                            logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                        }
                        return results;
                    }
                }
            } else {
                if (indexQueryLanguage != null) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("(No DB QL) Using SOLR query: " + "dbQueryLanguage==null" + " for " + searchParameters);
                    }
                    stopWatch.start();
                    ResultSet results = indexQueryLanguage.executeQuery(searchParameters);
                    stopWatch.stop();
                    if (logger.isDebugEnabled()) {
                        logger.debug("SOLR returned " + results.length() + " results in " + stopWatch.getLastTaskTimeMillis() + "ms");
                    }
                    return results;
                }
            }
            throw new QueryModelException("No query language available");
    }
}
Also used : ResultSet(org.alfresco.service.cmr.search.ResultSet) ChildAssocRefResultSet(org.alfresco.repo.search.results.ChildAssocRefResultSet) SolrJSONResultSet(org.alfresco.repo.search.impl.lucene.SolrJSONResultSet) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) QueryConsistency(org.alfresco.service.cmr.search.QueryConsistency) StopWatch(org.springframework.util.StopWatch)

Example 12 with QueryModelException

use of org.alfresco.repo.search.impl.querymodel.QueryModelException in project alfresco-repository by Alfresco.

the class DBOrdering method prepare.

/* (non-Javadoc)
     * @see org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryBuilderComponent#prepare(org.alfresco.service.namespace.NamespaceService, org.alfresco.service.cmr.dictionary.DictionaryService, org.alfresco.repo.domain.qname.QNameDAO, org.alfresco.repo.domain.node.NodeDAO, java.util.Set, java.util.Map, org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext)
     */
@Override
public void prepare(NamespaceService namespaceService, DictionaryService dictionaryService, QNameDAO qnameDAO, NodeDAO nodeDAO, TenantService tenantService, Set<String> selectors, Map<String, Argument> functionArgs, FunctionEvaluationContext functionContext, boolean supportBooleanFloatAndDouble) {
    if (getColumn().getFunction().getName().equals(PropertyAccessor.NAME)) {
        PropertyArgument property = (PropertyArgument) getColumn().getFunctionArguments().get(PropertyAccessor.ARG_PROPERTY);
        if (property == null) {
            throw new QueryModelException("No property to order ");
        }
        if (property.getPropertyName().equals(PropertyIds.PARENT_ID)) {
            throw new QueryModelException("Ordering is not supported for " + PropertyIds.PARENT_ID);
        } else if (property.getPropertyName().equals(PropertyIds.OBJECT_ID)) {
            throw new QueryModelException("Ordering is not supported for " + PropertyIds.OBJECT_ID);
        } else if (property.getPropertyName().equals(PropertyIds.OBJECT_TYPE_ID)) {
            throw new QueryModelException("Ordering is not supported for " + PropertyIds.OBJECT_TYPE_ID);
        } else if (property.getPropertyName().equals(PropertyIds.BASE_TYPE_ID)) {
            throw new QueryModelException("Ordering is not supported for " + PropertyIds.BASE_TYPE_ID);
        } else if (property.getPropertyName().equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
            PropertySupport propertySupport = new PropertySupport();
            if (getOrder() == Order.ASCENDING) {
                propertySupport.setValue("ASC");
            } else if (getOrder() == Order.DESCENDING) {
                propertySupport.setValue("DESC");
            }
            QName basePropertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(property.getPropertyName()), namespaceService));
            propertySupport.setPropertyQName(basePropertyQName);
            propertySupport.setPair(qnameDAO.getQName(basePropertyQName));
            propertySupport.setJoinCommandType(DBQueryBuilderJoinCommandType.CONTENT_MIMETYPE);
            propertySupport.setFieldName("mimetype_str");
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.ORDER);
            propertySupport.setLeftOuter(true);
            builderSupport = propertySupport;
        } else if (property.getPropertyName().equals(PropertyIds.CONTENT_STREAM_LENGTH)) {
            PropertySupport propertySupport = new PropertySupport();
            if (getOrder() == Order.ASCENDING) {
                propertySupport.setValue("ASC");
            } else if (getOrder() == Order.DESCENDING) {
                propertySupport.setValue("DESC");
            }
            QName basePropertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(property.getPropertyName()), namespaceService));
            propertySupport.setPropertyQName(basePropertyQName);
            propertySupport.setPair(qnameDAO.getQName(basePropertyQName));
            propertySupport.setJoinCommandType(DBQueryBuilderJoinCommandType.CONTENT_URL);
            propertySupport.setFieldName("content_size");
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.ORDER);
            propertySupport.setLeftOuter(true);
            builderSupport = propertySupport;
        } else {
            PropertySupport propertySupport = new PropertySupport();
            if (getOrder() == Order.ASCENDING) {
                propertySupport.setValue("ASC");
            } else if (getOrder() == Order.DESCENDING) {
                propertySupport.setValue("DESC");
            }
            QName propertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(property.getPropertyName()), namespaceService));
            propertySupport.setPropertyQName(propertyQName);
            propertySupport.setPair(qnameDAO.getQName(propertyQName));
            propertySupport.setJoinCommandType(DBQuery.getJoinCommandType(propertyQName));
            propertySupport.setFieldName(DBQuery.getFieldName(dictionaryService, propertyQName, supportBooleanFloatAndDouble));
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.ORDER);
            propertySupport.setLeftOuter(true);
            builderSupport = propertySupport;
        }
    } else if (getColumn().getFunction().getName().equals(Score.NAME)) {
        throw new QueryModelException("Ordering on score() is not supported");
    } else {
        throw new QueryModelException("Ordering not supported " + getColumn().getFunction().getName());
    }
}
Also used : QName(org.alfresco.service.namespace.QName) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument)

Example 13 with QueryModelException

use of org.alfresco.repo.search.impl.querymodel.QueryModelException in project alfresco-repository by Alfresco.

the class DBQuery method findTypeIds.

public static List<Long> findTypeIds(String type, NamespaceService namespaceService, DictionaryService dictionaryService, QNameDAO qnameDAO, boolean exact) {
    ArrayList<Long> qnameIds = new ArrayList<Long>();
    TypeDefinition target = matchTypeDefinition(type, namespaceService, dictionaryService);
    if (target == null) {
        throw new QueryModelException("Invalid type: " + type);
    }
    if (exact) {
        Pair<Long, QName> pair = qnameDAO.getQName(target.getName());
        if (pair != null) {
            Long qnameId = pair.getFirst();
            qnameIds.add(qnameId);
        }
    } else {
        Collection<QName> subclasses = dictionaryService.getSubTypes(target.getName(), true);
        for (QName qname : subclasses) {
            TypeDefinition current = dictionaryService.getType(qname);
            if (target.getName().equals(current.getName()) || current.getIncludedInSuperTypeQuery()) {
                Pair<Long, QName> pair = qnameDAO.getQName(qname);
                if (pair != null) {
                    Long qnameId = pair.getFirst();
                    qnameIds.add(qnameId);
                }
            }
        }
    }
    return qnameIds;
}
Also used : QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 14 with QueryModelException

use of org.alfresco.repo.search.impl.querymodel.QueryModelException in project alfresco-repository by Alfresco.

the class DBQuery method matchAspectDefinition.

public static AspectDefinition matchAspectDefinition(String string, NamespacePrefixResolver namespacePrefixResolver, DictionaryService dictionaryService) {
    QName search = QName.createQName(expandQName(string, namespacePrefixResolver));
    AspectDefinition aspectDefinition = dictionaryService.getAspect(search);
    QName match = null;
    if (aspectDefinition == null) {
        for (QName definition : dictionaryService.getAllAspects()) {
            if (definition.getNamespaceURI().equalsIgnoreCase(search.getNamespaceURI())) {
                if (definition.getLocalName().equalsIgnoreCase(search.getLocalName())) {
                    if (match == null) {
                        match = definition;
                    } else {
                        throw new QueryModelException("Ambiguous data datype " + string);
                    }
                }
            }
        }
    } else {
        return aspectDefinition;
    }
    if (match == null) {
        return null;
    } else {
        return dictionaryService.getAspect(match);
    }
}
Also used : QName(org.alfresco.service.namespace.QName) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition)

Example 15 with QueryModelException

use of org.alfresco.repo.search.impl.querymodel.QueryModelException in project alfresco-repository by Alfresco.

the class DBQuery method getDbid.

public static Long getDbid(String source, NodeDAO nodeDAO, TenantService tenantService) {
    // Ignore version label  for now
    String ref;
    String versionLabel = null;
    String[] split = source.split(";");
    if (split.length == 1) {
        ref = source;
    } else {
        if (split[1].equalsIgnoreCase("PWC")) {
            throw new UnsupportedOperationException("Query for PWC is not supported");
        }
        ref = split[0];
        versionLabel = split[1];
    }
    if (NodeRef.isNodeRef(ref)) {
        NodeRef nodeRef = tenantService.getName(new NodeRef(ref));
        Pair<Long, NodeRef> pair = nodeDAO.getNodePair(nodeRef);
        if (pair == null) {
            throw new QueryModelException("Invalid Object Id " + ref);
        } else {
            return pair.getFirst();
        }
    } else {
        NodeRef nodeRef = new NodeRef(tenantService.getName(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE), ref);
        Pair<Long, NodeRef> pair = nodeDAO.getNodePair(nodeRef);
        if (pair == null) {
            throw new QueryModelException("Invalid Object Id " + ref);
        } else {
            return pair.getFirst();
        }
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException)

Aggregations

QueryModelException (org.alfresco.repo.search.impl.querymodel.QueryModelException)16 QName (org.alfresco.service.namespace.QName)9 ArrayList (java.util.ArrayList)4 Argument (org.alfresco.repo.search.impl.querymodel.Argument)4 PropertyArgument (org.alfresco.repo.search.impl.querymodel.PropertyArgument)4 AnalysisMode (org.alfresco.repo.search.adaptor.lucene.AnalysisMode)3 ParentSupport (org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport)3 PropertySupport (org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport)3 ResultSet (org.alfresco.service.cmr.search.ResultSet)3 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2 Node (org.alfresco.repo.domain.node.Node)2 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)2 FTSQueryException (org.alfresco.repo.search.impl.parsers.FTSQueryException)2 AspectSupport (org.alfresco.repo.search.impl.querymodel.impl.db.AspectSupport)2 TypeSupport (org.alfresco.repo.search.impl.querymodel.impl.db.TypeSupport)2 ChildAssocRefResultSet (org.alfresco.repo.search.results.ChildAssocRefResultSet)2 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)2 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)2 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)2