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");
}
}
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());
}
}
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;
}
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);
}
}
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();
}
}
}
Aggregations