Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

105527: Merged 5.0.N (5.0.3) to HEAD-BUG-FIX (5.1/Cloud)
      105471: MNT-14121: Merged V4.2-BUG-FIX (4.2.5) to 5.0.N (5.0.3) (PARTIAL MERGE)
         104622: Merged DEV to V4.2-BUG-FIX (4.2.5)
            87826: MNT-12133 : CMISQueryService doesn't take into consideration the option QueryConsistency.TRANSACTIONAL
               - Change lucene CMISQueryServiceImpl to use switchable logic depending on QueryConsistency condition


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@105590 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tatyana Valkevych
2015-06-05 11:02:41 +00:00
parent ad12f36e85
commit 5f73ad1ed8
2 changed files with 85 additions and 26 deletions

View File

@@ -6,14 +6,16 @@
<bean id="search.OpenCMISQueryService" class="org.alfresco.opencmis.search.CMISQueryServiceImpl" > <bean id="search.OpenCMISQueryService" class="org.alfresco.opencmis.search.CMISQueryServiceImpl" >
<property name="OpenCMISDictionaryService" ref="OpenCMISDictionaryService" /> <property name="OpenCMISDictionaryService" ref="OpenCMISDictionaryService" />
<property name="queryEngine" ref="search.adm.luceneQueryEngine" /> <property name="luceneQueryEngine" ref="search.adm.luceneQueryEngine" />
<property name="dbQueryEngine" ref="search.dbQueryEngine" />
<property name="nodeService" ref="nodeService" /> <property name="nodeService" ref="nodeService" />
<property name="alfrescoDictionaryService" ref="dictionaryService" /> <property name="alfrescoDictionaryService" ref="dictionaryService" />
</bean> </bean>
<bean id="search.OpenCMISQueryService1.1" class="org.alfresco.opencmis.search.CMISQueryServiceImpl" > <bean id="search.OpenCMISQueryService1.1" class="org.alfresco.opencmis.search.CMISQueryServiceImpl" >
<property name="OpenCMISDictionaryService" ref="OpenCMISDictionaryService1.1" /> <property name="OpenCMISDictionaryService" ref="OpenCMISDictionaryService1.1" />
<property name="queryEngine" ref="search.adm.luceneQueryEngine" /> <property name="luceneQueryEngine" ref="search.adm.luceneQueryEngine" />
<property name="dbQueryEngine" ref="search.dbQueryEngine" />
<property name="nodeService" ref="nodeService" /> <property name="nodeService" ref="nodeService" />
<property name="alfrescoDictionaryService" ref="dictionaryService" /> <property name="alfrescoDictionaryService" ref="dictionaryService" />
</bean> </bean>

View File

