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
118
119
120
121
122
123
124
125
126
127
128
129
|
/*******************************************************************************
* Copyright (c) 2004, 2007 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.core.internal.search;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.ds.CriteriaSet;
import org.eclipse.osee.orcs.core.ds.Options;
import org.eclipse.osee.orcs.core.ds.OptionsUtil;
import org.eclipse.osee.orcs.core.ds.QueryData;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranch;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.search.ApplicabilityQuery;
import org.eclipse.osee.orcs.search.BranchQuery;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.search.TransactionQuery;
import org.eclipse.osee.orcs.search.TupleQuery;
/**
* @author Roberto E. Escobar
*/
public class QueryFactoryImpl implements QueryFactory {
private final OrcsSession context;
private final CriteriaFactory criteriaFctry;
private final CallableQueryFactory queryFctry;
private final BranchCriteriaFactory branchCriteriaFactory;
private final BranchCallableQueryFactory branchQueryFactory;
private final TransactionCallableQueryFactory txQueryFactory;
private final TransactionCriteriaFactory txCriteriaFactory;
private final ApplicabilityQuery applicabilityQuery;
private final TupleQuery tupleQuery;
public QueryFactoryImpl(OrcsSession context, CriteriaFactory criteriaFctry, CallableQueryFactory queryFctry, BranchCriteriaFactory branchCriteriaFactory, BranchCallableQueryFactory branchQueryFactory, TransactionCallableQueryFactory txQueryFactory, TransactionCriteriaFactory txCriteriaFactory, TupleQuery tupleQuery, ApplicabilityQuery applicabilityQuery) {
super();
this.context = context;
this.criteriaFctry = criteriaFctry;
this.queryFctry = queryFctry;
this.branchCriteriaFactory = branchCriteriaFactory;
this.branchQueryFactory = branchQueryFactory;
this.txQueryFactory = txQueryFactory;
this.txCriteriaFactory = txCriteriaFactory;
this.applicabilityQuery = applicabilityQuery;
this.tupleQuery = tupleQuery;
}
private QueryBuilder createBuilder(Long branchId) {
Options options = OptionsUtil.createOptions();
CriteriaSet criteriaSet = new CriteriaSet();
if (branchId != null) {
criteriaSet.add(new CriteriaBranch(branchId));
}
QueryData queryData = new QueryData(criteriaSet, options);
QueryBuilder builder = new QueryBuilderImpl(queryFctry, criteriaFctry, context, queryData);
return builder;
}
@Override
public BranchQuery branchQuery() {
Options options = OptionsUtil.createOptions();
CriteriaSet criteriaSet = new CriteriaSet();
QueryData queryData = new QueryData(criteriaSet, options);
BranchQueryImpl query = new BranchQueryImpl(branchQueryFactory, branchCriteriaFactory, context, queryData);
return query;
}
@Override
public QueryBuilder fromBranch(BranchId branch) throws OseeCoreException {
Conditions.checkNotNull(branch, "branch");
return fromBranch(branch.getUuid());
}
@Override
public QueryBuilder fromBranch(Long branchId) throws OseeCoreException {
return createBuilder(branchId);
}
@Override
public QueryBuilder fromArtifacts(Collection<? extends ArtifactReadable> artifacts) throws OseeCoreException {
Conditions.checkNotNullOrEmpty(artifacts, "artifacts");
ArtifactReadable artifact = artifacts.iterator().next();
Set<String> guids = new HashSet<>();
for (ArtifactReadable art : artifacts) {
guids.add(art.getGuid());
}
return fromBranch(artifact.getBranchId()).andGuids(guids);
}
@Override
public QueryBuilder fromArtifactTypeAllBranches(IArtifactType artifactType) throws OseeCoreException {
QueryBuilder builder = createBuilder(null);
builder.andIsOfType(artifactType);
return builder;
}
@Override
public TransactionQuery transactionQuery() {
Options options = OptionsUtil.createOptions();
CriteriaSet criteriaSet = new CriteriaSet();
QueryData queryData = new QueryData(criteriaSet, options);
TransactionQueryImpl query = new TransactionQueryImpl(txQueryFactory, txCriteriaFactory, context, queryData);
return query;
}
@Override
public TupleQuery tupleQuery() {
return tupleQuery;
}
@Override
public ApplicabilityQuery applicabilityQuery() {
return applicabilityQuery;
}
}
|