Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2011-10-13 05:35:01 +0000
committerRoberto E. Escobar2011-10-13 05:35:01 +0000
commitb929fa41fc7e129666f5e6cd1a1b98a8ebde674f (patch)
tree919f0ed7f0cf824632a8f54baef76ae490ca73ca
parent1e68e80fa7039201ff3b83d24f8088fd363caaf0 (diff)
downloadorg.eclipse.osee-b929fa41fc7e129666f5e6cd1a1b98a8ebde674f.tar.gz
org.eclipse.osee-b929fa41fc7e129666f5e6cd1a1b98a8ebde674f.tar.xz
org.eclipse.osee-b929fa41fc7e129666f5e6cd1a1b98a8ebde674f.zip
feature[ats_Q9NLC]: Implement ORCS Query
Create Sql Query implementation Create Sql Handlers Create SqlBuilder Register query engine service Register sql provider service
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryTest.java29
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/mocks/MockSessionContext.java5
-rw-r--r--plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/CriteriaSet.java35
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java3
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryOptions.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactGuids.java51
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactHrids.java49
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactIds.java40
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactType.java42
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeKeyword.java53
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeOther.java62
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeTypeExists.java41
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaRelationTypeExists.java40
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java21
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SessionContext.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/CriteriaFactory.java42
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryBuilderImpl.java110
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java82
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetFactory.java17
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetImpl.java8
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java24
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoaderTest.java20
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java26
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SearchTestSuite.java23
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SqlBuilderTest.java276
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SqlWriterTest.java220
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockIdentityService.java48
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java67
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/SqlUtility.java53
-rw-r--r--plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF7
-rw-r--r--plugins/org.eclipse.osee.orcs.db/OSGI-INF/query.engine.impl.xml11
-rw-r--r--plugins/org.eclipse.osee.orcs.db/OSGI-INF/sql.provider.impl.xml9
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/SqlProvider.java3
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java1
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryEngineImpl.java73
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlAliasManager.java86
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlBuilder.java85
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlConstants.java59
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlContext.java65
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlHandler.java42
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlHandlerFactory.java24
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlWriter.java200
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactGuidSqlHandler.java78
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactHridsSqlHandler.java78
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactIdsSqlHandler.java78
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactTypeSqlHandler.java99
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeOtherSqlHandler.java113
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTokenSqlHandler.java49
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTypeExistsSqlHandler.java108
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelationTypeExistsSqlHandler.java88
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerComparator.java25
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryImpl.java76
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/StaticSqlProvider.java22
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/ApplicationContext.java2
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/Operator.java12
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryBuilder.java41
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java24
59 files changed, 2931 insertions, 127 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryTest.java
new file mode 100644
index 00000000000..7c2df2b19e9
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryTest.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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 org.eclipse.osee.orcs.search.QueryFactory;
+import org.junit.Test;
+
+/**
+ * Test Case for {@link QueryFactory}
+ *
+ * @author Roberto E. Escobar
+ */
+public class QueryFactoryTest {
+
+ @Test
+ public void testX() {
+ // QueryFactory factory = new QueryFactoryImpl();
+ // factory.fromArtifact(branch, artifactToken);
+
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/mocks/MockSessionContext.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/mocks/MockSessionContext.java
index 55e666d720e..058c053c544 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/mocks/MockSessionContext.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/mocks/MockSessionContext.java
@@ -28,4 +28,9 @@ public class MockSessionContext implements SessionContext {
return null;
}
+ @Override
+ public String getSessionId() {
+ return null;
+ }
+
}
diff --git a/plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF
index 782685c414c..3f4a73f90aa 100644
--- a/plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.core/META-INF/MANIFEST.MF
@@ -20,5 +20,6 @@ Import-Package: org.eclipse.osee.framework.core.data,
org.eclipse.osee.orcs.data,
org.eclipse.osee.orcs.search
Export-Package: org.eclipse.osee.orcs.core,
- org.eclipse.osee.orcs.core.ds
+ org.eclipse.osee.orcs.core.ds,
+ org.eclipse.osee.orcs.core.ds.criteria
Require-Bundle: org.eclipse.core.runtime
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/CriteriaSet.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/CriteriaSet.java
index e37f0adf4d0..75bd20acba4 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/CriteriaSet.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/CriteriaSet.java
@@ -10,27 +10,26 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.ds;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
/**
* @author Roberto E. Escobar
*/
-public class CriteriaSet implements Cloneable {
+public class CriteriaSet implements Cloneable, Iterable<Criteria> {
- private final Set<Criteria> criterias = new HashSet<Criteria>();
- private Criteria baseCriteria;
+ private final List<Criteria> criterias = new LinkedList<Criteria>();
+ private final IOseeBranch branch;
- public CriteriaSet() {
-
- }
-
- public Criteria getBaseCriteria() {
- return baseCriteria;
+ public CriteriaSet(IOseeBranch branch) {
+ this.branch = branch;
}
- public void setBaseCriteria(Criteria baseCriteria) {
- this.baseCriteria = baseCriteria;
+ public IOseeBranch getBranch() {
+ return branch;
}
public void add(Criteria criteria) {
@@ -41,7 +40,7 @@ public class CriteriaSet implements Cloneable {
return criterias.remove(criteria);
}
- public Set<Criteria> getCriterias() {
+ public Collection<Criteria> getCriterias() {
return criterias;
}
@@ -51,10 +50,14 @@ public class CriteriaSet implements Cloneable {
@Override
public CriteriaSet clone() {
- CriteriaSet clone = new CriteriaSet();
- clone.baseCriteria = this.baseCriteria;
+ CriteriaSet clone = new CriteriaSet(this.branch);
clone.criterias.addAll(this.criterias);
return clone;
}
+ @Override
+ public Iterator<Criteria> iterator() {
+ return criterias.iterator();
+ }
+
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java
index 40cb96d192d..b2c27aeffb4 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryEngine.java
@@ -14,6 +14,7 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException;
public interface QueryEngine {
- Object create(CriteriaSet criteriaSet, QueryOptions options) throws OseeCoreException;
+ Object createCount(String sessionId, CriteriaSet criteriaSet, QueryOptions options) throws OseeCoreException;
+ Object create(String sessionId, CriteriaSet criteriaSet, QueryOptions options) throws OseeCoreException;
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryOptions.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryOptions.java
index 5d6a60a86bb..033ee807ac9 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryOptions.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryOptions.java
@@ -76,6 +76,10 @@ public class QueryOptions implements Cloneable {
includeTypeInheritance = enabled;
}
+ public boolean isHistorical() {
+ return !isHeadTransaction();
+ }
+
@Override
public String toString() {
return "QueryOptions [includeCache=" + includeCache + ", includeDeleted=" + includeDeleted + ", includeTypeInheritance=" + includeTypeInheritance + ", transactionId=" + transactionId + "]";
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactGuids.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactGuids.java
new file mode 100644
index 00000000000..f9566adf9b0
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactGuids.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.ds.criteria;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.QueryOptions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaArtifactGuids extends Criteria {
+
+ private final Collection<String> artifactGuids;
+
+ public CriteriaArtifactGuids(Collection<String> artifactGuids) {
+ super();
+ this.artifactGuids = artifactGuids;
+ }
+
+ @Override
+ public void checkValid(QueryOptions options) throws OseeCoreException {
+ super.checkValid(options);
+ Conditions.checkNotNullOrEmpty(artifactGuids, "artifact guids");
+ List<String> invalids = new ArrayList<String>();
+ for (String guid : artifactGuids) {
+ if (!GUID.isValid(guid)) {
+ invalids.add(guid);
+ }
+ }
+ Conditions.checkExpressionFailOnTrue(!invalids.isEmpty(), "Invalid Guids - %s", invalids);
+ }
+
+ public Collection<String> getIds() {
+ return artifactGuids;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactHrids.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactHrids.java
new file mode 100644
index 00000000000..efbb4171af0
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactHrids.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.ds.criteria;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.HumanReadableId;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.QueryOptions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaArtifactHrids extends Criteria {
+ private final Collection<String> hrids;
+
+ public CriteriaArtifactHrids(Collection<String> hrids) {
+ super();
+ this.hrids = hrids;
+ }
+
+ @Override
+ public void checkValid(QueryOptions options) throws OseeCoreException {
+ super.checkValid(options);
+ Conditions.checkNotNullOrEmpty(hrids, "artifact hrids");
+ List<String> invalids = new ArrayList<String>();
+ for (String hrid : hrids) {
+ if (!HumanReadableId.isValid(hrid)) {
+ invalids.add(hrid);
+ }
+ }
+ Conditions.checkExpressionFailOnTrue(!invalids.isEmpty(), "Invalid Hrids - %s", invalids);
+ }
+
+ public Collection<String> getIds() {
+ return hrids;
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactIds.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactIds.java
new file mode 100644
index 00000000000..935b1e64dae
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactIds.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.ds.criteria;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.QueryOptions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaArtifactIds extends Criteria {
+
+ private final Collection<Integer> ids;
+
+ public CriteriaArtifactIds(Collection<Integer> ids) {
+ super();
+ this.ids = ids;
+ }
+
+ @Override
+ public void checkValid(QueryOptions options) throws OseeCoreException {
+ super.checkValid(options);
+ Conditions.checkNotNullOrEmpty(ids, "artifact ids");
+ }
+
+ public Collection<Integer> getIds() {
+ return ids;
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactType.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactType.java
new file mode 100644
index 00000000000..19e70ed5774
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaArtifactType.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.ds.criteria;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.QueryOptions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaArtifactType extends Criteria {
+
+ private final Collection<? extends IArtifactType> artifactTypes;
+
+ public CriteriaArtifactType(Collection<? extends IArtifactType> artifactTypes) {
+ super();
+ this.artifactTypes = artifactTypes;
+ }
+
+ @Override
+ public void checkValid(QueryOptions options) throws OseeCoreException {
+ super.checkValid(options);
+ Conditions.checkNotNullOrEmpty(artifactTypes, "artifact types");
+ }
+
+ public Collection<? extends IArtifactType> getTypes() {
+ return artifactTypes;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeKeyword.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeKeyword.java
new file mode 100644
index 00000000000..7a7cf067354
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeKeyword.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.ds.criteria;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.search.CaseType;
+import org.eclipse.osee.orcs.search.StringOperator;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaAttributeKeyword extends Criteria {
+
+ private final IAttributeType attributeType;
+ private final Collection<String> values;
+ private final StringOperator stringOp;
+ private final CaseType match;
+
+ public CriteriaAttributeKeyword(IAttributeType attributeType, Collection<String> values, StringOperator stringOp, CaseType match) {
+ super();
+ this.attributeType = attributeType;
+ this.values = values;
+ this.stringOp = stringOp;
+ this.match = match;
+ }
+
+ public IAttributeType getAttributeType() {
+ return attributeType;
+ }
+
+ public Collection<String> getValues() {
+ return values;
+ }
+
+ public StringOperator getStringOp() {
+ return stringOp;
+ }
+
+ public CaseType getMatch() {
+ return match;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeOther.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeOther.java
new file mode 100644
index 00000000000..a165cae8efd
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeOther.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.ds.criteria;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.QueryOptions;
+import org.eclipse.osee.orcs.search.Operator;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaAttributeOther extends Criteria {
+
+ private final IAttributeType attributeType;
+ private final Collection<String> values;
+ private final Operator operator;
+
+ public CriteriaAttributeOther(IAttributeType attributeType, Collection<String> values, Operator operator) {
+ super();
+ this.attributeType = attributeType;
+ this.values = values;
+ this.operator = operator;
+ }
+
+ public IAttributeType getAttributeType() {
+ return attributeType;
+ }
+
+ public Collection<String> getValues() {
+ return values;
+ }
+
+ public Operator getOperator() {
+ return operator;
+ }
+
+ @Override
+ public void checkValid(QueryOptions options) throws OseeCoreException {
+ super.checkValid(options);
+ Operator operator = getOperator();
+ for (String value : getValues()) {
+ if (value != null && value.contains("%") && operator.isGreaterThanOrLessThan()) {
+ throw new OseeArgumentException(
+ "When value contains %%, one of the following operators must be used: %s, %s", Operator.EQUAL,
+ Operator.NOT_EQUAL);
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeTypeExists.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeTypeExists.java
new file mode 100644
index 00000000000..fc1a764e246
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaAttributeTypeExists.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.ds.criteria;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.QueryOptions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaAttributeTypeExists extends Criteria {
+
+ private final Collection<? extends IAttributeType> attributeTypes;
+
+ public CriteriaAttributeTypeExists(Collection<? extends IAttributeType> attributeTypes) {
+ super();
+ this.attributeTypes = attributeTypes;
+ }
+
+ public Collection<? extends IAttributeType> getTypes() {
+ return attributeTypes;
+ }
+
+ @Override
+ public void checkValid(QueryOptions options) throws OseeCoreException {
+ super.checkValid(options);
+ Conditions.checkNotNullOrEmpty(getTypes(), "attribute types");
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaRelationTypeExists.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaRelationTypeExists.java
new file mode 100644
index 00000000000..b2b9b5a969a
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaRelationTypeExists.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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.ds.criteria;
+
+import org.eclipse.osee.framework.core.data.IRelationTypeSide;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.QueryOptions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaRelationTypeExists extends Criteria {
+ private final IRelationTypeSide relationType;
+
+ public CriteriaRelationTypeExists(IRelationTypeSide relationType) {
+ super();
+ this.relationType = relationType;
+ }
+
+ public IRelationTypeSide getType() {
+ return relationType;
+ }
+
+ @Override
+ public void checkValid(QueryOptions options) throws OseeCoreException {
+ super.checkValid(options);
+ Conditions.checkNotNull(getType(), "relation type side");
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java
index 6f1687f6015..57f6ae792c4 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/OrcsApiImpl.java
@@ -1,19 +1,30 @@
-/*
- * Created on Oct 10, 2011
+/*******************************************************************************
+ * 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
*
- * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
- */
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
package org.eclipse.osee.orcs.core.internal;
import org.eclipse.osee.orcs.ApplicationContext;
import org.eclipse.osee.orcs.OseeApi;
+import org.eclipse.osee.orcs.core.internal.search.QueryFactoryImpl;
import org.eclipse.osee.orcs.search.QueryFactory;
+/**
+ * @author Roberto E. Escobar
+ */
public class OrcsApiImpl implements OseeApi {
+ private final QueryFactoryImpl queryFactory = new QueryFactoryImpl();
+
@Override
public QueryFactory getQueryFactory(ApplicationContext context) {
- return null;
+ return queryFactory;
}
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SessionContext.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SessionContext.java
index d0d08ac182d..995d6d9f26e 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SessionContext.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/SessionContext.java
@@ -17,6 +17,8 @@ import org.eclipse.osee.orcs.core.ds.AttributeContainer;
*/
public interface SessionContext {
+ String getSessionId();
+
<T extends AttributeContainer> T getHistorical(int artId, int stripeId);
<T extends AttributeContainer> T getActive(int artId, int branchId);
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/CriteriaFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/CriteriaFactory.java
index 5c9f5eaba47..65ee5bb4a55 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/CriteriaFactory.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/CriteriaFactory.java
@@ -11,11 +11,23 @@
package org.eclipse.osee.orcs.core.internal.search;
import java.util.Collection;
+import java.util.Set;
+import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IRelationTypeSide;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactGuids;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactHrids;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactIds;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactType;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeOther;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeKeyword;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeTypeExists;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists;
+import org.eclipse.osee.orcs.search.CaseType;
import org.eclipse.osee.orcs.search.Operator;
+import org.eclipse.osee.orcs.search.StringOperator;
/**
* @author Roberto E. Escobar
@@ -23,20 +35,36 @@ import org.eclipse.osee.orcs.search.Operator;
@SuppressWarnings("unused")
public class CriteriaFactory {
- public Criteria createExistsCriteria(IAttributeType attributeType) throws OseeCoreException {
- return null;
+ public Criteria createExistsCriteria(Collection<? extends IAttributeType> attributeTypes) throws OseeCoreException {
+ return new CriteriaAttributeTypeExists(attributeTypes);
}
public Criteria createExistsCriteria(IRelationTypeSide relationType) throws OseeCoreException {
- return null;
+ return new CriteriaRelationTypeExists(relationType);
}
- public Criteria createAttributeCriteria(IAttributeType attributeType, Operator operator, String value) throws OseeCoreException {
- return null;
+ public Criteria createAttributeCriteria(IAttributeType attributeType, Operator operator, Collection<String> values) throws OseeCoreException {
+ return new CriteriaAttributeOther(attributeType, values, operator);
}
- public Criteria createAttributeCriteria(IAttributeType attributeType, Operator operator, Collection<String> values) throws OseeCoreException {
- return null;
+ public Criteria createAttributeCriteria(IAttributeType attributeType, StringOperator operator, CaseType match, Collection<String> values) throws OseeCoreException {
+ return new CriteriaAttributeKeyword(attributeType, values, operator, match);
+ }
+
+ public Criteria createArtifactTypeCriteria(Collection<? extends IArtifactType> artifactTypes) throws OseeCoreException {
+ return new CriteriaArtifactType(artifactTypes);
+ }
+
+ public Criteria createArtifactIdCriteria(Collection<Integer> artifactIds) throws OseeCoreException {
+ return new CriteriaArtifactIds(artifactIds);
+ }
+
+ public Criteria createArtifactGuidCriteria(Set<String> guids) throws OseeCoreException {
+ return new CriteriaArtifactGuids(guids);
+ }
+
+ public Criteria createArtifactHridCriteria(Set<String> hrids) throws OseeCoreException {
+ return new CriteriaArtifactHrids(hrids);
}
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryBuilderImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryBuilderImpl.java
index 56b55775c41..08b2c2d5ccd 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryBuilderImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryBuilderImpl.java
@@ -10,11 +10,19 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.internal.search;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+import org.eclipse.osee.framework.core.data.IArtifactType;
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.framework.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.jdk.core.util.HumanReadableId;
import org.eclipse.osee.orcs.core.ds.Criteria;
import org.eclipse.osee.orcs.core.ds.CriteriaSet;
import org.eclipse.osee.orcs.core.ds.QueryOptions;
@@ -144,8 +152,72 @@ public class QueryBuilderImpl implements QueryBuilder {
}
@Override
- public QueryBuilder andExists(IAttributeType attributeType) throws OseeCoreException {
- Criteria criteria = criteriaFactory.createExistsCriteria(attributeType);
+ public QueryBuilder withLocalId(int... artifactIds) throws OseeCoreException {
+ Set<Integer> ids = new HashSet<Integer>();
+ for (Integer id : artifactIds) {
+ ids.add(id);
+ }
+ return withLocalIds(ids);
+ }
+
+ @Override
+ public QueryBuilder withGuidsOrHrids(String... ids) throws OseeCoreException {
+ return withGuidsOrHrids(Arrays.asList(ids));
+ }
+
+ @Override
+ public QueryBuilder withLocalIds(Collection<Integer> artifactIds) throws OseeCoreException {
+ Criteria criteria = criteriaFactory.createArtifactIdCriteria(artifactIds);
+ return addAndCheck(criteria);
+ }
+
+ @Override
+ public QueryBuilder withGuidsOrHrids(Collection<String> ids) throws OseeCoreException {
+ Set<String> guids = new HashSet<String>();
+ Set<String> hrids = new HashSet<String>();
+ Set<String> invalids = new HashSet<String>();
+ for (String id : ids) {
+ if (GUID.isValid(id)) {
+ guids.add(id);
+ } else if (HumanReadableId.isValid(id)) {
+ hrids.add(id);
+ } else {
+ invalids.add(id);
+ }
+ }
+ Conditions.checkExpressionFailOnTrue(!invalids.isEmpty(), "Invalid guids or hrids detected - %s", invalids);
+ if (guids.isEmpty()) {
+ Criteria guidCriteria = criteriaFactory.createArtifactGuidCriteria(guids);
+ addAndCheck(guidCriteria);
+ }
+
+ if (hrids.isEmpty()) {
+ Criteria hridCriteria = criteriaFactory.createArtifactHridCriteria(hrids);
+ addAndCheck(hridCriteria);
+ }
+ return this;
+ }
+
+ @Override
+ public QueryBuilder and(IArtifactType... artifactType) throws OseeCoreException {
+ Criteria criteria = criteriaFactory.createArtifactTypeCriteria(Arrays.asList(artifactType));
+ return addAndCheck(criteria);
+ }
+
+ @Override
+ public QueryBuilder and(Collection<? extends IArtifactType> artifactType) throws OseeCoreException {
+ Criteria criteria = criteriaFactory.createArtifactTypeCriteria(artifactType);
+ return addAndCheck(criteria);
+ }
+
+ @Override
+ public QueryBuilder andExists(IAttributeType... attributeType) throws OseeCoreException {
+ return andExists(Arrays.asList(attributeType));
+ }
+
+ @Override
+ public QueryBuilder andExists(Collection<? extends IAttributeType> attributeTypes) throws OseeCoreException {
+ Criteria criteria = criteriaFactory.createExistsCriteria(attributeTypes);
return addAndCheck(criteria);
}
@@ -157,7 +229,8 @@ public class QueryBuilderImpl implements QueryBuilder {
@Override
public QueryBuilder and(IAttributeType attributeType, Operator operator, String value) throws OseeCoreException {
- Criteria criteria = criteriaFactory.createAttributeCriteria(attributeType, operator, value);
+ Criteria criteria =
+ criteriaFactory.createAttributeCriteria(attributeType, operator, Collections.singleton(value));
return addAndCheck(criteria);
}
@@ -167,6 +240,19 @@ public class QueryBuilderImpl implements QueryBuilder {
return addAndCheck(criteria);
}
+ @Override
+ public QueryBuilder and(IAttributeType attributeType, StringOperator operator, CaseType match, String value) throws OseeCoreException {
+ Criteria criteria =
+ criteriaFactory.createAttributeCriteria(attributeType, operator, match, Collections.singleton(value));
+ return addAndCheck(criteria);
+ }
+
+ @Override
+ public QueryBuilder and(IAttributeType attributeType, StringOperator operator, CaseType match, Collection<String> values) throws OseeCoreException {
+ Criteria criteria = criteriaFactory.createAttributeCriteria(attributeType, operator, match, values);
+ return addAndCheck(criteria);
+ }
+
private QueryBuilder addAndCheck(Criteria criteria) throws OseeCoreException {
criteria.checkValid(options);
criteriaSet.add(criteria);
@@ -179,22 +265,12 @@ public class QueryBuilderImpl implements QueryBuilder {
}
@Override
- public int getCount() throws OseeCoreException {
- return rsetFactory.getCount(criteriaSet.clone(), options.clone());
- }
-
- @Override
- public QueryBuilder and(IAttributeType attributeType, StringOperator operator, CaseType match, String value) throws OseeCoreException {
- return null;
- }
-
- @Override
- public QueryBuilder and(IAttributeType attributeType, StringOperator operator, CaseType match, Collection<String> values) throws OseeCoreException {
- return null;
+ public ResultSet<Match<ReadableArtifact, ReadableAttribute<?>>> buildMatches(LoadLevel loadLevel) throws OseeCoreException {
+ return rsetFactory.createMatchesResultSet(criteriaSet.clone(), options.clone());
}
@Override
- public ResultSet<Match<ReadableArtifact, ReadableAttribute<?>>> buildMatches(LoadLevel loadLevel) throws OseeCoreException {
- return null;
+ public int getCount() throws OseeCoreException {
+ return rsetFactory.getCount(criteriaSet.clone(), options.clone());
}
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java
index 3681a7b81a4..65b469af012 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java
@@ -11,14 +11,19 @@
package org.eclipse.osee.orcs.core.internal.search;
import java.util.Collection;
-import java.util.List;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.osee.framework.core.data.IArtifactToken;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
-import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
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.QueryFactory;
@@ -30,66 +35,85 @@ public class QueryFactoryImpl implements QueryFactory {
private final CriteriaFactory criteriaFctry = new CriteriaFactory();
private final ResultSetFactory rsetFctry = new ResultSetFactory();
- private QueryBuilder createBuilder(Criteria baseCriteria) {
+ @SuppressWarnings("unused")
+ private QueryBuilder createBuilder(IOseeBranch branch) throws OseeCoreException {
QueryOptions options = new QueryOptions();
- CriteriaSet criteriaSet = new CriteriaSet();
- criteriaSet.setBaseCriteria(baseCriteria);
- return new QueryBuilderImpl(rsetFctry, criteriaFctry, criteriaSet, options);
+ CriteriaSet criteriaSet = new CriteriaSet(branch);
+ QueryBuilder builder = new QueryBuilderImpl(rsetFctry, criteriaFctry, criteriaSet, options);
+ return builder;
}
@Override
- public QueryBuilder fromBranch(IOseeBranch branch) {
- return null;
+ public QueryBuilder fromBranch(IOseeBranch branch) throws OseeCoreException {
+ return createBuilder(branch);
}
@Override
- public QueryBuilder fromArtifactType(IOseeBranch branch, IArtifactType artifactType) {
- return null;
+ public QueryBuilder fromArtifactType(IOseeBranch branch, IArtifactType artifactType) throws OseeCoreException {
+ return fromArtifactTypes(branch, Collections.singleton(artifactType));
}
@Override
- public QueryBuilder fromArtifactTypes(IOseeBranch branch, Collection<? extends IArtifactType> artifactTypes) {
- return null;
+ public QueryBuilder fromArtifactTypes(IOseeBranch branch, Collection<? extends IArtifactType> artifactTypes) throws OseeCoreException {
+ QueryBuilder builder = fromBranch(branch);
+ builder.and(artifactTypes);
+ return builder;
}
@Override
- public QueryBuilder fromArtifactTypeAllBranches(IArtifactType artifactType) {
- return null;
+ public QueryBuilder fromUuids(IOseeBranch branch, Collection<Integer> artifactIds) throws OseeCoreException {
+ QueryBuilder builder = fromBranch(branch);
+ builder.withLocalIds(artifactIds);
+ return builder;
}
@Override
- public QueryBuilder fromUuids(IOseeBranch branch, Collection<Integer> artifactIds) {
- return null;
+ public QueryBuilder fromGuidOrHrid(IOseeBranch branch, String guidOrHrid) throws OseeCoreException {
+ return fromGuidOrHrids(branch, Collections.singleton(guidOrHrid));
}
@Override
- public QueryBuilder fromGuidOrHrid(IOseeBranch branch, String guidOrHrid) {
- return null;
+ public QueryBuilder fromGuidOrHrids(IOseeBranch branch, Collection<String> guidOrHrids) throws OseeCoreException {
+ QueryBuilder builder = fromBranch(branch);
+ builder.withGuidsOrHrids(guidOrHrids);
+ return builder;
}
@Override
- public QueryBuilder fromGuidOrHrids(IOseeBranch branch, List<String> guidOrHrids) {
- return null;
+ public QueryBuilder fromArtifact(IOseeBranch branch, IArtifactToken artifactToken) throws OseeCoreException {
+ return fromGuidOrHrid(branch, artifactToken.getGuid());
}
@Override
- public QueryBuilder fromArtifact(IOseeBranch branch, IArtifactToken artifactToken) {
- return null;
+ public QueryBuilder fromArtifacts(Collection<? extends ReadableArtifact> artifacts) throws OseeCoreException {
+ Conditions.checkNotNullOrEmpty(artifacts, "artifacts");
+ ReadableArtifact artifact = artifacts.iterator().next();
+ IOseeBranch branch = artifact.getBranch();
+ Set<String> guids = new HashSet<String>();
+ for (ReadableArtifact art : artifacts) {
+ guids.add(art.getGuid());
+ }
+ return fromGuidOrHrids(branch, guids);
}
@Override
- public QueryBuilder fromArtifacts(Collection<? extends ReadableArtifact> artifacts) {
- return null;
+ public QueryBuilder fromName(IOseeBranch branch, String artifactName) throws OseeCoreException {
+ QueryBuilder builder = fromBranch(branch);
+ builder.and(CoreAttributeTypes.Name, Operator.EQUAL, artifactName);
+ return builder;
}
@Override
- public QueryBuilder fromName(IOseeBranch branch, String artifactName) {
- return null;
+ public QueryBuilder fromArtifactTypeAndName(IOseeBranch branch, IArtifactType artifactType, String artifactName) throws OseeCoreException {
+ QueryBuilder builder = fromArtifactType(branch, artifactType);
+ builder.and(CoreAttributeTypes.Name, Operator.EQUAL, artifactName);
+ return builder;
}
@Override
- public QueryBuilder fromArtifactTypeAndName(IOseeBranch branch, IArtifactType artifactType, String artifactName) {
- return null;
+ public QueryBuilder fromArtifactTypeAllBranches(IArtifactType artifactType) throws OseeCoreException {
+ QueryBuilder builder = createBuilder(null);
+ builder.and(artifactType);
+ return builder;
}
-
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetFactory.java
index ea9bf7d9171..6c4b98614cb 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetFactory.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetFactory.java
@@ -16,13 +16,18 @@ import org.eclipse.osee.orcs.core.ds.CriteriaSet;
import org.eclipse.osee.orcs.core.ds.QueryEngine;
import org.eclipse.osee.orcs.core.ds.QueryOptions;
import org.eclipse.osee.orcs.data.ReadableArtifact;
+import org.eclipse.osee.orcs.data.ReadableAttribute;
+import org.eclipse.osee.orcs.search.Match;
import org.eclipse.osee.orcs.search.ResultSet;
/**
* @author Roberto E. Escobar
*/
+@SuppressWarnings("unused")
public class ResultSetFactory {
+ // TODO implements ResultSetFactory tie in with ArtifactLoader
+
private Log logger;
private QueryEngine queryEngine;
@@ -32,7 +37,17 @@ public class ResultSetFactory {
return new ResultSetImpl(queryEngine, criteriaSet, options);
}
+ public ResultSet<Match<ReadableArtifact, ReadableAttribute<?>>> createMatchesResultSet(CriteriaSet criteriaSet, QueryOptions options) throws OseeCoreException {
+ // return new ResultSetImpl(queryEngine, criteriaSet, options)
+ return null;
+ }
+
public int getCount(CriteriaSet criteriaSet, QueryOptions options) throws OseeCoreException {
- return -1;
+ String sessionId = "fromContext";
+ Object object = queryEngine.createCount(sessionId, criteriaSet, options);
+ // Execute Query
+ // Return results;
+ int results = -1;
+ return results;
}
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetImpl.java
index dfd18e97e29..0eb1ef30fc3 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/ResultSetImpl.java
@@ -21,8 +21,10 @@ import org.eclipse.osee.orcs.search.ResultSet;
/**
* @author Roberto E. Escobar
*/
+@SuppressWarnings("unused")
public class ResultSetImpl implements ResultSet<ReadableArtifact> {
+ // TODO implements ResultSetFactory tie in with ArtifactLoader
private final QueryEngine queryEngine;
private final CriteriaSet criteriaSet;
private final QueryOptions options;
@@ -36,9 +38,8 @@ public class ResultSetImpl implements ResultSet<ReadableArtifact> {
@Override
public ReadableArtifact getOneOrNull() throws OseeCoreException {
- // SearchCallable callable = queryEngine.search(criteriaSet, options);
- // LoaderCallable callable = loader.load(search);
- // ArtifactFactory
+ // SearchCallable call = queryEngine.search(criteriaSet, options);
+ // LoaderCallable call = loader.load(search);
return null;
}
@@ -49,6 +50,7 @@ public class ResultSetImpl implements ResultSet<ReadableArtifact> {
@Override
public List<ReadableArtifact> getList() throws OseeCoreException {
+
return null;
}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.java
index 1eb27fd4f73..bf8b6a1cecb 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/InternalTestSuite.java
@@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.osee.orcs.db.internal;
-import org.eclipse.osee.orcs.db.internal.proxy.ClobDataProxyTest;
import org.eclipse.osee.orcs.db.internal.proxy.ProxyTestSuite;
+import org.eclipse.osee.orcs.db.internal.search.SearchTestSuite;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -19,7 +19,7 @@ import org.junit.runners.Suite;
* @author Roberto E. Escobar
*/
@RunWith(Suite.class)
-@Suite.SuiteClasses({ClobDataProxyTest.class, ProxyTestSuite.class})
+@Suite.SuiteClasses({ProxyTestSuite.class, SearchTestSuite.class})
public class InternalTestSuite {
// Test Suite
}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java
index e0503ddd4d4..9703b0508a8 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/ArtifactLoaderTest.java
@@ -22,14 +22,16 @@ import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.database.core.ArtifactJoinQuery;
import org.eclipse.osee.framework.database.core.JoinUtility;
import org.eclipse.osee.framework.database.core.OseeConnection;
+import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.core.ds.ArtifactRow;
import org.eclipse.osee.orcs.core.ds.ArtifactRowHandler;
-import org.eclipse.osee.orcs.db.internal.SqlProvider;
import org.eclipse.osee.orcs.db.internal.sql.StaticSqlProvider;
import org.eclipse.osee.orcs.db.mock.H2Preferences;
import org.eclipse.osee.orcs.db.mock.MockLog;
import org.eclipse.osee.orcs.db.mock.OseeDatabase;
import org.eclipse.osee.orcs.db.mock.OsgiUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Rule;
public class ArtifactLoaderTest {
@@ -37,12 +39,26 @@ public class ArtifactLoaderTest {
@Rule
public OseeDatabase db = new OseeDatabase("osee.demo.h2");
+ private static StaticSqlProvider sqlProvider;
+ private static Log log;
+
+ @BeforeClass
+ public static void setUp() {
+ log = new MockLog();
+ sqlProvider = new StaticSqlProvider();
+ sqlProvider.setLogger(new MockLog());
+ sqlProvider.setPreferences(new H2Preferences());
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ sqlProvider = null;
+ }
+
@org.junit.Test
public void testArtifactLoadingData() throws OseeCoreException {
IOseeDatabaseService oseeDbService = OsgiUtil.getService(IOseeDatabaseService.class);
IdentityService identityService = OsgiUtil.getService(IdentityService.class);
- MockLog log = new MockLog();
- SqlProvider sqlProvider = new StaticSqlProvider(log, new H2Preferences());
ArtifactLoader loader = new ArtifactLoader(log, sqlProvider, oseeDbService, identityService);
@@ -93,8 +109,6 @@ public class ArtifactLoaderTest {
IOseeDatabaseService oseeDbService = OsgiUtil.getService(IOseeDatabaseService.class);
IdentityService identityService = OsgiUtil.getService(IdentityService.class);
- MockLog log = new MockLog();
- SqlProvider sqlProvider = new StaticSqlProvider(log, new H2Preferences());
ArtifactLoader loader = new ArtifactLoader(log, sqlProvider, oseeDbService, identityService);
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoaderTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoaderTest.java
index 86bc6d6233f..76d44fca346 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoaderTest.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/AttributeLoaderTest.java
@@ -25,7 +25,6 @@ import org.eclipse.osee.framework.database.core.OseeConnection;
import org.eclipse.osee.orcs.core.ds.AttributeRow;
import org.eclipse.osee.orcs.core.ds.AttributeRowHandler;
import org.eclipse.osee.orcs.core.ds.DataProxy;
-import org.eclipse.osee.orcs.db.internal.SqlProvider;
import org.eclipse.osee.orcs.db.internal.loader.AttributeLoader.ProxyDataFactory;
import org.eclipse.osee.orcs.db.internal.sql.StaticSqlProvider;
import org.eclipse.osee.orcs.db.mock.H2Preferences;
@@ -33,6 +32,8 @@ import org.eclipse.osee.orcs.db.mock.MockLog;
import org.eclipse.osee.orcs.db.mock.OseeDatabase;
import org.eclipse.osee.orcs.db.mock.OsgiUtil;
import org.eclipse.osee.orcs.db.mocks.MockDataProxy;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Rule;
/**
@@ -43,12 +44,24 @@ public class AttributeLoaderTest {
@Rule
public OseeDatabase db = new OseeDatabase("osee.demo.h2");
+ private static StaticSqlProvider sqlProvider;
+
+ @BeforeClass
+ public static void setUp() {
+ sqlProvider = new StaticSqlProvider();
+ sqlProvider.setLogger(new MockLog());
+ sqlProvider.setPreferences(new H2Preferences());
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ sqlProvider = null;
+ }
+
@org.junit.Test
public void testAttributeLoadingData() throws OseeCoreException {
IOseeDatabaseService oseeDbService = OsgiUtil.getService(IOseeDatabaseService.class);
IdentityService identityService = OsgiUtil.getService(IdentityService.class);
- MockLog log = new MockLog();
- SqlProvider sqlProvider = new StaticSqlProvider(log, new H2Preferences());
final List<AttributeRow> actuals = new ArrayList<AttributeRow>();
@@ -121,6 +134,7 @@ public class AttributeLoaderTest {
return row;
}
+ @SuppressWarnings("unused")
private final class AttributeDataProxy extends MockDataProxy {
private final long typeUuid;
private final String value;
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java
index 3deaf24c1bd..a880b54c40c 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/loader/RelationLoaderTest.java
@@ -24,12 +24,13 @@ import org.eclipse.osee.framework.database.core.JoinUtility;
import org.eclipse.osee.framework.database.core.OseeConnection;
import org.eclipse.osee.orcs.core.ds.RelationRow;
import org.eclipse.osee.orcs.core.ds.RelationRowHandler;
-import org.eclipse.osee.orcs.db.internal.SqlProvider;
import org.eclipse.osee.orcs.db.internal.sql.StaticSqlProvider;
import org.eclipse.osee.orcs.db.mock.H2Preferences;
import org.eclipse.osee.orcs.db.mock.MockLog;
import org.eclipse.osee.orcs.db.mock.OseeDatabase;
import org.eclipse.osee.orcs.db.mock.OsgiUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Rule;
public class RelationLoaderTest {
@@ -37,13 +38,24 @@ public class RelationLoaderTest {
@Rule
public OseeDatabase db = new OseeDatabase("osee.demo.h2");
+ private static StaticSqlProvider sqlProvider;
+
+ @BeforeClass
+ public static void setUp() {
+ sqlProvider = new StaticSqlProvider();
+ sqlProvider.setLogger(new MockLog());
+ sqlProvider.setPreferences(new H2Preferences());
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ sqlProvider = null;
+ }
+
@org.junit.Test
public void testRelationLoadingData() throws OseeCoreException {
IOseeDatabaseService oseeDbService = OsgiUtil.getService(IOseeDatabaseService.class);
- MockLog log = new MockLog();
- SqlProvider sqlProvider = new StaticSqlProvider(log, new H2Preferences());
-
RelationLoader relationLoader = new RelationLoader(sqlProvider, oseeDbService);
ArtifactJoinQuery artJoinQuery = JoinUtility.createArtifactJoinQuery();
@@ -83,9 +95,6 @@ public class RelationLoaderTest {
public void testNoRelationsFound() throws OseeCoreException {
IOseeDatabaseService oseeDbService = OsgiUtil.getService(IOseeDatabaseService.class);
- MockLog log = new MockLog();
- SqlProvider sqlProvider = new StaticSqlProvider(log, new H2Preferences());
-
RelationLoader relationLoader = new RelationLoader(sqlProvider, oseeDbService);
ArtifactJoinQuery artJoinQuery = JoinUtility.createArtifactJoinQuery();
@@ -113,9 +122,6 @@ public class RelationLoaderTest {
@org.junit.Test
public void testHistoricalLoad() throws OseeCoreException {
IOseeDatabaseService oseeDbService = OsgiUtil.getService(IOseeDatabaseService.class);
- MockLog log = new MockLog();
- SqlProvider sqlProvider = new StaticSqlProvider(log, new H2Preferences());
-
RelationLoader relationLoader = new RelationLoader(sqlProvider, oseeDbService);
ArtifactJoinQuery artJoinQuery = JoinUtility.createArtifactJoinQuery();
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SearchTestSuite.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SearchTestSuite.java
new file mode 100644
index 00000000000..5ac6a317a9b
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SearchTestSuite.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@RunWith(Suite.class)
+@Suite.SuiteClasses({SqlBuilderTest.class, SqlWriterTest.class})
+public class SearchTestSuite {
+ // Test Suite
+}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SqlBuilderTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SqlBuilderTest.java
new file mode 100644
index 00000000000..16116c2bd3c
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SqlBuilderTest.java
@@ -0,0 +1,276 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.exception.OseeArgumentException;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+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.core.ds.criteria.CriteriaArtifactGuids;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactHrids;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactIds;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactType;
+import org.eclipse.osee.orcs.db.internal.search.SqlBuilder.QueryType;
+import org.eclipse.osee.orcs.db.internal.sql.StaticSqlProvider;
+import org.eclipse.osee.orcs.db.mock.MockLog;
+import org.eclipse.osee.orcs.db.mocks.MockSystemPreferences;
+import org.eclipse.osee.orcs.db.mocks.SqlUtility;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test Case for {@link SqlBuilder}
+ *
+ * @author Roberto E. Escobar
+ */
+public class SqlBuilderTest {
+
+ private static final Criteria GUIDS = new CriteriaArtifactGuids(Arrays.asList(GUID.create(), GUID.create()));
+ private static final Criteria IDS = new CriteriaArtifactIds(Arrays.asList(1, 2, 3, 4, 5));
+ private static final Criteria HRIDS = new CriteriaArtifactHrids(Arrays.asList("ABCDE", "FGHIJ"));
+ private static final Criteria TYPES = new CriteriaArtifactType(Arrays.asList(CoreArtifactTypes.CodeUnit));
+
+ // private static final Criteria TWO_TYPES = new CriteriaArtifactType(Arrays.asList(CoreArtifactTypes.CodeUnit,
+ // CoreArtifactTypes.Artifact));
+
+ private static StaticSqlProvider sqlProvider;
+
+ @BeforeClass
+ public static void setUp() {
+ sqlProvider = new StaticSqlProvider();
+ sqlProvider.setLogger(new MockLog());
+ sqlProvider.setPreferences(new MockSystemPreferences());
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ sqlProvider = null;
+ }
+
+ @Test(expected = OseeArgumentException.class)
+ public void testEmptyHandlers() throws OseeCoreException {
+ int branchId = 4;
+
+ List<SqlHandler> handlers = Collections.emptyList();
+ SqlBuilder builder = new SqlBuilder(sqlProvider, null);
+ builder.generateSql(null, branchId, handlers, QueryType.COUNT_ARTIFACTS);
+ }
+
+ @Test
+ public void testCountSql() throws OseeCoreException {
+ int branchId = 4;
+ CriteriaSet criteria = SqlUtility.createCriteria(CoreBranches.COMMON, GUIDS, IDS, HRIDS, TYPES);
+ List<SqlHandler> handlers = SqlUtility.createHandlers(criteria);
+
+ QueryOptions options = new QueryOptions();
+ SqlContext context = new SqlContext("mysession", options);
+ SqlBuilder builder = new SqlBuilder(sqlProvider, null);
+ builder.generateSql(context, branchId, handlers, QueryType.COUNT_ARTIFACTS);
+
+ String sql = context.getSql();
+ Assert.assertEquals(
+ "SELECT count(art1.art_id)\n" + //
+ " FROM \n" + //
+ "osee_join_id jid1, osee_artifact art1, osee_txs txs1, osee_join_char_id jch1, osee_artifact art2, osee_txs txs2, osee_join_char_id jch2, osee_artifact art3, osee_txs txs3\n" + //
+ " WHERE \n" + //
+ "art1.art_id = jid1.id AND jid1.query_id = ? AND art1.gamma_id = txs1.gamma_id AND txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
+ " AND \n" + //
+ "art2.guid = jch1.id AND jch1.query_id = ? AND art2.gamma_id = txs2.gamma_id AND txs2.tx_current = 1 AND txs2.branch_id = ?\n" + //
+ " AND \n" + //
+ "art3.human_readable_id = jch2.id AND jch2.query_id = ? AND art3.gamma_id = txs3.gamma_id AND txs3.tx_current = 1 AND txs3.branch_id = ?\n" + //
+ " AND \n" + //
+ "art1.art_type_id = ? AND art2.art_type_id = ? AND art3.art_type_id = ?\n" + //
+ " AND \n" + //
+ "txs1.gamma_id = txs2.gamma_id AND txs1.transaction_id = txs2.transaction_id AND txs1.branch_id = txs2.branch_id\n" + //
+ " AND \n" + //
+ "txs2.gamma_id = txs3.gamma_id AND txs2.transaction_id = txs3.transaction_id AND txs2.branch_id = txs3.branch_id", //
+ sql);
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(9, parameters.size());
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(3, joins.size());
+
+ Assert.assertEquals(joins.get(0).getQueryId(), parameters.get(0));
+ Assert.assertEquals(branchId, parameters.get(1));
+ Assert.assertEquals(joins.get(1).getQueryId(), parameters.get(2));
+ Assert.assertEquals(branchId, parameters.get(3));
+ Assert.assertEquals(joins.get(2).getQueryId(), parameters.get(4));
+ Assert.assertEquals(branchId, parameters.get(5));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(6));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(7));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(8));
+ }
+
+ @Test
+ public void testBuildSql() throws OseeCoreException {
+ int branchId = 4;
+ CriteriaSet criteria = SqlUtility.createCriteria(CoreBranches.COMMON, GUIDS, IDS, HRIDS, TYPES);
+ List<SqlHandler> handlers = SqlUtility.createHandlers(criteria);
+
+ QueryOptions options = new QueryOptions();
+ SqlContext context = new SqlContext("mysession", options);
+ SqlBuilder builder = new SqlBuilder(sqlProvider, null);
+ builder.generateSql(context, branchId, handlers, QueryType.SELECT_ARTIFACTS);
+
+ String sql = context.getSql();
+ Assert.assertEquals(
+ "SELECT art1.art_id, txs1.branch_id\n" + //
+ " FROM \n" + //
+ "osee_join_id jid1, osee_artifact art1, osee_txs txs1, osee_join_char_id jch1, osee_artifact art2, osee_txs txs2, osee_join_char_id jch2, osee_artifact art3, osee_txs txs3\n" + //
+ " WHERE \n" + //
+ "art1.art_id = jid1.id AND jid1.query_id = ? AND art1.gamma_id = txs1.gamma_id AND txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
+ " AND \n" + //
+ "art2.guid = jch1.id AND jch1.query_id = ? AND art2.gamma_id = txs2.gamma_id AND txs2.tx_current = 1 AND txs2.branch_id = ?\n" + //
+ " AND \n" + //
+ "art3.human_readable_id = jch2.id AND jch2.query_id = ? AND art3.gamma_id = txs3.gamma_id AND txs3.tx_current = 1 AND txs3.branch_id = ?\n" + //
+ " AND \n" + //
+ "art1.art_type_id = ? AND art2.art_type_id = ? AND art3.art_type_id = ?\n" + //
+ " AND \n" + //
+ "txs1.gamma_id = txs2.gamma_id AND txs1.transaction_id = txs2.transaction_id AND txs1.branch_id = txs2.branch_id\n" + //
+ " AND \n" + //
+ "txs2.gamma_id = txs3.gamma_id AND txs2.transaction_id = txs3.transaction_id AND txs2.branch_id = txs3.branch_id\n" + //
+ " ORDER BY art_id, branch_id",//
+ sql);
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(9, parameters.size());
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(3, joins.size());
+
+ Assert.assertEquals(joins.get(0).getQueryId(), parameters.get(0));
+ Assert.assertEquals(branchId, parameters.get(1));
+ Assert.assertEquals(joins.get(1).getQueryId(), parameters.get(2));
+ Assert.assertEquals(branchId, parameters.get(3));
+ Assert.assertEquals(joins.get(2).getQueryId(), parameters.get(4));
+ Assert.assertEquals(branchId, parameters.get(5));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(6));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(7));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(8));
+ }
+
+ @Test
+ public void testBuildSqlIncludeDeleted() throws OseeCoreException {
+ int branchId = 4;
+ CriteriaSet criteria = SqlUtility.createCriteria(CoreBranches.COMMON, GUIDS, IDS, HRIDS, TYPES);
+ List<SqlHandler> handlers = SqlUtility.createHandlers(criteria);
+
+ QueryOptions options = new QueryOptions();
+ options.setIncludeDeleted(true);
+
+ SqlContext context = new SqlContext("mysession", options);
+ SqlBuilder builder = new SqlBuilder(sqlProvider, null);
+ builder.generateSql(context, branchId, handlers, QueryType.SELECT_ARTIFACTS);
+
+ String sql = context.getSql();
+ Assert.assertEquals(
+ "SELECT art1.art_id, txs1.branch_id\n" + //
+ " FROM \n" + //
+ "osee_join_id jid1, osee_artifact art1, osee_txs txs1, osee_join_char_id jch1, osee_artifact art2, osee_txs txs2, osee_join_char_id jch2, osee_artifact art3, osee_txs txs3\n" + //
+ " WHERE \n" + //
+ "art1.art_id = jid1.id AND jid1.query_id = ? AND art1.gamma_id = txs1.gamma_id AND txs1.tx_current IN (1, 2) AND txs1.branch_id = ?\n" + //
+ " AND \n" + //
+ "art2.guid = jch1.id AND jch1.query_id = ? AND art2.gamma_id = txs2.gamma_id AND txs2.tx_current IN (1, 2) AND txs2.branch_id = ?\n" + //
+ " AND \n" + //
+ "art3.human_readable_id = jch2.id AND jch2.query_id = ? AND art3.gamma_id = txs3.gamma_id AND txs3.tx_current IN (1, 2) AND txs3.branch_id = ?\n" + //
+ " AND \n" + //
+ "art1.art_type_id = ? AND art2.art_type_id = ? AND art3.art_type_id = ?\n" + //
+ " AND \n" + //
+ "txs1.gamma_id = txs2.gamma_id AND txs1.transaction_id = txs2.transaction_id AND txs1.branch_id = txs2.branch_id\n" + //
+ " AND \n" + //
+ "txs2.gamma_id = txs3.gamma_id AND txs2.transaction_id = txs3.transaction_id AND txs2.branch_id = txs3.branch_id\n" + //
+ " ORDER BY art_id, branch_id",//
+ sql);
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(9, parameters.size());
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(3, joins.size());
+
+ Assert.assertEquals(joins.get(0).getQueryId(), parameters.get(0));
+ Assert.assertEquals(branchId, parameters.get(1));
+ Assert.assertEquals(joins.get(1).getQueryId(), parameters.get(2));
+ Assert.assertEquals(branchId, parameters.get(3));
+ Assert.assertEquals(joins.get(2).getQueryId(), parameters.get(4));
+ Assert.assertEquals(branchId, parameters.get(5));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(6));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(7));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(8));
+ }
+
+ @Test
+ public void testBuildSqlHistorical() throws OseeCoreException {
+ int branchId = 4;
+ int transactionId = 1000;
+
+ CriteriaSet criteria = SqlUtility.createCriteria(CoreBranches.COMMON, GUIDS, IDS, HRIDS, TYPES);
+ List<SqlHandler> handlers = SqlUtility.createHandlers(criteria);
+
+ QueryOptions options = new QueryOptions();
+ options.setFromTransaction(transactionId);
+
+ SqlContext context = new SqlContext("mysession", options);
+ SqlBuilder builder = new SqlBuilder(sqlProvider, null);
+ builder.generateSql(context, branchId, handlers, QueryType.SELECT_ARTIFACTS);
+
+ String sql = context.getSql();
+ Assert.assertEquals(
+ "SELECT max(transaction_id), art1.art_id, txs1.branch_id\n" + //
+ " FROM \n" + //
+ "osee_join_id jid1, osee_artifact art1, osee_txs txs1, osee_join_char_id jch1, osee_artifact art2, osee_txs txs2, osee_join_char_id jch2, osee_artifact art3, osee_txs txs3\n" + //
+ " WHERE \n" + //
+ "art1.art_id = jid1.id AND jid1.query_id = ? AND art1.gamma_id = txs1.gamma_id AND txs1.transaction_id <= ? AND txs1.branch_id = ?\n" + //
+ " AND \n" + //
+ "art2.guid = jch1.id AND jch1.query_id = ? AND art2.gamma_id = txs2.gamma_id AND txs2.transaction_id <= ? AND txs2.branch_id = ?\n" + //
+ " AND \n" + //
+ "art3.human_readable_id = jch2.id AND jch2.query_id = ? AND art3.gamma_id = txs3.gamma_id AND txs3.transaction_id <= ? AND txs3.branch_id = ?\n" + //
+ " AND \n" + //
+ "art1.art_type_id = ? AND art2.art_type_id = ? AND art3.art_type_id = ?\n" + //
+ " AND \n" + //
+ "txs1.gamma_id = txs2.gamma_id AND txs1.transaction_id = txs2.transaction_id AND txs1.branch_id = txs2.branch_id\n" + //
+ " AND \n" + //
+ "txs2.gamma_id = txs3.gamma_id AND txs2.transaction_id = txs3.transaction_id AND txs2.branch_id = txs3.branch_id\n" + //
+ " GROUP BY art_id, branch_id\n" + //
+ " ORDER BY art_id, branch_id",//
+ sql);
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(12, parameters.size());
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(3, joins.size());
+
+ Assert.assertEquals(joins.get(0).getQueryId(), parameters.get(0));
+ Assert.assertEquals(transactionId, parameters.get(1));
+ Assert.assertEquals(branchId, parameters.get(2));
+
+ Assert.assertEquals(joins.get(1).getQueryId(), parameters.get(3));
+ Assert.assertEquals(transactionId, parameters.get(4));
+ Assert.assertEquals(branchId, parameters.get(5));
+
+ Assert.assertEquals(joins.get(2).getQueryId(), parameters.get(6));
+ Assert.assertEquals(transactionId, parameters.get(7));
+ Assert.assertEquals(branchId, parameters.get(8));
+
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(9));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(10));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(11));
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SqlWriterTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SqlWriterTest.java
new file mode 100644
index 00000000000..1052bbb5a07
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/SqlWriterTest.java
@@ -0,0 +1,220 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import java.util.Arrays;
+import java.util.List;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
+import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+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.core.ds.criteria.CriteriaArtifactGuids;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactHrids;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactIds;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactType;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeTypeExists;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists;
+import org.eclipse.osee.orcs.db.mocks.SqlUtility;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test Case for {@link SqlWriter}
+ *
+ * @author Roberto E. Escobar
+ */
+public class SqlWriterTest {
+
+ private static final Criteria GUIDS = new CriteriaArtifactGuids(Arrays.asList(GUID.create(), GUID.create()));
+ private static final Criteria IDS = new CriteriaArtifactIds(Arrays.asList(1, 2, 3, 4, 5));
+ private static final Criteria HRIDS = new CriteriaArtifactHrids(Arrays.asList("ABCDE", "FGHIJ"));
+ private static final Criteria TYPES = new CriteriaArtifactType(Arrays.asList(CoreArtifactTypes.CodeUnit));
+
+ private static final Criteria ATTR_TYPE_EXITS = new CriteriaAttributeTypeExists(
+ Arrays.asList(CoreAttributeTypes.Name));
+ private static final Criteria REL_TYPE_EXISTS = new CriteriaRelationTypeExists(
+ CoreRelationTypes.Default_Hierarchical__Child);
+
+ // private static final Criteria TWO_TYPES = new CriteriaArtifactType(Arrays.asList(CoreArtifactTypes.CodeUnit,
+ // CoreArtifactTypes.Artifact));
+ // private static final Criteria ATTRIBUTE_EXITS = new CriteriaAttributeExists(CoreAttributeTypes.Name);
+ // private static final Criteria RELATION_EXISTS = new CriteriaRelationExists(
+ // CoreRelationTypes.Default_Hierarchical__Child);
+
+ @Test
+ public void testBuildWithBranch() throws OseeCoreException {
+ int branchId = 4;
+ IOseeDatabaseService service = null;
+ QueryOptions options = new QueryOptions();
+ SqlContext context = new SqlContext("mysession", options);
+ StringBuilder output = new StringBuilder();
+ SqlWriter writer = new SqlWriter(service, branchId, context, output);
+
+ List<SqlHandler> handlers = SqlUtility.createHandlers(createCriteria());
+
+ writer.writeTables(handlers);
+ Assert.assertEquals(//
+ "osee_join_id jid1, osee_artifact art1, osee_txs txs1, " + //
+ "osee_join_char_id jch1, osee_artifact art2, osee_txs txs2, " + //
+ "osee_join_char_id jch2, osee_artifact art3, osee_txs txs3, " + //
+ "osee_attribute att1, osee_txs txs4, " + //
+ "osee_relation_link rel1, osee_txs txs5", //
+ output.toString());
+
+ output.delete(0, output.length());
+
+ writer.writePredicates(handlers);
+
+ Assert.assertEquals(
+ //
+ "art1.art_id = jid1.id AND jid1.query_id = ? AND art1.gamma_id = txs1.gamma_id AND txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
+ " AND \n" + //
+ "art2.guid = jch1.id AND jch1.query_id = ? AND art2.gamma_id = txs2.gamma_id AND txs2.tx_current = 1 AND txs2.branch_id = ?\n" + //
+ " AND \n" + //
+ "art3.human_readable_id = jch2.id AND jch2.query_id = ? AND art3.gamma_id = txs3.gamma_id AND txs3.tx_current = 1 AND txs3.branch_id = ?\n" + //
+ " AND \n" + //
+ "art1.art_type_id = ? AND art2.art_type_id = ? AND art3.art_type_id = ?\n" + //
+ " AND \n" + //
+ "att1.attr_type_id = ?\n" + //
+ " AND \n" + //
+ "att1.art_id = art1.art_id AND att1.art_id = art2.art_id AND att1.art_id = art3.art_id\n" + //
+ " AND \n" + //
+ "att1.gamma_id = txs4.gamma_id AND txs4.tx_current = 1 AND txs4.branch_id = ?\n" + //
+ " AND \n" + //
+ "rel1.rel_link_type_id = ?\n" + //
+ " AND \n" + //
+ "(rel1.a_art_id = art1.art_id OR rel1.b_art_id = art1.art_id)\n" + //
+ " AND \n" + //
+ "(rel1.a_art_id = art2.art_id OR rel1.b_art_id = art2.art_id)\n" + //
+ " AND \n" + //
+ "(rel1.a_art_id = art3.art_id OR rel1.b_art_id = art3.art_id)\n" + //
+ " AND \n" + //
+ "rel1.gamma_id = txs5.gamma_id AND txs5.tx_current = 1 AND txs5.branch_id = ?\n" + //
+ " AND \n" + //
+ "txs1.gamma_id = txs2.gamma_id AND txs1.transaction_id = txs2.transaction_id AND txs1.branch_id = txs2.branch_id\n" + //
+ " AND \n" + //
+ "txs2.gamma_id = txs3.gamma_id AND txs2.transaction_id = txs3.transaction_id AND txs2.branch_id = txs3.branch_id\n" + //
+ " AND \n" + //
+ "txs3.gamma_id = txs4.gamma_id AND txs3.transaction_id = txs4.transaction_id AND txs3.branch_id = txs4.branch_id\n" + //
+ " AND \n" + //
+ "txs4.gamma_id = txs5.gamma_id AND txs4.transaction_id = txs5.transaction_id AND txs4.branch_id = txs5.branch_id" //
+ , output.toString());
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(13, parameters.size());
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(3, joins.size());
+
+ Assert.assertEquals(joins.get(0).getQueryId(), parameters.get(0));
+ Assert.assertEquals(branchId, parameters.get(1));
+
+ Assert.assertEquals(joins.get(1).getQueryId(), parameters.get(2));
+ Assert.assertEquals(branchId, parameters.get(3));
+
+ Assert.assertEquals(joins.get(2).getQueryId(), parameters.get(4));
+ Assert.assertEquals(branchId, parameters.get(5));
+
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(6));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(7));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(8));
+
+ Assert.assertEquals(CoreAttributeTypes.Name.getGuid().intValue(), parameters.get(9));
+ Assert.assertEquals(branchId, parameters.get(10));
+
+ Assert.assertEquals(CoreRelationTypes.Default_Hierarchical__Child.getGuid().intValue(), parameters.get(11));
+ Assert.assertEquals(branchId, parameters.get(12));
+ }
+
+ @Test
+ public void testBuildNoBranch() throws OseeCoreException {
+ IOseeDatabaseService service = null;
+ QueryOptions options = new QueryOptions();
+ SqlContext context = new SqlContext("mysession", options);
+ StringBuilder output = new StringBuilder();
+ SqlWriter writer = new SqlWriter(service, -1, context, output);
+
+ List<SqlHandler> handlers = SqlUtility.createHandlers(createCriteria());
+
+ writer.writeTables(handlers);
+ Assert.assertEquals(//
+ "osee_join_id jid1, osee_artifact art1, osee_txs txs1, " + //
+ "osee_join_char_id jch1, osee_artifact art2, osee_txs txs2, " + //
+ "osee_join_char_id jch2, osee_artifact art3, osee_txs txs3, " + //
+ "osee_attribute att1, osee_txs txs4, " + //
+ "osee_relation_link rel1, osee_txs txs5", //
+ output.toString());
+
+ output.delete(0, output.length());
+
+ writer.writePredicates(handlers);
+
+ Assert.assertEquals(
+ //
+ "art1.art_id = jid1.id AND jid1.query_id = ? AND art1.gamma_id = txs1.gamma_id AND txs1.tx_current = 1\n" + //
+ " AND \n" + //
+ "art2.guid = jch1.id AND jch1.query_id = ? AND art2.gamma_id = txs2.gamma_id AND txs2.tx_current = 1\n" + //
+ " AND \n" + //
+ "art3.human_readable_id = jch2.id AND jch2.query_id = ? AND art3.gamma_id = txs3.gamma_id AND txs3.tx_current = 1\n" + //
+ " AND \n" + //
+ "art1.art_type_id = ? AND art2.art_type_id = ? AND art3.art_type_id = ?\n" + //
+ " AND \n" + //
+ "att1.attr_type_id = ?\n" + //
+ " AND \n" + //
+ "att1.art_id = art1.art_id AND att1.art_id = art2.art_id AND att1.art_id = art3.art_id\n" + //
+ " AND \n" + //
+ "att1.gamma_id = txs4.gamma_id AND txs4.tx_current = 1\n" + //
+ " AND \n" + //
+ "rel1.rel_link_type_id = ?\n" + //
+ " AND \n" + //
+ "(rel1.a_art_id = art1.art_id OR rel1.b_art_id = art1.art_id)\n" + //
+ " AND \n" + //
+ "(rel1.a_art_id = art2.art_id OR rel1.b_art_id = art2.art_id)\n" + //
+ " AND \n" + //
+ "(rel1.a_art_id = art3.art_id OR rel1.b_art_id = art3.art_id)\n" + //
+ " AND \n" + //
+ "rel1.gamma_id = txs5.gamma_id AND txs5.tx_current = 1\n" + //
+ " AND \n" + //
+ "txs1.gamma_id = txs2.gamma_id AND txs1.transaction_id = txs2.transaction_id AND txs1.branch_id = txs2.branch_id\n" + //
+ " AND \n" + //
+ "txs2.gamma_id = txs3.gamma_id AND txs2.transaction_id = txs3.transaction_id AND txs2.branch_id = txs3.branch_id\n" + //
+ " AND \n" + //
+ "txs3.gamma_id = txs4.gamma_id AND txs3.transaction_id = txs4.transaction_id AND txs3.branch_id = txs4.branch_id\n" + //
+ " AND \n" + //
+ "txs4.gamma_id = txs5.gamma_id AND txs4.transaction_id = txs5.transaction_id AND txs4.branch_id = txs5.branch_id" //
+ , output.toString());
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(8, parameters.size());
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(3, joins.size());
+
+ Assert.assertEquals(joins.get(0).getQueryId(), parameters.get(0));
+ Assert.assertEquals(joins.get(1).getQueryId(), parameters.get(1));
+ Assert.assertEquals(joins.get(2).getQueryId(), parameters.get(2));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(3));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(4));
+ Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid().intValue(), parameters.get(5));
+
+ Assert.assertEquals(CoreAttributeTypes.Name.getGuid().intValue(), parameters.get(6));
+ Assert.assertEquals(CoreRelationTypes.Default_Hierarchical__Child.getGuid().intValue(), parameters.get(7));
+ }
+
+ private CriteriaSet createCriteria() {
+ return SqlUtility.createCriteria(CoreBranches.COMMON, GUIDS, TYPES, REL_TYPE_EXISTS, IDS, ATTR_TYPE_EXITS, HRIDS);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockIdentityService.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockIdentityService.java
new file mode 100644
index 00000000000..2dc7a87aefd
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockIdentityService.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * 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.db.mocks;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.data.Identity;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.services.IdentityService;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@SuppressWarnings("unused")
+public class MockIdentityService implements IdentityService {
+
+ @Override
+ public Integer getLocalId(Long universalId) throws OseeCoreException {
+ return null;
+ }
+
+ @Override
+ public Long getUniversalId(Integer localId) throws OseeCoreException {
+ return null;
+ }
+
+ @Override
+ public int getLocalId(Identity<Long> identity) throws OseeCoreException {
+ return 0;
+ }
+
+ @Override
+ public void store(Collection<Long> universalIds) throws OseeCoreException {
+ //
+ }
+
+ @Override
+ public void clear() {
+ //
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java
new file mode 100644
index 00000000000..98727d4db58
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/MockSystemPreferences.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * 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.db.mocks;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.core.SystemPreferences;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@SuppressWarnings("unused")
+public class MockSystemPreferences implements SystemPreferences {
+
+ @Override
+ public String getSystemUuid() throws OseeCoreException {
+ return null;
+ }
+
+ @Override
+ public String getValue(String key) throws OseeCoreException {
+ return null;
+ }
+
+ @Override
+ public String getCachedValue(String key) throws OseeCoreException {
+ return null;
+ }
+
+ @Override
+ public boolean isEnabled(String key) throws OseeCoreException {
+ return false;
+ }
+
+ @Override
+ public boolean isCacheEnabled(String key) throws OseeCoreException {
+ return false;
+ }
+
+ @Override
+ public void setEnabled(String key, boolean enabled) throws OseeCoreException {
+ //
+ }
+
+ @Override
+ public void setBoolean(String key, boolean value) throws OseeCoreException {
+ //
+ }
+
+ @Override
+ public boolean isBoolean(String key) throws OseeCoreException {
+ return false;
+ }
+
+ @Override
+ public void putValue(String key, String value) throws OseeCoreException {
+ //
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/SqlUtility.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/SqlUtility.java
new file mode 100644
index 00000000000..596d4ea1bcc
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/mocks/SqlUtility.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * 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.db.mocks;
+
+import java.util.List;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.data.Identity;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.services.IdentityService;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.CriteriaSet;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandlerFactory;
+import org.eclipse.osee.orcs.db.internal.search.handlers.SqlHandlerFactoryImpl;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class SqlUtility {
+
+ private SqlUtility() {
+ //Utility Class
+ }
+
+ public static CriteriaSet createCriteria(IOseeBranch branch, Criteria... criteria) {
+ CriteriaSet set = new CriteriaSet(branch);
+ for (Criteria crit : criteria) {
+ set.add(crit);
+ }
+ return set;
+ }
+
+ public static List<SqlHandler> createHandlers(CriteriaSet criteriaSet) throws OseeCoreException {
+ IdentityService service = new MockIdentityService() {
+
+ @Override
+ public int getLocalId(Identity<Long> identity) {
+ return identity.getGuid().intValue();
+ }
+
+ };
+ SqlHandlerFactory factory = new SqlHandlerFactoryImpl(service);
+ return factory.createHandlers(criteriaSet);
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF
index 42e87b3d88c..67257e2df57 100644
--- a/plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.orcs.db/META-INF/MANIFEST.MF
@@ -6,10 +6,10 @@ Bundle-Version: 0.9.9.qualifier
Bundle-Vendor: Eclipse Open System Engineering Environment
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Service-Component: OSGI-INF/*.xml
-Import-Package: org.eclipse.core.runtime,
- org.eclipse.osee.framework.core.data,
+Import-Package: org.eclipse.osee.framework.core.data,
org.eclipse.osee.framework.core.enums,
org.eclipse.osee.framework.core.exception,
+ org.eclipse.osee.framework.core.model,
org.eclipse.osee.framework.core.model.cache,
org.eclipse.osee.framework.core.model.type,
org.eclipse.osee.framework.core.services,
@@ -22,6 +22,9 @@ Import-Package: org.eclipse.core.runtime,
org.eclipse.osee.logger,
org.eclipse.osee.orcs.core,
org.eclipse.osee.orcs.core.ds,
+ org.eclipse.osee.orcs.core.ds.criteria,
org.eclipse.osee.orcs.data,
+ org.eclipse.osee.orcs.search,
org.osgi.framework;version="1.6.0"
Bundle-ActivationPolicy: lazy
+Require-Bundle: org.eclipse.core.runtime
diff --git a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/query.engine.impl.xml b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/query.engine.impl.xml
new file mode 100644
index 00000000000..4db1077f8cb
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/query.engine.impl.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.eclipse.osee.orcs.db.internal.search.QueryEngineImpl">
+ <implementation class="org.eclipse.osee.orcs.db.internal.search.QueryEngineImpl"/>
+ <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/>
+ <service>
+ <provide interface="org.eclipse.osee.orcs.core.ds.QueryEngine"/>
+ </service>
+ <reference bind="setIdentityService" cardinality="1..1" interface="org.eclipse.osee.framework.core.services.IdentityService" name="IdentityService" policy="static"/>
+ <reference bind="setDatabaseService" cardinality="1..1" interface="org.eclipse.osee.framework.database.IOseeDatabaseService" name="IOseeDatabaseService" policy="static"/>
+ <reference bind="setSqlProvider" cardinality="1..1" interface="org.eclipse.osee.orcs.db.internal.SqlProvider" name="SqlProvider" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/sql.provider.impl.xml b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/sql.provider.impl.xml
new file mode 100644
index 00000000000..8c95d755159
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/sql.provider.impl.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.osee.orcs.db.internal.sql.StaticSqlProvider">
+ <implementation class="org.eclipse.osee.orcs.db.internal.sql.StaticSqlProvider"/>
+ <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/>
+ <service>
+ <provide interface="org.eclipse.osee.orcs.db.internal.SqlProvider"/>
+ </service>
+ <reference bind="setPreferences" cardinality="1..1" interface="org.eclipse.osee.orcs.core.SystemPreferences" name="SystemPreferences" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/SqlProvider.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/SqlProvider.java
index 61830279ab7..430fc788a94 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/SqlProvider.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/SqlProvider.java
@@ -18,7 +18,8 @@ import org.eclipse.osee.orcs.db.internal.sql.OseeSql;
*/
public interface SqlProvider {
+ String getSql(OseeSql key) throws OseeCoreException;
+
String getSql(String key) throws OseeCoreException;
- String getSql(OseeSql key) throws OseeCoreException;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java
index 8b7b4073823..37e6eedfc3c 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/proxy/MappedDataProxy.java
@@ -93,6 +93,7 @@ public class MappedDataProxy extends AbstractDataProxy implements CharacterDataP
@Override
public void purge() throws OseeCoreException {
+ // TODO
// try {
// if (isRemoteUriValid()) {
// URL url = AttributeURL.getAcquireURL(remoteUri);
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryEngineImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryEngineImpl.java
index 6e848e8f411..eb79a567134 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryEngineImpl.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/QueryEngineImpl.java
@@ -10,19 +10,88 @@
*******************************************************************************/
package org.eclipse.osee.orcs.db.internal.search;
+import java.util.List;
+import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
+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.logger.Log;
import org.eclipse.osee.orcs.core.ds.CriteriaSet;
import org.eclipse.osee.orcs.core.ds.QueryEngine;
import org.eclipse.osee.orcs.core.ds.QueryOptions;
+import org.eclipse.osee.orcs.db.internal.SqlProvider;
+import org.eclipse.osee.orcs.db.internal.search.SqlBuilder.QueryType;
+import org.eclipse.osee.orcs.db.internal.search.handlers.SqlHandlerFactoryImpl;
/**
* @author Roberto E. Escobar
*/
public class QueryEngineImpl implements QueryEngine {
+ private SqlHandlerFactory handlerFactory;
+ private SqlBuilder builder;
+
+ private SqlProvider sqlProvider;
+ private IOseeDatabaseService dbService;
+ private IdentityService identityService;
+
+ private BranchCache branchCache;
+ private Log logger;
+
+ public void setLogger(Log logger) {
+ this.logger = logger;
+ }
+
+ public void setSqlProvider(SqlProvider sqlProvider) {
+ this.sqlProvider = sqlProvider;
+ }
+
+ public void setIdentityService(IdentityService identityService) {
+ this.identityService = identityService;
+ }
+
+ public void setDatabaseService(IOseeDatabaseService dbService) {
+ this.dbService = dbService;
+ }
+
+ public void start() {
+ handlerFactory = new SqlHandlerFactoryImpl(identityService);
+ builder = new SqlBuilder(sqlProvider, dbService);
+ }
+
+ public void stop() {
+ handlerFactory = null;
+ builder = null;
+ }
+
+ public SqlContext createContext(String sessionId, QueryOptions options) {
+ return new SqlContext(sessionId, options);
+ }
+
+ @Override
+ public Object createCount(String sessionId, CriteriaSet criteriaSet, QueryOptions options) throws OseeCoreException {
+ return createQuery(sessionId, criteriaSet, options, QueryType.COUNT_ARTIFACTS);
+ }
+
@Override
- public Object create(CriteriaSet criteriaSet, QueryOptions options) throws OseeCoreException {
- return null;
+ public Object create(String sessionId, CriteriaSet criteriaSet, QueryOptions options) throws OseeCoreException {
+ return createQuery(sessionId, criteriaSet, options, QueryType.SELECT_ARTIFACTS);
+ }
+
+ private SqlContext createQuery(String sessionId, CriteriaSet criteriaSet, QueryOptions options, QueryType queryType) throws OseeCoreException {
+ IOseeBranch branch = criteriaSet.getBranch();
+ int branchId = branchCache.getLocalId(branch);
+
+ List<SqlHandler> handlers = handlerFactory.createHandlers(criteriaSet);
+ SqlContext context = createContext(sessionId, options);
+ builder.generateSql(context, branchId, handlers, queryType);
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("SessionId:[%s] Query:[%s] Parameters:[%s]", sessionId, context.getSql(), context.getParameters());
+ }
+
+ return context;
}
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlAliasManager.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlAliasManager.java
new file mode 100644
index 00000000000..2cc0a527a63
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlAliasManager.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SqlAliasManager {
+
+ private final HashMap<TableEnum, Alias> aliases = new HashMap<TableEnum, Alias>();
+ private final Map<TableEnum, List<String>> usedAliases = new HashMap<TableEnum, List<String>>();
+
+ public SqlAliasManager() {
+ for (TableEnum table : TableEnum.values()) {
+ aliases.put(table, new Alias(table.getAliasPrefix()));
+ }
+ }
+
+ public List<String> getAliases(TableEnum table) {
+ List<String> values = usedAliases.get(table);
+ return values != null ? values : Collections.<String> emptyList();
+ }
+
+ public String getNextAlias(TableEnum table) throws OseeCoreException {
+ Alias alias = aliases.get(table);
+ Conditions.checkNotNull(alias, "alias", "Unable to find alias for [%s]", table);
+ String toReturn = alias.next();
+ putUsedAlias(table, toReturn);
+ return toReturn;
+ }
+
+ private void putUsedAlias(TableEnum table, String alias) {
+ List<String> values = usedAliases.get(table);
+ if (values == null) {
+ values = new LinkedList<String>();
+ usedAliases.put(table, values);
+ }
+ values.add(alias);
+ }
+
+ public void reset() {
+ for (Alias alias : aliases.values()) {
+ alias.reset();
+ }
+ usedAliases.clear();
+ }
+
+ private class Alias {
+ private final String aliasPrefix;
+ private int aliasSuffix;
+
+ public Alias(String aliasPrefix) {
+ this.aliasPrefix = aliasPrefix;
+ reset();
+ }
+
+ public String next() {
+ return getName() + aliasSuffix++;
+ }
+
+ public String getName() {
+ return aliasPrefix;
+ }
+
+ public void reset() {
+ aliasSuffix = 1;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlBuilder.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlBuilder.java
new file mode 100644
index 00000000000..35a0ece90c0
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlBuilder.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeWrappedException;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.orcs.db.internal.SqlProvider;
+import org.eclipse.osee.orcs.db.internal.sql.OseeSql;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SqlBuilder {
+
+ private final SqlProvider sqlProvider;
+ private final IOseeDatabaseService dbService;
+
+ public static enum QueryType {
+ COUNT_ARTIFACTS,
+ SELECT_ARTIFACTS;
+ }
+
+ public SqlBuilder(SqlProvider sqlProvider, IOseeDatabaseService dbService) {
+ super();
+ this.sqlProvider = sqlProvider;
+ this.dbService = dbService;
+ }
+
+ public void generateSql(SqlContext context, int branchId, List<SqlHandler> handlers, QueryType queryType) throws OseeCoreException {
+ Conditions.checkNotNullOrEmpty(handlers, "SqlHandlers");
+
+ StringBuilder output = new StringBuilder();
+ SqlWriter writer = new SqlWriter(dbService, branchId, context, output);
+ List<String> paramList = buildSql(writer, handlers, queryType);
+
+ String sql = output.toString();
+ String query = updateSelect(sql, paramList);
+ context.setSql(query);
+ }
+
+ private List<String> buildSql(SqlWriter writer, List<SqlHandler> handlers, QueryType queryType) throws OseeCoreException {
+ if (queryType == QueryType.COUNT_ARTIFACTS) {
+ writer.writeCountSelect();
+ } else {
+ writer.writeSelect();
+ }
+ writer.write("\n FROM \n");
+ writer.writeTables(handlers);
+ writer.write("\n WHERE \n");
+ writer.writePredicates(handlers);
+ writer.writeGroupAndOrder(queryType);
+
+ List<String> paramList = new ArrayList<String>();
+ paramList.add(sqlProvider.getSql(OseeSql.QUERY_BUILDER));
+ paramList.add("art1");
+ if (queryType != QueryType.COUNT_ARTIFACTS) {
+ paramList.add("txs1");
+ }
+ return paramList;
+ }
+
+ private String updateSelect(String sql, List<String> paramList) throws OseeWrappedException {
+ String query = null;
+ try {
+ query = String.format(sql, paramList.toArray());
+ } catch (Exception ex) {
+ String message = String.format("Error formatting SQL:[%s] Data:[%s]", sql, paramList);
+ throw new OseeWrappedException(message, ex);
+ }
+ return query;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlConstants.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlConstants.java
new file mode 100644
index 00000000000..3cf7a09546e
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlConstants.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class SqlConstants {
+
+ private SqlConstants() {
+ // Constants
+ }
+
+ public static enum TableEnum {
+ TXS_TABLE("osee_txs", "txs"),
+ ARTIFACT_TABLE("osee_artifact", "art"),
+ ATTRIBUTE_TABLE("osee_attribute", "att"),
+ RELATION_TABLE("osee_relation_link", "rel"),
+ CHAR_JOIN_TABLE("osee_join_char_id", "jch"),
+ ID_JOIN_TABLE("osee_join_id", "jid");
+
+ private String tableName;
+ private String aliasPrefix;
+
+ private TableEnum(String tableName, String aliasPrefix) {
+ this.tableName = tableName;
+ this.aliasPrefix = aliasPrefix;
+ }
+
+ public String getName() {
+ return tableName;
+ }
+
+ public String getAliasPrefix() {
+ return aliasPrefix;
+ }
+
+ }
+
+ public static enum CriteriaPriority {
+ ARTIFACT_ID,
+ ARTIFACT_GUID,
+ ARTIFACT_HRID,
+ ARTIFACT_TYPE,
+ ATTRIBUTE_TYPE_EXISTS,
+ ATTRIBUTE_TYPE,
+ ATTRIBUTE_TOKEN,
+ RELATION_TYPE_EXISTS;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlContext.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlContext.java
new file mode 100644
index 00000000000..34f0ed1f7f9
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlContext.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.orcs.core.ds.QueryOptions;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SqlContext {
+
+ private final List<Object> parameters = new ArrayList<Object>();
+ private final List<AbstractJoinQuery> joinTables = new ArrayList<AbstractJoinQuery>();
+ private String sql;
+
+ private final String sessionId;
+ private final QueryOptions options;
+
+ public SqlContext(String sessionId, QueryOptions options) {
+ this.sessionId = sessionId;
+ this.options = options;
+ }
+
+ public String getSessionId() {
+ return sessionId;
+ }
+
+ public void setSql(String sql) {
+ this.sql = sql;
+ }
+
+ public String getSql() {
+ return sql;
+ }
+
+ public List<Object> getParameters() {
+ return parameters;
+ }
+
+ public List<AbstractJoinQuery> getJoins() {
+ return joinTables;
+ }
+
+ public QueryOptions getOptions() {
+ return options;
+ }
+
+ public void clear() {
+ setSql(null);
+ parameters.clear();
+ joinTables.clear();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlHandler.java
new file mode 100644
index 00000000000..5449f32ada7
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlHandler.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import org.eclipse.osee.framework.core.data.Identity;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.services.IdentityService;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+
+public abstract class SqlHandler {
+
+ private IdentityService idService;
+
+ public void setIdentityService(IdentityService idService) {
+ this.idService = idService;
+ }
+
+ protected int toLocalId(Identity<Long> identity) throws OseeCoreException {
+ return idService.getLocalId(identity);
+ }
+
+ public abstract int getPriority();
+
+ public abstract void setData(Criteria criteria);
+
+ public abstract void addTables(SqlWriter writer) throws OseeCoreException;
+
+ public abstract void addPredicates(SqlWriter writer) throws OseeCoreException;
+
+ @SuppressWarnings("unused")
+ public void addOrderBy(SqlWriter sqlWriter) throws OseeCoreException {
+ // Do nothing
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlHandlerFactory.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlHandlerFactory.java
new file mode 100644
index 00000000000..6678ee85503
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlHandlerFactory.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import java.util.List;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.core.ds.CriteriaSet;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface SqlHandlerFactory {
+
+ List<SqlHandler> createHandlers(CriteriaSet criteriaSet) throws OseeCoreException;
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlWriter.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlWriter.java
new file mode 100644
index 00000000000..7ed7efaaa89
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/SqlWriter.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * 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.db.internal.search;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.List;
+import org.eclipse.osee.framework.core.enums.TxChange;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.framework.database.core.CharJoinQuery;
+import org.eclipse.osee.framework.database.core.IdJoinQuery;
+import org.eclipse.osee.framework.database.core.JoinUtility;
+import org.eclipse.osee.orcs.db.internal.search.SqlBuilder.QueryType;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SqlWriter {
+
+ private final SqlAliasManager aliasManager = new SqlAliasManager();
+ private final IOseeDatabaseService dbService;
+ private final int branchId;
+ private final SqlContext context;
+ private final Appendable output;
+
+ private boolean isFirstTable = true;
+
+ public SqlWriter(IOseeDatabaseService dbService, int branchId, SqlContext context, Appendable output) {
+ this.dbService = dbService;
+ this.branchId = branchId;
+ this.context = context;
+ this.output = output;
+ }
+
+ public void writeCountSelect() throws OseeCoreException {
+ if (context.getOptions().isHistorical()) {
+ throw new OseeCoreException("Count historical is not supported.");
+ } else {
+ write("SELECT%s count(%s.art_id)");
+ }
+ }
+
+ public void writeSelect() throws OseeCoreException {
+ if (context.getOptions().isHistorical()) {
+ write("SELECT%s max(transaction_id), %s.art_id, %s.branch_id");
+ } else {
+ write("SELECT%s %s.art_id, %s.branch_id");
+ }
+ }
+
+ public void writeTables(List<SqlHandler> handlers) throws OseeCoreException {
+ for (SqlHandler handler : handlers) {
+ handler.addTables(this);
+ }
+ }
+
+ public void writePredicates(List<SqlHandler> handlers) throws OseeCoreException {
+ int size = handlers.size();
+ for (int index = 0; index < size; index++) {
+ SqlHandler handler = handlers.get(index);
+ handler.addPredicates(this);
+ if (index + 1 < size) {
+ write("\n AND \n");
+ }
+ }
+ write("\n AND \n");
+ List<String> aliases = aliasManager.getAliases(TableEnum.TXS_TABLE);
+ writeTxsJoin(aliases);
+ }
+
+ private void writeTxsJoin(List<String> aliases) throws OseeCoreException {
+ int size = aliases.size();
+ if (size > 1) {
+ for (int index = 1; index < size; index++) {
+ String alias1 = aliases.get(index - 1);
+ String alias2 = aliases.get(index);
+ write(alias1);
+ write(".gamma_id = ");
+ write(alias2);
+ write(".gamma_id AND ");
+ write(alias1);
+ write(".transaction_id = ");
+ write(alias2);
+ write(".transaction_id AND ");
+ write(alias1);
+ write(".branch_id = ");
+ write(alias2);
+ write(".branch_id");
+ if (index + 1 < size) {
+ write("\n AND \n");
+ }
+ }
+ }
+ }
+
+ public List<String> getAliases(TableEnum table) {
+ return aliasManager.getAliases(table);
+ }
+
+ public String writeTable(TableEnum table) throws OseeCoreException {
+ String alias = null;
+ if (isFirstTable) {
+ isFirstTable = false;
+ } else {
+ write(", ");
+ }
+ write(table.getName());
+ write(" ");
+
+ alias = aliasManager.getNextAlias(table);
+ write(alias);
+ return alias;
+ }
+
+ public void writeGroupAndOrder(QueryType type) throws OseeCoreException {
+ if (context.getOptions().isHistorical()) {
+ write("\n GROUP BY art_id, branch_id");
+ }
+ if (type != QueryType.COUNT_ARTIFACTS) {
+ write("\n ORDER BY art_id, branch_id");
+ }
+ }
+
+ public void writeTxBranchFilter(String txsAlias) throws OseeCoreException {
+ writeTxFilter(txsAlias);
+ if (branchId > 0) {
+ write(" AND ");
+ write(txsAlias);
+ write(".branch_id = ?");
+ addParameter(branchId);
+ }
+ }
+
+ public void write(String data) throws OseeCoreException {
+ try {
+ output.append(data);
+ } catch (IOException ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ }
+
+ public void writeTxFilter(String txsAlias) throws OseeCoreException {
+ if (context.getOptions().isHistorical()) {
+ write(txsAlias);
+ write(".transaction_id <= ?");
+ addParameter(context.getOptions().getFromTransaction());
+ } else {
+ write(txsAlias);
+ write(".tx_current");
+ if (context.getOptions().areDeletedIncluded()) {
+ write(" IN (");
+ write(String.valueOf(TxChange.CURRENT.getValue()));
+ write(", ");
+ write(String.valueOf(TxChange.DELETED.getValue()));
+ write(")");
+ } else {
+ write(" = ");
+ write(String.valueOf(TxChange.CURRENT.getValue()));
+ }
+ }
+ }
+
+ public void addParameter(Object data) {
+ context.getParameters().add(data);
+ }
+
+ private void addJoin(AbstractJoinQuery join) {
+ context.getJoins().add(join);
+ }
+
+ public CharJoinQuery writeCharJoin(Collection<String> ids) {
+ CharJoinQuery joinQuery = JoinUtility.createCharJoinQuery(dbService, context.getSessionId());
+ for (String id : ids) {
+ joinQuery.add(id);
+ }
+ addJoin(joinQuery);
+ return joinQuery;
+ }
+
+ public IdJoinQuery writeIdJoin(Collection<Integer> ids) {
+ IdJoinQuery joinQuery = JoinUtility.createIdJoinQuery(dbService);
+ for (Integer id : ids) {
+ joinQuery.add(id);
+ }
+ addJoin(joinQuery);
+ return joinQuery;
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactGuidSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactGuidSqlHandler.java
new file mode 100644
index 00000000000..464907a1535
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactGuidSqlHandler.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactGuids;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.CriteriaPriority;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlWriter;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ArtifactGuidSqlHandler extends SqlHandler {
+
+ private CriteriaArtifactGuids criteria;
+
+ private String artAlias;
+ private String jguidAlias;
+ private String txsAlias;
+ private AbstractJoinQuery joinQuery;
+
+ @Override
+ public void setData(Criteria criteria) {
+ this.criteria = (CriteriaArtifactGuids) criteria;
+ }
+
+ @Override
+ public void addTables(SqlWriter writer) throws OseeCoreException {
+ if (criteria.getIds().size() > 1) {
+ jguidAlias = writer.writeTable(TableEnum.CHAR_JOIN_TABLE);
+ }
+ artAlias = writer.writeTable(TableEnum.ARTIFACT_TABLE);
+ txsAlias = writer.writeTable(TableEnum.TXS_TABLE);
+ }
+
+ @Override
+ public void addPredicates(SqlWriter writer) throws OseeCoreException {
+ Collection<String> ids = criteria.getIds();
+ if (ids.size() > 1) {
+ joinQuery = writer.writeCharJoin(ids);
+ writer.write(artAlias);
+ writer.write(".guid = ");
+ writer.write(jguidAlias);
+ writer.write(".id AND ");
+ writer.write(jguidAlias);
+ writer.write(".query_id = ?");
+ writer.addParameter(joinQuery.getQueryId());
+ } else {
+ writer.write(artAlias);
+ writer.write(".guid = ?");
+ writer.addParameter(ids.iterator().next());
+ }
+ writer.write(" AND ");
+ writer.write(artAlias);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias);
+ writer.write(".gamma_id AND ");
+ writer.writeTxBranchFilter(txsAlias);
+ }
+
+ @Override
+ public int getPriority() {
+ return CriteriaPriority.ARTIFACT_GUID.ordinal();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactHridsSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactHridsSqlHandler.java
new file mode 100644
index 00000000000..730711d615b
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactHridsSqlHandler.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactHrids;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.CriteriaPriority;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlWriter;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ArtifactHridsSqlHandler extends SqlHandler {
+
+ private CriteriaArtifactHrids criteria;
+
+ private String artAlias;
+ private String jHridAlias;
+ private String txsAlias;
+ private AbstractJoinQuery joinQuery;
+
+ @Override
+ public void setData(Criteria criteria) {
+ this.criteria = (CriteriaArtifactHrids) criteria;
+ }
+
+ @Override
+ public void addTables(SqlWriter writer) throws OseeCoreException {
+ if (criteria.getIds().size() > 1) {
+ jHridAlias = writer.writeTable(TableEnum.CHAR_JOIN_TABLE);
+ }
+ artAlias = writer.writeTable(TableEnum.ARTIFACT_TABLE);
+ txsAlias = writer.writeTable(TableEnum.TXS_TABLE);
+ }
+
+ @Override
+ public void addPredicates(SqlWriter writer) throws OseeCoreException {
+ Collection<String> ids = criteria.getIds();
+ if (ids.size() > 1) {
+ joinQuery = writer.writeCharJoin(ids);
+ writer.write(artAlias);
+ writer.write(".human_readable_id = ");
+ writer.write(jHridAlias);
+ writer.write(".id AND ");
+ writer.write(jHridAlias);
+ writer.write(".query_id = ?");
+ writer.addParameter(joinQuery.getQueryId());
+ } else {
+ writer.write(artAlias);
+ writer.write(".human_readable_id = ?");
+ writer.addParameter(ids.iterator().next());
+ }
+ writer.write(" AND ");
+ writer.write(artAlias);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias);
+ writer.write(".gamma_id AND ");
+ writer.writeTxBranchFilter(txsAlias);
+ }
+
+ @Override
+ public int getPriority() {
+ return CriteriaPriority.ARTIFACT_HRID.ordinal();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactIdsSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactIdsSqlHandler.java
new file mode 100644
index 00000000000..586067cfd3f
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactIdsSqlHandler.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactIds;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.CriteriaPriority;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlWriter;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ArtifactIdsSqlHandler extends SqlHandler {
+
+ private CriteriaArtifactIds criteria;
+
+ private String artAlias;
+ private String jIdAlias;
+ private String txsAlias;
+ private AbstractJoinQuery joinQuery;
+
+ @Override
+ public void setData(Criteria criteria) {
+ this.criteria = (CriteriaArtifactIds) criteria;
+ }
+
+ @Override
+ public void addTables(SqlWriter writer) throws OseeCoreException {
+ if (criteria.getIds().size() > 1) {
+ jIdAlias = writer.writeTable(TableEnum.ID_JOIN_TABLE);
+ }
+ artAlias = writer.writeTable(TableEnum.ARTIFACT_TABLE);
+ txsAlias = writer.writeTable(TableEnum.TXS_TABLE);
+ }
+
+ @Override
+ public void addPredicates(SqlWriter writer) throws OseeCoreException {
+ Collection<Integer> ids = criteria.getIds();
+ if (ids.size() > 1) {
+ joinQuery = writer.writeIdJoin(ids);
+ writer.write(artAlias);
+ writer.write(".art_id = ");
+ writer.write(jIdAlias);
+ writer.write(".id AND ");
+ writer.write(jIdAlias);
+ writer.write(".query_id = ?");
+ writer.addParameter(joinQuery.getQueryId());
+ } else {
+ writer.write(artAlias);
+ writer.write(".art_id = ?");
+ writer.addParameter(ids.iterator().next());
+ }
+ writer.write(" AND ");
+ writer.write(artAlias);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias);
+ writer.write(".gamma_id AND ");
+ writer.writeTxBranchFilter(txsAlias);
+ }
+
+ @Override
+ public int getPriority() {
+ return CriteriaPriority.ARTIFACT_ID.ordinal();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactTypeSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactTypeSqlHandler.java
new file mode 100644
index 00000000000..f2c6ac0e3f3
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/ArtifactTypeSqlHandler.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.osee.framework.core.data.IArtifactType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactType;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.CriteriaPriority;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlWriter;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ArtifactTypeSqlHandler extends SqlHandler {
+
+ private CriteriaArtifactType criteria;
+
+ private String jIdAlias;
+ private AbstractJoinQuery joinQuery;
+
+ @Override
+ public void setData(Criteria criteria) {
+ this.criteria = (CriteriaArtifactType) criteria;
+ }
+
+ @Override
+ public void addTables(SqlWriter writer) throws OseeCoreException {
+ if (criteria.getTypes().size() > 1) {
+ jIdAlias = writer.writeTable(TableEnum.ID_JOIN_TABLE);
+ }
+ }
+
+ @Override
+ public void addPredicates(SqlWriter writer) throws OseeCoreException {
+ Collection<? extends IArtifactType> types = criteria.getTypes();
+ if (types.size() > 1) {
+ Set<Integer> typeIds = new HashSet<Integer>();
+ for (IArtifactType type : types) {
+ typeIds.add(toLocalId(type));
+ }
+ joinQuery = writer.writeIdJoin(typeIds);
+ writer.write(jIdAlias);
+ writer.write(".query_id=?");
+ writer.addParameter(joinQuery.getQueryId());
+
+ List<String> aliases = writer.getAliases(TableEnum.ARTIFACT_TABLE);
+ if (!aliases.isEmpty()) {
+ writer.write(" AND ");
+ int aSize = aliases.size();
+ for (int index = 0; index < aSize; index++) {
+ String artAlias = aliases.get(index);
+ writer.write(artAlias);
+ writer.write(".art_type_id=");
+ writer.write(jIdAlias);
+ writer.write(".id");
+ if (index + 1 < aSize) {
+ writer.write(" AND ");
+ }
+ }
+ }
+ } else {
+ IArtifactType type = types.iterator().next();
+ int localId = toLocalId(type);
+
+ List<String> aliases = writer.getAliases(TableEnum.ARTIFACT_TABLE);
+ int aSize = aliases.size();
+ for (int index = 0; index < aSize; index++) {
+ String artAlias = aliases.get(index);
+ writer.write(artAlias);
+ writer.write(".art_type_id = ?");
+ writer.addParameter(localId);
+ if (index + 1 < aSize) {
+ writer.write(" AND ");
+ }
+ }
+ }
+ }
+
+ @Override
+ public int getPriority() {
+ return CriteriaPriority.ARTIFACT_TYPE.ordinal();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeOtherSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeOtherSqlHandler.java
new file mode 100644
index 00000000000..338b0dbff6d
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeOtherSqlHandler.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeOther;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.CriteriaPriority;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlWriter;
+import org.eclipse.osee.orcs.search.Operator;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AttributeOtherSqlHandler extends SqlHandler {
+
+ private CriteriaAttributeOther criteria;
+ private String attrAlias;
+ private String txsAlias;
+ private String joinAlias;
+ private String value;
+ private AbstractJoinQuery joinQuery;
+
+ @Override
+ public void setData(Criteria criteria) {
+ this.criteria = (CriteriaAttributeOther) criteria;
+ }
+
+ @Override
+ public void addTables(SqlWriter writer) throws OseeCoreException {
+ Collection<String> values = criteria.getValues();
+ if (values.size() == 1) {
+ this.value = values.iterator().next();
+ } else {
+ joinQuery = writer.writeCharJoin(values);
+ }
+ if (joinQuery != null && criteria.getOperator().isEquals()) {
+ joinAlias = writer.writeTable(TableEnum.CHAR_JOIN_TABLE);
+ }
+ attrAlias = writer.writeTable(TableEnum.ATTRIBUTE_TABLE);
+ txsAlias = writer.writeTable(TableEnum.TXS_TABLE);
+ }
+
+ @Override
+ public void addPredicates(SqlWriter writer) throws OseeCoreException {
+ IAttributeType attributeType = criteria.getAttributeType();
+ Operator operator = criteria.getOperator();
+
+ if (attributeType != null) {
+ writer.write(attrAlias);
+ writer.write(".attr_type_id = ? AND ");
+ writer.addParameter(toLocalId(attributeType));
+ }
+ if (value != null) {
+ writer.write(attrAlias);
+ writer.write(".value");
+ if (value.contains("%")) {
+ if (operator.isNotEquals()) {
+ writer.write(" NOT");
+ }
+ writer.write(" LIKE ");
+ } else {
+ writer.write(operator.toString());
+ }
+ writer.write("? AND ");
+ writer.addParameter(value);
+ }
+
+ if (joinQuery != null) {
+ if (operator.isEquals()) {
+ writer.write(attrAlias);
+ writer.write(".value = ");
+ writer.write(joinAlias);
+ writer.write(".id AND ");
+ writer.write(joinAlias);
+ writer.write(".query_id = ?");
+ } else {
+ writer.write("NOT EXISTS (SELECT 1 FROM ");
+ writer.write(TableEnum.CHAR_JOIN_TABLE.getName());
+ writer.write(" WHERE id = ");
+ writer.write(attrAlias);
+ writer.write(".value AND query_id = ?)");
+ }
+ writer.addParameter(joinQuery.getQueryId());
+ joinQuery.store();
+ }
+
+ writer.write(" AND ");
+ writer.write(attrAlias);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias);
+ writer.write(".gamma_id AND ");
+ writer.writeTxBranchFilter(txsAlias);
+ }
+
+ @Override
+ public int getPriority() {
+ return CriteriaPriority.ATTRIBUTE_TYPE.ordinal();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTokenSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTokenSqlHandler.java
new file mode 100644
index 00000000000..60d914225d3
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTokenSqlHandler.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeKeyword;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.CriteriaPriority;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlWriter;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@SuppressWarnings("unused")
+public class AttributeTokenSqlHandler extends SqlHandler {
+
+ private CriteriaAttributeKeyword criteria;
+
+ // TODO Attach Quick Search Here
+
+ @Override
+ public void setData(Criteria criteria) {
+ this.criteria = (CriteriaAttributeKeyword) criteria;
+ }
+
+ @Override
+ public void addTables(SqlWriter writer) throws OseeCoreException {
+ // TODO
+ }
+
+ @Override
+ public void addPredicates(SqlWriter writer) throws OseeCoreException {
+ // TODO
+ }
+
+ @Override
+ public int getPriority() {
+ return CriteriaPriority.ATTRIBUTE_TOKEN.ordinal();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTypeExistsSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTypeExistsSqlHandler.java
new file mode 100644
index 00000000000..c95d6a11888
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTypeExistsSqlHandler.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.core.AbstractJoinQuery;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeTypeExists;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.CriteriaPriority;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlWriter;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class AttributeTypeExistsSqlHandler extends SqlHandler {
+
+ private CriteriaAttributeTypeExists criteria;
+
+ private String attrAlias;
+ private String txsAlias;
+
+ private String jIdAlias;
+ private AbstractJoinQuery joinQuery;
+
+ @Override
+ public void setData(Criteria criteria) {
+ this.criteria = (CriteriaAttributeTypeExists) criteria;
+ }
+
+ @Override
+ public void addTables(SqlWriter writer) throws OseeCoreException {
+ if (criteria.getTypes().size() > 1) {
+ jIdAlias = writer.writeTable(TableEnum.ID_JOIN_TABLE);
+ }
+ attrAlias = writer.writeTable(TableEnum.ATTRIBUTE_TABLE);
+ txsAlias = writer.writeTable(TableEnum.TXS_TABLE);
+ }
+
+ @Override
+ public void addPredicates(SqlWriter writer) throws OseeCoreException {
+ Collection<? extends IAttributeType> types = criteria.getTypes();
+ if (types.size() > 1) {
+ Set<Integer> typeIds = new HashSet<Integer>();
+ for (IAttributeType type : types) {
+ typeIds.add(toLocalId(type));
+ }
+ joinQuery = writer.writeIdJoin(typeIds);
+
+ writer.write(attrAlias);
+ writer.write(".attr_type_id = ");
+ writer.write(jIdAlias);
+ writer.write(".id AND ");
+ writer.write(jIdAlias);
+ writer.write(".query_id = ?");
+ writer.addParameter(joinQuery.getQueryId());
+
+ } else {
+ IAttributeType type = types.iterator().next();
+ int localId = toLocalId(type);
+ writer.write(attrAlias);
+ writer.write(".attr_type_id = ?");
+ writer.addParameter(localId);
+ }
+
+ List<String> aliases = writer.getAliases(TableEnum.ARTIFACT_TABLE);
+ if (!aliases.isEmpty()) {
+ writer.write("\n AND \n");
+ int aSize = aliases.size();
+ for (int index = 0; index < aSize; index++) {
+ String artAlias = aliases.get(index);
+ writer.write(attrAlias);
+ writer.write(".art_id = ");
+ writer.write(artAlias);
+ writer.write(".art_id");
+
+ if (index + 1 < aSize) {
+ writer.write(" AND ");
+ }
+ }
+ }
+ writer.write("\n AND \n");
+ writer.write(attrAlias);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias);
+ writer.write(".gamma_id AND ");
+ writer.writeTxBranchFilter(txsAlias);
+ }
+
+ @Override
+ public int getPriority() {
+ return CriteriaPriority.ATTRIBUTE_TYPE_EXISTS.ordinal();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelationTypeExistsSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelationTypeExistsSqlHandler.java
new file mode 100644
index 00000000000..071981d763a
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelationTypeExistsSqlHandler.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.List;
+import org.eclipse.osee.framework.core.data.IRelationTypeSide;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.CriteriaPriority;
+import org.eclipse.osee.orcs.db.internal.search.SqlConstants.TableEnum;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlWriter;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class RelationTypeExistsSqlHandler extends SqlHandler {
+
+ private CriteriaRelationTypeExists criteria;
+
+ private String relAlias;
+ private String txsAlias;
+
+ @Override
+ public void setData(Criteria criteria) {
+ this.criteria = (CriteriaRelationTypeExists) criteria;
+ }
+
+ @Override
+ public void addTables(SqlWriter writer) throws OseeCoreException {
+ relAlias = writer.writeTable(TableEnum.RELATION_TABLE);
+ txsAlias = writer.writeTable(TableEnum.TXS_TABLE);
+ }
+
+ @Override
+ public void addPredicates(SqlWriter writer) throws OseeCoreException {
+ IRelationTypeSide typeSide = criteria.getType();
+ writer.write(relAlias);
+ writer.write(".rel_link_type_id = ?");
+ writer.addParameter(toLocalId(typeSide));
+
+ List<String> aliases = writer.getAliases(TableEnum.ARTIFACT_TABLE);
+ if (!aliases.isEmpty()) {
+ writer.write("\n AND \n");
+ int aSize = aliases.size();
+ for (int index = 0; index < aSize; index++) {
+ String artAlias = aliases.get(index);
+
+ writer.write("(");
+ writer.write(relAlias);
+ writer.write(".a_art_id = ");
+ writer.write(artAlias);
+ writer.write(".art_id");
+
+ writer.write(" OR ");
+
+ writer.write(relAlias);
+ writer.write(".b_art_id = ");
+ writer.write(artAlias);
+ writer.write(".art_id)");
+
+ if (index + 1 < aSize) {
+ writer.write("\n AND \n");
+ }
+ }
+ }
+ writer.write("\n AND \n");
+ writer.write(relAlias);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias);
+ writer.write(".gamma_id AND ");
+ writer.writeTxBranchFilter(txsAlias);
+ }
+
+ @Override
+ public int getPriority() {
+ return CriteriaPriority.RELATION_TYPE_EXISTS.ordinal();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerComparator.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerComparator.java
new file mode 100644
index 00000000000..ea75ff65be8
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerComparator.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.Comparator;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SqlHandlerComparator implements Comparator<SqlHandler> {
+
+ @Override
+ public int compare(SqlHandler o1, SqlHandler o2) {
+ return o1.getPriority() - o2.getPriority();
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryImpl.java
new file mode 100644
index 00000000000..3bcbf43fca4
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryImpl.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * 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.db.internal.search.handlers;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.core.services.IdentityService;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.CriteriaSet;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactGuids;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactHrids;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactIds;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaArtifactType;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeKeyword;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeOther;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeTypeExists;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.search.SqlHandlerFactory;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SqlHandlerFactoryImpl implements SqlHandlerFactory {
+
+ private static final SqlHandlerComparator comparator = new SqlHandlerComparator();
+ private final Map<Class<? extends Criteria>, Class<? extends SqlHandler>> handleMap =
+ new HashMap<Class<? extends Criteria>, Class<? extends SqlHandler>>();
+
+ private final IdentityService idService;
+
+ public SqlHandlerFactoryImpl(IdentityService idService) {
+ this.idService = idService;
+
+ handleMap.put(CriteriaArtifactGuids.class, ArtifactGuidSqlHandler.class);
+ handleMap.put(CriteriaArtifactHrids.class, ArtifactHridsSqlHandler.class);
+ handleMap.put(CriteriaArtifactIds.class, ArtifactIdsSqlHandler.class);
+ handleMap.put(CriteriaArtifactType.class, ArtifactTypeSqlHandler.class);
+ handleMap.put(CriteriaRelationTypeExists.class, RelationTypeExistsSqlHandler.class);
+ handleMap.put(CriteriaAttributeTypeExists.class, AttributeTypeExistsSqlHandler.class);
+ handleMap.put(CriteriaAttributeOther.class, AttributeOtherSqlHandler.class);
+ handleMap.put(CriteriaAttributeKeyword.class, AttributeTokenSqlHandler.class);
+ }
+
+ @Override
+ public List<SqlHandler> createHandlers(CriteriaSet criteriaSet) throws OseeCoreException {
+ List<SqlHandler> handlers = new ArrayList<SqlHandler>();
+ for (Criteria criteria : criteriaSet) {
+ Class<? extends Criteria> key = criteria.getClass();
+ Class<? extends SqlHandler> item = handleMap.get(key);
+ try {
+ SqlHandler handler = item.newInstance();
+ handler.setData(criteria);
+ handler.setIdentityService(idService);
+ handlers.add(handler);
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ }
+ Collections.sort(handlers, comparator);
+ return handlers;
+ }
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/StaticSqlProvider.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/StaticSqlProvider.java
index a51104e1d04..4c6b5fb5f2d 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/StaticSqlProvider.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/StaticSqlProvider.java
@@ -14,7 +14,6 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Conditions;
-import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.core.SystemPreferences;
import org.eclipse.osee.orcs.db.internal.SqlProvider;
@@ -25,23 +24,32 @@ import org.eclipse.osee.orcs.db.internal.SqlProvider;
public class StaticSqlProvider implements SqlProvider {
private final Map<String, String> sqlMap = new HashMap<String, String>();
- private final Log logger;
- private final SystemPreferences preferences;
+
+ private Log logger;
+ private SystemPreferences preferences;
private boolean wasPopulated;
- public StaticSqlProvider(Log logger, SystemPreferences preferences) {
+ public StaticSqlProvider() {
super();
+ this.wasPopulated = false;
+ }
+
+ public void setLogger(Log logger) {
this.logger = logger;
+ }
+
+ public void setPreferences(SystemPreferences preferences) {
this.preferences = preferences;
- this.wasPopulated = false;
}
@Override
public String getSql(String key) throws OseeCoreException {
Conditions.checkNotNull(key, "Sql Key");
ensurePopulated();
- String query = sqlMap.get(key);
- if (!Strings.isValid(query)) {
+ String query = null;
+ if (sqlMap.containsKey(key)) {
+ query = sqlMap.get(key);
+ } else {
logger.error("Unable to find - SqlKey [%s]", key);
}
return query;
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/ApplicationContext.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/ApplicationContext.java
index 45f43979dd7..332cd41fadb 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/ApplicationContext.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/ApplicationContext.java
@@ -11,5 +11,5 @@
package org.eclipse.osee.orcs;
public interface ApplicationContext {
-
+ //
}
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/Operator.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/Operator.java
index 14094b7a6a9..477c8fe3a8d 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/Operator.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/Operator.java
@@ -25,6 +25,18 @@ public enum Operator {
this.expression = expression;
}
+ public boolean isEquals() {
+ return EQUAL == this;
+ }
+
+ public boolean isNotEquals() {
+ return NOT_EQUAL == this;
+ }
+
+ public boolean isGreaterThanOrLessThan() {
+ return GREATER_THAN == this || LESS_THAN == this;
+ }
+
@Override
public String toString() {
return expression;
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryBuilder.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryBuilder.java
index 3e0b7c8e764..1a73fa9556f 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryBuilder.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryBuilder.java
@@ -11,6 +11,7 @@
package org.eclipse.osee.orcs.search;
import java.util.Collection;
+import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IRelationTypeSide;
import org.eclipse.osee.framework.core.data.TokenFactory;
@@ -66,9 +67,44 @@ public interface QueryBuilder {
QueryBuilder resetToDefaults();
/**
- * Search criteria that checks for the existence of an attribute type.
+ * Search criteria that finds a given artifact id
*/
- QueryBuilder andExists(IAttributeType attributeType) throws OseeCoreException;
+ QueryBuilder withLocalId(int... artifactId) throws OseeCoreException;
+
+ /**
+ * Search criteria that finds a given artifact ids
+ */
+ QueryBuilder withLocalIds(Collection<Integer> artifactIds) throws OseeCoreException;
+
+ /**
+ * Search criteria that finds a given artifact with guids or hrids
+ */
+ QueryBuilder withGuidsOrHrids(String... ids) throws OseeCoreException;
+
+ /**
+ * Search criteria that finds a given artifact with guids or hrids
+ */
+ QueryBuilder withGuidsOrHrids(Collection<String> ids) throws OseeCoreException;
+
+ /**
+ * Search criteria that finds a given artifact type
+ */
+ QueryBuilder and(IArtifactType... artifactType) throws OseeCoreException;
+
+ /**
+ * Search criteria that finds a given artifact types
+ */
+ QueryBuilder and(Collection<? extends IArtifactType> artifactType) throws OseeCoreException;
+
+ /**
+ * Search criteria that checks for the existence of an attribute type(s).
+ */
+ QueryBuilder andExists(IAttributeType... attributeType) throws OseeCoreException;
+
+ /**
+ * Search criteria that checks for the existence of an attribute types.
+ */
+ QueryBuilder andExists(Collection<? extends IAttributeType> attributeTypes) throws OseeCoreException;
/**
* Search criteria that follows the relation link ending on the given side
@@ -121,4 +157,5 @@ public interface QueryBuilder {
* Counts the number of items available
*/
int getCount() throws OseeCoreException;
+
}
diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java
index f1aa697bbfe..606b45cc747 100644
--- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java
+++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryFactory.java
@@ -11,10 +11,10 @@
package org.eclipse.osee.orcs.search;
import java.util.Collection;
-import java.util.List;
import org.eclipse.osee.framework.core.data.IArtifactToken;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.orcs.data.ReadableArtifact;
/**
@@ -23,25 +23,25 @@ import org.eclipse.osee.orcs.data.ReadableArtifact;
*/
public interface QueryFactory {
- QueryBuilder fromBranch(IOseeBranch branch);
+ QueryBuilder fromBranch(IOseeBranch branch) throws OseeCoreException;
- QueryBuilder fromArtifactType(IOseeBranch branch, IArtifactType artifactType);
+ QueryBuilder fromArtifactType(IOseeBranch branch, IArtifactType artifactType) throws OseeCoreException;
- QueryBuilder fromArtifactTypes(IOseeBranch branch, Collection<? extends IArtifactType> artifactTypes);
+ QueryBuilder fromArtifactTypes(IOseeBranch branch, Collection<? extends IArtifactType> artifactTypes) throws OseeCoreException;
- QueryBuilder fromArtifactTypeAllBranches(IArtifactType artifactType);
+ QueryBuilder fromArtifactTypeAllBranches(IArtifactType artifactType) throws OseeCoreException;
- QueryBuilder fromUuids(IOseeBranch branch, Collection<Integer> artifactIds);
+ QueryBuilder fromUuids(IOseeBranch branch, Collection<Integer> artifactIds) throws OseeCoreException;
- QueryBuilder fromGuidOrHrid(IOseeBranch branch, String guidOrHrid);
+ QueryBuilder fromGuidOrHrid(IOseeBranch branch, String guidOrHrid) throws OseeCoreException;
- QueryBuilder fromGuidOrHrids(IOseeBranch branch, List<String> guidOrHrids);
+ QueryBuilder fromGuidOrHrids(IOseeBranch branch, Collection<String> guidOrHrids) throws OseeCoreException;
- QueryBuilder fromArtifact(IOseeBranch branch, IArtifactToken artifactToken);
+ QueryBuilder fromArtifact(IOseeBranch branch, IArtifactToken artifactToken) throws OseeCoreException;
- QueryBuilder fromArtifacts(Collection<? extends ReadableArtifact> artifacts);
+ QueryBuilder fromArtifacts(Collection<? extends ReadableArtifact> artifacts) throws OseeCoreException;
- QueryBuilder fromName(IOseeBranch branch, String artifactName);
+ QueryBuilder fromName(IOseeBranch branch, String artifactName) throws OseeCoreException;
- QueryBuilder fromArtifactTypeAndName(IOseeBranch branch, IArtifactType artifactType, String artifactName);
+ QueryBuilder fromArtifactTypeAndName(IOseeBranch branch, IArtifactType artifactType, String artifactName) throws OseeCoreException;
}

Back to the top