1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/*******************************************************************************
* Copyright (c) 2012 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.orcs.db.internal.search;
import static org.eclipse.osee.orcs.db.internal.search.handlers.SqlHandlerFactoryUtil.createArtifactSqlHandlerFactory;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.osee.executor.admin.ExecutorAdmin;
import org.eclipse.osee.framework.core.model.cache.BranchCache;
import org.eclipse.osee.framework.core.services.IdentityService;
import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.resource.management.IResourceManager;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.core.ds.DataPostProcessorFactory;
import org.eclipse.osee.orcs.core.ds.QueryEngineIndexer;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeKeywords;
import org.eclipse.osee.orcs.db.internal.SqlProvider;
import org.eclipse.osee.orcs.db.internal.search.indexer.IndexerCallableFactory;
import org.eclipse.osee.orcs.db.internal.search.indexer.IndexerCallableFactoryImpl;
import org.eclipse.osee.orcs.db.internal.search.indexer.IndexerConstants;
import org.eclipse.osee.orcs.db.internal.search.indexer.IndexingTaskConsumer;
import org.eclipse.osee.orcs.db.internal.search.indexer.IndexingTaskConsumerImpl;
import org.eclipse.osee.orcs.db.internal.search.indexer.QueryEngineIndexerImpl;
import org.eclipse.osee.orcs.db.internal.search.indexer.QueueToAttributeLoader;
import org.eclipse.osee.orcs.db.internal.search.indexer.data.QueueToAttributeLoaderImpl;
import org.eclipse.osee.orcs.db.internal.search.language.EnglishLanguage;
import org.eclipse.osee.orcs.db.internal.search.tagger.DefaultAttributeTagger;
import org.eclipse.osee.orcs.db.internal.search.tagger.StreamMatcher;
import org.eclipse.osee.orcs.db.internal.search.tagger.TagEncoder;
import org.eclipse.osee.orcs.db.internal.search.tagger.TagProcessor;
import org.eclipse.osee.orcs.db.internal.search.tagger.Tagger;
import org.eclipse.osee.orcs.db.internal.search.tagger.TaggingEngine;
import org.eclipse.osee.orcs.db.internal.search.tagger.XmlAttributeTagger;
import org.eclipse.osee.orcs.db.internal.search.util.DataPostProcessorFactoryImpl;
import org.eclipse.osee.orcs.db.internal.search.util.MatcherFactory;
import org.eclipse.osee.orcs.db.internal.sql.SqlHandlerFactory;
/**
* @author Roberto E. Escobar
*/
public class QueryModule {
private final Log logger;
private final ExecutorAdmin executorAdmin;
private final IOseeDatabaseService dbService;
private final IdentityService idService;
private final SqlProvider sqlProvider;
private TaggingEngine taggingEngine;
private QueryEngineIndexer queryIndexer;
public QueryModule(Log logger, ExecutorAdmin executorAdmin, IOseeDatabaseService dbService, IdentityService idService, SqlProvider sqlProvider) {
super();
this.logger = logger;
this.executorAdmin = executorAdmin;
this.dbService = dbService;
this.idService = idService;
this.sqlProvider = sqlProvider;
}
public void startIndexer(IResourceManager resourceManager) throws Exception {
taggingEngine = createTaggingEngine();
executorAdmin.createFixedPoolExecutor(IndexerConstants.INDEXING_CONSUMER_EXECUTOR_ID, 4);
queryIndexer = createQueryEngineIndexer(taggingEngine, resourceManager);
}
public void stopIndexer() throws Exception {
queryIndexer = null;
taggingEngine = null;
executorAdmin.shutdown(IndexerConstants.INDEXING_CONSUMER_EXECUTOR_ID);
}
public QueryEngineIndexer getQueryIndexer() {
return queryIndexer;
}
public QueryEngineImpl createQueryEngine(BranchCache branchCache) {
DataPostProcessorFactory<CriteriaAttributeKeywords> postProcessor =
createAttributeKeywordPostProcessor(taggingEngine);
SqlHandlerFactory handlerFactory =
createArtifactSqlHandlerFactory(logger, idService, taggingEngine.getTagProcessor(), postProcessor);
return new QueryEngineImpl(logger, dbService, sqlProvider, branchCache, handlerFactory);
}
protected TaggingEngine createTaggingEngine() {
TagProcessor tagProcessor = new TagProcessor(new EnglishLanguage(logger), new TagEncoder());
Map<String, Tagger> taggers = new HashMap<String, Tagger>();
StreamMatcher matcher = MatcherFactory.createMatcher();
taggers.put("DefaultAttributeTaggerProvider", new DefaultAttributeTagger(tagProcessor, matcher));
taggers.put("XmlAttributeTaggerProvider", new XmlAttributeTagger(tagProcessor, matcher));
return new TaggingEngine(taggers, tagProcessor);
}
protected QueryEngineIndexer createQueryEngineIndexer(TaggingEngine taggingEngine, IResourceManager resourceManager) {
QueueToAttributeLoader resourceLoader =
new QueueToAttributeLoaderImpl(logger, dbService, idService, resourceManager);
IndexerCallableFactory callableFactory =
new IndexerCallableFactoryImpl(logger, dbService, taggingEngine, resourceLoader);
IndexingTaskConsumer indexConsumer = new IndexingTaskConsumerImpl(executorAdmin, callableFactory);
return new QueryEngineIndexerImpl(logger, dbService, idService, indexConsumer);
}
protected DataPostProcessorFactory<CriteriaAttributeKeywords> createAttributeKeywordPostProcessor(TaggingEngine taggingEngine) {
return new DataPostProcessorFactoryImpl(logger, taggingEngine, executorAdmin);
}
}
|