Skip to main content
summaryrefslogtreecommitdiffstats
blob: e21d4e7050d90aeb54b59f70a73e80cf89a7f90d (plain) (blame)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*******************************************************************************
 * 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 org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IRelationTypeSide;
import org.eclipse.osee.framework.core.enums.LoadLevel;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.orcs.core.ds.Criteria;
import org.eclipse.osee.orcs.core.ds.CriteriaSet;
import org.eclipse.osee.orcs.core.ds.QueryOptions;
import org.eclipse.osee.orcs.data.ReadableArtifact;
import org.eclipse.osee.orcs.search.Operator;
import org.eclipse.osee.orcs.search.QueryBuilder;
import org.eclipse.osee.orcs.search.ResultSet;

/**
 * @author Roberto E. Escobar
 */
public class QueryBuilderImpl implements QueryBuilder {

   private final ResultSetFactory rsetFactory;
   private final CriteriaFactory criteriaFactory;

   private final CriteriaSet criteriaSet;
   private final QueryOptions options;

   public QueryBuilderImpl(ResultSetFactory rsetFactory, CriteriaFactory criteriaFactory, CriteriaSet criteriaSet, QueryOptions options) {
      this.rsetFactory = rsetFactory;
      this.criteriaFactory = criteriaFactory;
      this.criteriaSet = criteriaSet;
      this.options = options;
   }

   @Override
   public QueryBuilder includeCache() {
      includeCache(true);
      return this;
   }

   @Override
   public QueryBuilder includeCache(boolean enabled) {
      options.setIncludeCache(enabled);
      return this;
   }

   @Override
   public boolean isCacheIncluded() {
      return options.isCacheIncluded();
   }

   @Override
   public QueryBuilder includeDeleted() {
      includeDeleted(true);
      return this;
   }

   @Override
   public QueryBuilder includeDeleted(boolean enabled) {
      options.setIncludeDeleted(enabled);
      return this;
   }

   @Override
   public boolean areDeletedIncluded() {
      return options.areDeletedIncluded();
   }

   @Override
   public QueryBuilder includeTypeInheritance() {
      includeTypeInheritance(true);
      return this;
   }

   @Override
   public QueryBuilder includeTypeInheritance(boolean enabled) {
      options.setIncludeTypeInheritance(enabled);
      return this;
   }

   @Override
   public boolean isTypeInheritanceIncluded() {
      return options.isTypeInheritanceIncluded();
   }

   @Override
   public QueryBuilder fromTransaction(int transactionId) {
      options.setFromTransaction(transactionId);
      return this;
   }

   @Override
   public int getFromTransaction() {
      return options.getFromTransaction();
   }

   @Override
   public QueryBuilder headTransaction() {
      options.setHeadTransaction();
      return this;
   }

   @Override
   public boolean isHeadTransaction() {
      return options.isHeadTransaction();
   }

   @Override
   public QueryBuilder excludeCache() {
      includeCache(false);
      return this;
   }

   @Override
   public QueryBuilder excludeDeleted() {
      includeDeleted(false);
      return this;
   }

   @Override
   public QueryBuilder excludeTypeInheritance() {
      includeTypeInheritance(false);
      return this;
   }

   @Override
   public QueryBuilder resetToDefaults() {
      options.reset();
      criteriaSet.reset();
      return this;
   }

   @Override
   public QueryBuilder andExists(IAttributeType attributeType) throws OseeCoreException {
      Criteria criteria = criteriaFactory.createExistsCriteria(attributeType);
      return addAndCheck(criteria);
   }

   @Override
   public QueryBuilder andExists(IRelationTypeSide relationType) throws OseeCoreException {
      Criteria criteria = criteriaFactory.createExistsCriteria(relationType);
      return addAndCheck(criteria);
   }

   @Override
   public QueryBuilder and(IAttributeType attributeType, Operator operator, String value) throws OseeCoreException {
      Criteria criteria = criteriaFactory.createAttributeCriteria(attributeType, operator, value);
      return addAndCheck(criteria);
   }

   @Override
   public QueryBuilder and(IAttributeType attributeType, Operator operator, Collection<String> values) throws OseeCoreException {
      Criteria criteria = criteriaFactory.createAttributeCriteria(attributeType, operator, values);
      return addAndCheck(criteria);
   }

   private QueryBuilder addAndCheck(Criteria criteria) throws OseeCoreException {
      criteria.checkValid(options);
      criteriaSet.add(criteria);
      return this;
   }

   @Override
   public ResultSet<ReadableArtifact> build(LoadLevel loadLevel) throws OseeCoreException {
      return rsetFactory.createResultSet(criteriaSet.clone(), options.clone());
   }

   @Override
   public int getCount() throws OseeCoreException {
      return rsetFactory.getCount(criteriaSet.clone(), options.clone());
   }
}

Back to the top