@@ -28,13 +28,16 @@ import org.alfresco.repo.search.impl.lucene.PagingLuceneResultSet;
import org.alfresco.repo.search.impl.querymodel.Query; import org.alfresco.repo.search.impl.querymodel.Query;
import org.alfresco.repo.search.impl.querymodel.QueryEngine; import org.alfresco.repo.search.impl.querymodel.QueryEngine;
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults; import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
import org.alfresco.repo.search.impl.querymodel.QueryModelException;
import org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet; import org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.LimitBy; import org.alfresco.service.cmr.search.LimitBy;
import org.alfresco.service.cmr.search.QueryConsistency;
import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.util.Pair;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId; import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
import org.apache.chemistry.opencmis.commons.enums.CapabilityJoin; import org.apache.chemistry.opencmis.commons.enums.CapabilityJoin;
import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery; import org.apache.chemistry.opencmis.commons.enums.CapabilityQuery;
@@ -46,7 +49,8 @@ public class CMISQueryServiceImpl implements CMISQueryService
{ {
private CMISDictionaryService cmisDictionaryService; private CMISDictionaryService cmisDictionaryService;
private QueryEngine queryEngine; private QueryEngine luceneQueryEngine;
private QueryEngine dbQueryEngine;
private NodeService nodeService; private NodeService nodeService;
@@ -59,11 +63,20 @@ public class CMISQueryServiceImpl implements CMISQueryService
/** /**
* @param queryEngine * @param queryEngine
* the queryEngine to set * the luceneQueryEngine to set
*/ */
public void setQueryEngine(QueryEngine queryEngine) public void setLuceneQueryEngine(QueryEngine queryEngine)
{ {
this.queryEngine = queryEngine; this.luceneQueryEngine = queryEngine;
}
/**
* @param queryEngine
* the dbQueryEngine to set
*/
public void setDbQueryEngine(QueryEngine queryEngine)
{
this.dbQueryEngine = queryEngine;
} }
/** /**
@@ -86,26 +99,11 @@ public class CMISQueryServiceImpl implements CMISQueryService
public CMISResultSet query(CMISQueryOptions options) public CMISResultSet query(CMISQueryOptions options)
{ {
CapabilityJoin joinSupport = getJoinSupport(); Pair<Query, QueryEngineResults> resultPair = executeQuerySwitchingImpl(options);
if (options.getQueryMode() == CMISQueryOptions.CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS)
{ Query query = resultPair.getFirst();
joinSupport = CapabilityJoin.INNERONLY; QueryEngineResults results = resultPair.getSecond();
}
// TODO: Refactor to avoid duplication of valid scopes here and in
// CMISQueryParser
BaseTypeId[] validScopes = (options.getQueryMode() == CMISQueryMode.CMS_STRICT) ? CmisFunctionEvaluationContext.STRICT_SCOPES
: CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
functionContext.setCmisDictionaryService(cmisDictionaryService);
functionContext.setNodeService(nodeService);
functionContext.setValidScopes(validScopes);
CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
Query query = parser.parse(queryEngine.getQueryModelFactory(), functionContext);
QueryEngineResults results = queryEngine.executeQuery(query, options, functionContext);
Map<String, ResultSet> wrapped = new HashMap<String, ResultSet>(); Map<String, ResultSet> wrapped = new HashMap<String, ResultSet>();
Map<Set<String>, ResultSet> map = results.getResults(); Map<Set<String>, ResultSet> map = results.getResults();
for (Set<String> group : map.keySet()) for (Set<String> group : map.keySet())
@@ -126,7 +124,66 @@ public class CMISQueryServiceImpl implements CMISQueryService
alfrescoDictionaryService); alfrescoDictionaryService);
return cmis; return cmis;
} }
private Pair<Query, QueryEngineResults> executeQuerySwitchingImpl(CMISQueryOptions options)
{
switch (options.getQueryConsistency())
{
case TRANSACTIONAL_IF_POSSIBLE :
{
try
{
return executeQueryUsingEngine(dbQueryEngine, options);
}
catch(QueryModelException qme)
{
return executeQueryUsingEngine(luceneQueryEngine, options);
}
}
case TRANSACTIONAL :
{
return executeQueryUsingEngine(dbQueryEngine, options);
}
case EVENTUAL :
case DEFAULT :
default :
{
return executeQueryUsingEngine(luceneQueryEngine, options);
}
}
}
private Pair<Query, QueryEngineResults> executeQueryUsingEngine(QueryEngine queryEngine, CMISQueryOptions options)
{
CapabilityJoin joinSupport = getJoinSupport();
if (options.getQueryMode() == CMISQueryOptions.CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS)
{
joinSupport = CapabilityJoin.INNERONLY;
}
// TODO: Refactor to avoid duplication of valid scopes here and in
// CMISQueryParser
BaseTypeId[] validScopes = (options.getQueryMode() == CMISQueryMode.CMS_STRICT) ? CmisFunctionEvaluationContext.STRICT_SCOPES
: CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
functionContext.setCmisDictionaryService(cmisDictionaryService);
functionContext.setNodeService(nodeService);
functionContext.setValidScopes(validScopes);
CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
QueryConsistency queryConsistency = options.getQueryConsistency();
if (queryConsistency == QueryConsistency.DEFAULT)
{
options.setQueryConsistency(QueryConsistency.EVENTUAL);
}
Query query = parser.parse(queryEngine.getQueryModelFactory(), functionContext);
QueryEngineResults queryEngineResults = queryEngine.executeQuery(query, options, functionContext);
return new Pair<Query, QueryEngineResults>(query, queryEngineResults);
}
/* MNT-8804 filter ResultSet for nodes with corrupted indexes */ /* MNT-8804 filter ResultSet for nodes with corrupted indexes */
private ResultSet filterNotExistingNodes(ResultSet resultSet) private ResultSet filterNotExistingNodes(ResultSet resultSet)
{ {