Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-09-01 18:02:35 +0000
committerRoberto E. Escobar2014-10-01 21:03:36 +0000
commit536f8bb71bf04c13c6a210ca4225bc8ac645f36e (patch)
tree4cc0710753b3cb760e713ffc0d37888d286cbb25
parenta31161bf00726d43b39c32732663558b5b5120a5 (diff)
downloadorg.eclipse.osee-536f8bb71bf04c13c6a210ca4225bc8ac645f36e.tar.gz
org.eclipse.osee-536f8bb71bf04c13c6a210ca4225bc8ac645f36e.tar.xz
org.eclipse.osee-536f8bb71bf04c13c6a210ca4225bc8ac645f36e.zip
feature[ats_ATS103634]: Add follow relation type to QueryBuilder
-rw-r--r--plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsTest.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryData.java80
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaRelationTypeFollow.java45
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchQueryImpl.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/CriteriaFactory.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryBuilderImpl.java18
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryFactoryImpl.java5
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsImpl.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionQueryImpl.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImplTest.java179
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtilTest.java5
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/LoadSqlWriter.java42
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImpl.java7
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlWriter.java14
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryFilterFactoryImpl.java2
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlContextFactoryImpl.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlWriter.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/AttributeTokenSqlHandler.java20
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelatedToSqlHandler.java6
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelationTypeFollowSqlHandler.java122
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerPriority.java3
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AbstractSqlWriter.java59
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AliasEntry.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlAliasManager.java85
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandler.java9
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactory.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactoryImpl.java37
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlUtil.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java8
-rw-r--r--plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java100
-rw-r--r--plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/QueryBuilder.java7
32 files changed, 742 insertions, 147 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsTest.java b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsTest.java
index f64b0246a9d..4098afa5bd9 100644
--- a/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsTest.java
+++ b/plugins/org.eclipse.osee.orcs.core.test/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsTest.java
@@ -126,7 +126,7 @@ public class QueryStatisticsTest {
builder.append("\tDetails:\n\t\t");
builder.append(data.getOptions());
builder.append("\n\t\t");
- builder.append(data.getCriteriaSet());
+ builder.append(data.getCriteriaSets());
builder.append("\n");
return builder.toString();
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryData.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryData.java
index d42354fe9a6..e438efd4978 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryData.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/QueryData.java
@@ -10,17 +10,26 @@
*******************************************************************************/
package org.eclipse.osee.orcs.core.ds;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Roberto E. Escobar
+ */
public class QueryData implements HasOptions, Cloneable {
- private final CriteriaSet criteriaSet;
+
+ private final List<CriteriaSet> criterias;
private final Options options;
public QueryData(CriteriaSet criteriaSet, Options options) {
- this.criteriaSet = criteriaSet;
- this.options = options;
+ this(options, new ArrayList<CriteriaSet>());
+ criterias.add(criteriaSet);
}
- public CriteriaSet getCriteriaSet() {
- return criteriaSet;
+ public QueryData(Options options, List<CriteriaSet> criterias) {
+ this.criterias = criterias;
+ this.options = options;
}
@Override
@@ -28,28 +37,81 @@ public class QueryData implements HasOptions, Cloneable {
return options;
}
+ public List<Criteria> getAllCriteria() {
+ List<Criteria> allCriterias = new ArrayList<Criteria>();
+ for (CriteriaSet set : criterias) {
+ allCriterias.addAll(set.getCriterias());
+ }
+ return allCriterias;
+ }
+
+ public List<CriteriaSet> getCriteriaSets() {
+ return Collections.unmodifiableList(criterias);
+ }
+
+ public CriteriaSet getLastCriteriaSet() {
+ return !criterias.isEmpty() ? criterias.get(criterias.size() - 1) : null;
+ }
+
+ public CriteriaSet getFirstCriteriaSet() {
+ return !criterias.isEmpty() ? criterias.get(0) : null;
+ }
+
+ public int size() {
+ return criterias.size();
+ }
+
+ public CriteriaSet newCriteriaSet() {
+ CriteriaSet criteriaSet = new CriteriaSet();
+ criterias.add(criteriaSet);
+ return criteriaSet;
+ }
+
public void addCriteria(Criteria... criterias) {
+ CriteriaSet criteriaSet = getLastCriteriaSet();
for (Criteria criteria : criterias) {
criteriaSet.add(criteria);
}
}
public boolean hasCriteriaType(Class<? extends Criteria> type) {
- return criteriaSet.hasCriteriaType(type);
+ boolean result = false;
+ for (CriteriaSet criteriaSet : criterias) {
+ if (criteriaSet.hasCriteriaType(type)) {
+ result = true;
+ break;
+ }
+ }
+ return result;
}
public void reset() {
options.reset();
- criteriaSet.reset();
+
+ CriteriaSet criteriaSet = null;
+ if (!criterias.isEmpty()) {
+ criteriaSet = criterias.get(0);
+ criteriaSet.reset();
+ }
+ criterias.clear();
+
+ if (criteriaSet != null) {
+ criterias.add(criteriaSet);
+ }
}
@Override
public QueryData clone() {
- return new QueryData(criteriaSet.clone(), options.clone());
+ List<CriteriaSet> cloned = new ArrayList<CriteriaSet>(criterias.size());
+ for (CriteriaSet criteriaSet : criterias) {
+ cloned.add(criteriaSet.clone());
+ }
+ return new QueryData(options.clone(), cloned);
}
@Override
public String toString() {
- return "QueryData [criteriaSet=" + criteriaSet + ", options=" + options + "]";
+ return "QueryData [criteriaSet(s)=" + criterias + ", options=" + options + "]";
}
+
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaRelationTypeFollow.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaRelationTypeFollow.java
new file mode 100644
index 00000000000..c0c30dc1944
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaRelationTypeFollow.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.framework.jdk.core.util.Conditions;
+import org.eclipse.osee.orcs.core.ds.Criteria;
+import org.eclipse.osee.orcs.core.ds.Options;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class CriteriaRelationTypeFollow extends Criteria {
+
+ private final IRelationTypeSide typeSide;
+
+ public CriteriaRelationTypeFollow(IRelationTypeSide typeSide) {
+ super();
+ this.typeSide = typeSide;
+ }
+
+ public IRelationTypeSide getType() {
+ return typeSide;
+ }
+
+ @Override
+ public void checkValid(Options options) throws OseeCoreException {
+ Conditions.checkNotNull(typeSide, "Relation Type Side");
+ }
+
+ @Override
+ public String toString() {
+ return "CriteriaRelationTypeFollow [typeSide=" + typeSide + "]";
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchQueryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchQueryImpl.java
index 0b0d0cab0c2..99c686e9b99 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchQueryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/BranchQueryImpl.java
@@ -226,7 +226,7 @@ public class BranchQueryImpl implements BranchQuery {
private QueryData checkAndCloneQueryData() throws OseeCoreException {
QueryData queryData = getQueryData().clone();
- CriteriaSet criteriaSet = queryData.getCriteriaSet();
+ CriteriaSet criteriaSet = queryData.getLastCriteriaSet();
if (criteriaSet.getCriterias().isEmpty()) {
addAndCheck(queryData, criteriaFactory.createAllBranchesCriteria());
}
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 2818eef617f..c82dc2752f4 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
@@ -31,6 +31,7 @@ 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.CriteriaRelatedTo;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeFollow;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeNotExists;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeSideExists;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeSideNotExists;
@@ -142,4 +143,7 @@ public class CriteriaFactory {
return new CriteriaAllArtifacts();
}
+ public Criteria createFollowRelationType(IRelationTypeSide relationTypeSide) {
+ return new CriteriaRelationTypeFollow(relationTypeSide);
+ }
}
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 0480a719a06..5f2788fd949 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
@@ -31,7 +31,6 @@ import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.framework.jdk.core.util.GUID;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.ds.Criteria;
-import org.eclipse.osee.orcs.core.ds.CriteriaSet;
import org.eclipse.osee.orcs.core.ds.Options;
import org.eclipse.osee.orcs.core.ds.OptionsUtil;
import org.eclipse.osee.orcs.core.ds.QueryData;
@@ -318,6 +317,14 @@ public class QueryBuilderImpl implements QueryBuilder {
}
@Override
+ public QueryBuilder followRelation(IRelationTypeSide relationTypeSide) {
+ Criteria criteria = criteriaFactory.createFollowRelationType(relationTypeSide);
+ addAndCheck(getQueryData(), criteria);
+ queryData.newCriteriaSet();
+ return this;
+ }
+
+ @Override
public ResultSet<ArtifactReadable> getResults() throws OseeCoreException {
ResultSet<ArtifactReadable> result = null;
try {
@@ -378,14 +385,17 @@ public class QueryBuilderImpl implements QueryBuilder {
private QueryData checkAndCloneQueryData() throws OseeCoreException {
QueryData queryData = getQueryData().clone();
- CriteriaSet criteriaSet = queryData.getCriteriaSet();
- Collection<Criteria> criterias = criteriaSet.getCriterias();
- if (criterias.isEmpty() || (criterias.size() == 1 && criteriaSet.hasCriteriaType(CriteriaBranch.class))) {
+ Collection<Criteria> criterias = queryData.getAllCriteria();
+ if (criterias.isEmpty() || hasOneBranchCriteria(criterias)) {
addAndCheck(queryData, criteriaFactory.createAllArtifactsCriteria());
}
return queryData;
}
+ private boolean hasOneBranchCriteria(Collection<Criteria> criterias) {
+ return criterias.size() == 1 && criterias.iterator().next() instanceof CriteriaBranch;
+ }
+
@Override
public CancellableCallable<Integer> createCount() throws OseeCoreException {
return queryFactory.createCount(session, checkAndCloneQueryData());
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 5c5f840d3a7..94bdeef3bcd 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
@@ -82,8 +82,9 @@ public class QueryFactoryImpl implements QueryFactory {
@Override
public QueryBuilder fromBranch(long branchUuid) throws OseeCoreException {
- return fromBranch(TokenFactory.createBranch(branchUuid,
- String.format("N/A>%s:%s", getClass().getSimpleName(), "fromBranch")));
+ String name = String.format("uuid:[%s] name:[N/A] - %s.fromBranch(long)", branchUuid, getClass().getSimpleName());
+ IOseeBranch branch = TokenFactory.createBranch(branchUuid, name);
+ return fromBranch(branch);
}
@Override
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsImpl.java
index 6eb669211ec..b0d6accec23 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/QueryStatisticsImpl.java
@@ -84,7 +84,7 @@ public class QueryStatisticsImpl implements Cloneable, QueryStatistics {
builder.append("\tDetails:\n\t\t");
builder.append(data.getOptions());
builder.append("\n\t\t");
- builder.append(data.getCriteriaSet());
+ builder.append(data.getCriteriaSets());
builder.append("\n");
return builder.toString();
}
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionQueryImpl.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionQueryImpl.java
index bda9c6f6483..bc0af2851bc 100644
--- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionQueryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionQueryImpl.java
@@ -268,7 +268,7 @@ public class TransactionQueryImpl implements TransactionQuery {
private QueryData checkAndCloneQueryData() throws OseeCoreException {
QueryData queryData = getQueryData().clone();
- CriteriaSet criteriaSet = queryData.getCriteriaSet();
+ CriteriaSet criteriaSet = queryData.getLastCriteriaSet();
if (criteriaSet.getCriterias().isEmpty()) {
addAndCheck(queryData, criteriaFactory.createAllTransactionsCriteria());
}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImplTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImplTest.java
index e3b235f389f..917893d98dc 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImplTest.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImplTest.java
@@ -47,6 +47,7 @@ import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAttributeTypeExists;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranch;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelatedTo;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeFollow;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeNotExists;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeSideExists;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeSideNotExists;
@@ -102,6 +103,9 @@ public class ArtifactQuerySqlContextFactoryImplTest {
private static final Criteria ALL_ARTIFACTS = new CriteriaAllArtifacts();
+ private static final Criteria FOLLOW_RELATION_TYPE = new CriteriaRelationTypeFollow(
+ CoreRelationTypes.Default_Hierarchical__Child);
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -159,7 +163,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
@Test
public void testCount() throws Exception {
String expected =
- "SELECT/*+ ordered */ count(art1.art_id)\n" + //
+ "SELECT/*+ ordered */ count(art2.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\n" + //
" WHERE \n" + //
@@ -224,7 +228,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
@Test
public void testQuery() throws Exception {
String expected =
- "SELECT/*+ ordered */ art1.art_id, txs1.branch_id\n" + //
+ "SELECT/*+ ordered */ art2.art_id, txs2.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\n" + //
" WHERE \n" + //
@@ -233,7 +237,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
"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" + //
"art1.art_type_id = ? AND art2.art_type_id = ?\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " ORDER BY art2.art_id, txs2.branch_id";
queryData.addCriteria(GUIDS, IDS, TYPES);
@@ -258,7 +262,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
@Test
public void testQuerySqlIncludeDeleted() throws OseeCoreException {
String expected =
- "SELECT/*+ ordered */ art1.art_id, txs1.branch_id\n" + //
+ "SELECT/*+ ordered */ art2.art_id, txs2.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\n" + //
" WHERE \n" + //
@@ -267,7 +271,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
"art2.guid = jch1.id AND jch1.query_id = ? AND art2.gamma_id = txs2.gamma_id AND txs2.tx_current IN (1, 2, 3) AND txs2.branch_id = ?\n" + //
" AND \n" + //
"art1.art_type_id = ? AND art2.art_type_id = ?\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " ORDER BY art2.art_id, txs2.branch_id";
queryData.addCriteria(GUIDS, IDS, TYPES);
OptionsUtil.setIncludeDeletedArtifacts(queryData.getOptions(), true);
@@ -297,7 +301,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
" WHERE txs.gamma_id = art.gamma_id\n" + //
" AND art.guid = id.id AND id.query_id = ? AND txs.transaction_id <= ? AND txs.branch_id = ?\n" + //
" GROUP BY art.art_id)\n" + //
- "SELECT max(txs1.transaction_id) as transaction_id, art1.art_id, txs1.branch_id\n" + //
+ "SELECT max(txs2.transaction_id) as transaction_id, art2.art_id, txs2.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, artUuid1\n" + //
" WHERE \n" + //
@@ -312,8 +316,8 @@ public class ArtifactQuerySqlContextFactoryImplTest {
"txs2.mod_type <> 3 AND txs2.branch_id = ?\n" + //
" AND \n" + //
"art1.art_type_id = ? AND art2.art_type_id = ?\n" + //
- " GROUP BY art1.art_id, txs1.branch_id\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " GROUP BY art2.art_id, txs2.branch_id\n" + //
+ " ORDER BY art2.art_id, txs2.branch_id";
queryData.addCriteria(GUIDS, IDS, TYPES);
OptionsUtil.setFromTransaction(queryData.getOptions(), EXPECTED_TX_ID);
@@ -359,7 +363,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
" WHERE txs.gamma_id = attr.gamma_id\n" + //
" AND att.attr_type_id = ? AND txs.transaction_id <= ? AND txs.branch_id = ?\n" + //
" GROUP BY attr.art_id)\n" + //
- "SELECT max(txs1.transaction_id) as transaction_id, art1.art_id, txs1.branch_id\n" + //
+ "SELECT max(txs4.transaction_id) as transaction_id, art2.art_id, txs4.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_attribute att1, osee_txs txs3, osee_txs txs4, osee_relation_link rel1, artUuid1, attrExt1\n" + //
" WHERE \n" + //
@@ -396,8 +400,8 @@ public class ArtifactQuerySqlContextFactoryImplTest {
"txs4.transaction_id <= ?\n" + //
" AND \n" + //
"txs4.mod_type <> 3 AND txs4.branch_id = ?\n" + //
- " GROUP BY art1.art_id, txs1.branch_id\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " GROUP BY art2.art_id, txs4.branch_id\n" + //
+ " ORDER BY art2.art_id, txs4.branch_id";
queryData.addCriteria(GUIDS, IDS, TYPES, ATTR_TYPE_EXITS, REL_TYPE_EXISTS);
OptionsUtil.setFromTransaction(queryData.getOptions(), EXPECTED_TX_ID);
@@ -492,7 +496,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
@Test
public void testQueryAttribute() throws OseeCoreException {
- String expected = "SELECT/*+ ordered */ art1.art_id, txs1.branch_id\n" + //
+ String expected = "SELECT/*+ ordered */ art1.art_id, txs2.branch_id\n" + //
" FROM \n" + //
"osee_attribute att1, osee_txs txs1, osee_artifact art1, osee_txs txs2\n" + //
" WHERE \n" + //
@@ -501,7 +505,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
"art1.art_id = att1.art_id AND att1.gamma_id = txs1.gamma_id AND txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
" AND \n" + //
"art1.gamma_id = txs2.gamma_id AND txs2.tx_current = 1 AND txs2.branch_id = ?\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " ORDER BY art1.art_id, txs2.branch_id";
queryData.addCriteria(ATTRIBUTE);
@@ -537,9 +541,9 @@ public class ArtifactQuerySqlContextFactoryImplTest {
" WHERE \n" + //
"art1.art_id = att1.art_id\n" + //
" AND \n" + //
- "txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
+ "txs1.gamma_id = art1.gamma_id\n" + //
" AND \n" + //
- "txs1.gamma_id = art1.gamma_id\n" + //
+ "txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
" ORDER BY art1.art_id, txs1.branch_id";
queryData.addCriteria(ATTRIBUTE_KEYWORD);
@@ -572,7 +576,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
" att2 AS (SELECT art_id FROM osee_attribute att, osee_txs txs, osee_join_id jid1, " + //
"gamma1 WHERE att.gamma_id = gamma1.gamma_id AND att.gamma_id = txs.gamma_id AND " + //
"txs.tx_current = 1 AND txs.branch_id = ? AND att.attr_type_id = jid1.id AND jid1.query_id = ?)\n" + //
- "SELECT art1.art_id, txs1.branch_id\n" + //
+ "SELECT art1.art_id, txs2.branch_id\n" + //
" FROM \n" + //
"osee_attribute att1, osee_txs txs1, osee_artifact art1, osee_txs txs2, att2\n" + //
" WHERE \n" + //
@@ -584,12 +588,8 @@ public class ArtifactQuerySqlContextFactoryImplTest {
" AND \n" + //
"art1.art_id = att2.art_id\n" + //
" AND \n" + //
- "txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
- " AND \n" + //
- "txs1.gamma_id = art1.gamma_id\n" + //
- " AND \n" + //
"art1.art_type_id = ?\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " ORDER BY art1.art_id, txs2.branch_id";
queryData.addCriteria(ATTRIBUTE, ATTRIBUTE_KEYWORD, TYPES);
@@ -597,7 +597,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
Assert.assertEquals(expected, context.getSql());
List<Object> parameters = context.getParameters();
- Assert.assertEquals(11, parameters.size());
+ Assert.assertEquals(10, parameters.size());
List<AbstractJoinQuery> joins = context.getJoins();
Assert.assertEquals(1, joins.size());
@@ -613,7 +613,6 @@ public class ArtifactQuerySqlContextFactoryImplTest {
Assert.assertEquals(EXPECTED_BRANCH_ID, iterator.next());
Assert.assertEquals(EXPECTED_BRANCH_ID, iterator.next());
- Assert.assertEquals(EXPECTED_BRANCH_ID, iterator.next());
Assert.assertEquals(CoreArtifactTypes.CodeUnit.getGuid(), iterator.next());
}
@@ -621,7 +620,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
public void testQueryExistsNoBranch() throws OseeCoreException {
String expected =
- "SELECT/*+ ordered */ art1.art_id, txs1.branch_id\n" + //
+ "SELECT/*+ ordered */ art2.art_id, txs4.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, " + //
@@ -649,7 +648,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
"rel1.gamma_id = txs4.gamma_id\n" + //
" AND \n" + //
"txs4.tx_current = 1 AND txs4.branch_id = ?\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " ORDER BY art2.art_id, txs4.branch_id";
queryData.addCriteria(GUIDS, TYPES, REL_TYPE_EXISTS, IDS, ATTR_TYPE_EXITS);
@@ -676,7 +675,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
@Test
public void testQueryExistsWithBranch() throws OseeCoreException {
String expected =
- "SELECT/*+ ordered */ art1.art_id, txs1.branch_id\n" + //
+ "SELECT/*+ ordered */ art2.art_id, txs4.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, " + //
@@ -704,7 +703,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
"rel1.gamma_id = txs4.gamma_id\n" + //
" AND \n" + //
"txs4.tx_current = 1 AND txs4.branch_id = ?\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " ORDER BY art2.art_id, txs4.branch_id";
queryData.addCriteria(GUIDS, TYPES, REL_TYPE_EXISTS, IDS, ATTR_TYPE_EXITS);
@@ -735,7 +734,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
@Test
public void testRelatedTo() throws OseeCoreException {
String expected =
- "SELECT/*+ ordered */ art1.art_id, txs1.branch_id\n" + //
+ "SELECT/*+ ordered */ art2.art_id, txs3.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_id jid2, osee_relation_link rel1, osee_txs txs3\n" + //
" WHERE \n" + //
@@ -754,7 +753,7 @@ public class ArtifactQuerySqlContextFactoryImplTest {
"rel1.gamma_id = txs3.gamma_id\n" + //
" AND \n" + //
"txs3.tx_current = 1 AND txs3.branch_id = ?\n" + //
- " ORDER BY art1.art_id, txs1.branch_id";
+ " ORDER BY art2.art_id, txs3.branch_id";
queryData.addCriteria(GUIDS, TYPES, IDS, RELATED_TO);
@@ -1005,4 +1004,126 @@ public class ArtifactQuerySqlContextFactoryImplTest {
List<AbstractJoinQuery> joins = context.getJoins();
Assert.assertEquals(0, joins.size());
}
+
+ @Test
+ public void testRelationTypeFollow() throws OseeCoreException {
+ String expected =
+ "SELECT/*+ ordered */ art2.art_id, txs3.branch_id\n" + //
+ " FROM \n" + //
+ "osee_artifact art1, osee_txs txs1, osee_relation_link rel1, osee_txs txs2, osee_artifact art2, osee_txs txs3\n" + //
+ " WHERE \n" + //
+ "art1.gamma_id = txs1.gamma_id AND txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
+ " AND \n" + //
+ "rel1.rel_link_type_id = ? AND rel1.a_art_id = art1.art_id AND rel1.gamma_id = txs2.gamma_id AND txs2.tx_current = 1 AND txs2.branch_id = ?\n" + //
+ " AND \n" + //
+ "rel1.b_art_id = art2.art_id AND art2.gamma_id = txs3.gamma_id AND txs3.tx_current = 1 AND txs3.branch_id = ?\n" + //
+ " ORDER BY art2.art_id, txs3.branch_id";
+
+ queryData.addCriteria(FOLLOW_RELATION_TYPE);
+
+ QuerySqlContext context = queryEngine.createQueryContext(session, queryData);
+ Assert.assertEquals(expected, context.getSql());
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(4, parameters.size());
+
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(0, joins.size());
+
+ Iterator<Object> iterator = parameters.iterator();
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ assertEquals(CoreRelationTypes.Default_Hierarchical__Child.getGuid(), iterator.next());
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ }
+
+ @Test
+ public void testRelationTypeFollowCombined() throws OseeCoreException {
+ String expected =
+ "WITH gamma1 AS ((SELECT gamma_id FROM osee_search_tags WHERE coded_tag_id = ?\n" + //
+ " INTERSECT \n" + //
+ "SELECT gamma_id FROM osee_search_tags WHERE coded_tag_id = ?\n" + //
+ " INTERSECT \n" + //
+ "SELECT gamma_id FROM osee_search_tags WHERE coded_tag_id = ?) ), \n" + //
+ " att1 AS (SELECT art_id FROM osee_attribute att, osee_txs txs, osee_join_id jid1, gamma1 WHERE att.gamma_id = gamma1.gamma_id AND att.gamma_id = txs.gamma_id AND txs.tx_current = 1 AND txs.branch_id = ? AND att.attr_type_id = jid1.id AND jid1.query_id = ?)\n" + //
+ "SELECT art2.art_id, txs3.branch_id\n" + //
+ " FROM \n" + //
+ "osee_join_char_id jch1, osee_artifact art1, osee_txs txs1, osee_relation_link rel1, osee_txs txs2, osee_artifact art2, osee_txs txs3, att1\n" + //
+ " WHERE \n" + //
+ "art1.guid = jch1.id AND jch1.query_id = ? AND art1.gamma_id = txs1.gamma_id AND txs1.tx_current = 1 AND txs1.branch_id = ?\n" + //
+ " AND \n" + //
+ "art1.art_id = att1.art_id\n" + //
+ " AND \n" + //
+ "rel1.rel_link_type_id = ? AND rel1.a_art_id = art1.art_id AND rel1.gamma_id = txs2.gamma_id AND txs2.tx_current = 1 AND txs2.branch_id = ?\n" + //
+ " AND \n" + //
+ "rel1.b_art_id = art2.art_id AND art2.gamma_id = txs3.gamma_id AND txs3.tx_current = 1 AND txs3.branch_id = ?\n" + //
+ " ORDER BY art2.art_id, txs3.branch_id";
+
+ queryData.addCriteria(ATTRIBUTE_KEYWORD, FOLLOW_RELATION_TYPE, GUIDS);
+
+ QuerySqlContext context = queryEngine.createQueryContext(session, queryData);
+ Assert.assertEquals(expected, context.getSql());
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(10, parameters.size());
+
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(2, joins.size());
+
+ Iterator<Object> iterator = parameters.iterator();
+
+ assertEquals(CODED_WORD_1, iterator.next()); // Coded Hello
+ assertEquals(CODED_WORD_2, iterator.next()); // Coded two
+ assertEquals(CODED_WORD_3, iterator.next()); // Coded three
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ assertEquals(joins.get(0).getQueryId(), iterator.next());
+ assertEquals(joins.get(1).getQueryId(), iterator.next());
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ assertEquals(CoreRelationTypes.Default_Hierarchical__Child.getGuid(), iterator.next());
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ }
+
+ @Test
+ public void testRelationTypeFollowHistorical() throws OseeCoreException {
+ String expected =
+ "SELECT/*+ ordered */ max(txs3.transaction_id) as transaction_id, art2.art_id, txs3.branch_id\n" + //
+ " FROM \n" + //
+ "osee_artifact art1, osee_txs txs1, osee_relation_link rel1, osee_txs txs2, osee_artifact art2, osee_txs txs3\n" + //
+ " WHERE \n" + //
+ "art1.gamma_id = txs1.gamma_id AND txs1.transaction_id <= ?\n" + //
+ " AND \n" + //
+ "txs1.mod_type <> 3 AND txs1.branch_id = ?\n" + //
+ " AND \n" + //
+ "rel1.rel_link_type_id = ? AND rel1.a_art_id = art1.art_id AND rel1.gamma_id = txs2.gamma_id AND txs2.transaction_id <= ?\n" + //
+ " AND \n" + //
+ "txs2.mod_type <> 3 AND txs2.branch_id = ?\n" + //
+ " AND \n" + //
+ "rel1.b_art_id = art2.art_id AND art2.gamma_id = txs3.gamma_id AND txs3.transaction_id <= ?\n" + //
+ " AND \n" + //
+ "txs3.mod_type <> 3 AND txs3.branch_id = ?\n" + //
+ " GROUP BY art2.art_id, txs3.branch_id\n" + //
+ " ORDER BY art2.art_id, txs3.branch_id";
+
+ OptionsUtil.setFromTransaction(queryData.getOptions(), EXPECTED_TX_ID);
+ queryData.addCriteria(FOLLOW_RELATION_TYPE);
+
+ QuerySqlContext context = queryEngine.createQueryContext(session, queryData);
+ Assert.assertEquals(expected, context.getSql());
+
+ List<Object> parameters = context.getParameters();
+ Assert.assertEquals(7, parameters.size());
+
+ List<AbstractJoinQuery> joins = context.getJoins();
+ Assert.assertEquals(0, joins.size());
+
+ Iterator<Object> iterator = parameters.iterator();
+ assertEquals(EXPECTED_TX_ID, iterator.next());
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ assertEquals(CoreRelationTypes.Default_Hierarchical__Child.getGuid(), iterator.next());
+ assertEquals(EXPECTED_TX_ID, iterator.next());
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ assertEquals(EXPECTED_TX_ID, iterator.next());
+ assertEquals(EXPECTED_BRANCH_ID, iterator.next());
+ }
}
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtilTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtilTest.java
index 5af73b0c3c5..a823971c847 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtilTest.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtilTest.java
@@ -29,6 +29,7 @@ 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.CriteriaRelatedTo;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeFollow;
import org.eclipse.osee.orcs.db.internal.IdentityLocator;
import org.eclipse.osee.orcs.db.internal.search.tagger.HasTagProcessor;
import org.eclipse.osee.orcs.db.internal.search.tagger.TagProcessor;
@@ -66,6 +67,7 @@ public class SqlHandlerFactoryUtilTest {
List<Criteria> criteria = new ArrayList<Criteria>();
criteria.add(new CriteriaArtifactGuids(null));
criteria.add(new CriteriaArtifactIds(null));
+ criteria.add(new CriteriaRelationTypeFollow(null));
criteria.add(new CriteriaArtifactType(null, null, true));
criteria.add(new CriteriaRelationTypeExists(null));
criteria.add(new CriteriaAttributeTypeExists(null));
@@ -79,7 +81,7 @@ public class SqlHandlerFactoryUtilTest {
CriteriaSet criteriaSet = createCriteria(criteria);
List<SqlHandler<?>> handlers = factory.createHandlers(criteriaSet);
- Assert.assertEquals(9, handlers.size());
+ Assert.assertEquals(10, handlers.size());
Iterator<SqlHandler<?>> iterator = handlers.iterator();
assertHandler(iterator.next(), ArtifactIdsSqlHandler.class, SqlHandlerPriority.ARTIFACT_ID);
@@ -93,6 +95,7 @@ public class SqlHandlerFactoryUtilTest {
assertHandler(iterator.next(), RelationTypeExistsSqlHandler.class, SqlHandlerPriority.RELATION_TYPE_EXISTS);
assertHandler(iterator.next(), RelatedToSqlHandler.class, SqlHandlerPriority.RELATED_TO_ART_IDS);
assertHandler(iterator.next(), AllArtifactsSqlHandler.class, SqlHandlerPriority.ALL_ARTIFACTS);
+ assertHandler(iterator.next(), RelationTypeFollowSqlHandler.class, SqlHandlerPriority.FOLLOW_RELATION_TYPES);
}
private void assertHandler(SqlHandler<?> actual, Class<?> type, SqlHandlerPriority priority) {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/LoadSqlWriter.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/LoadSqlWriter.java
index fb6ff10cf44..63180e75aac 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/LoadSqlWriter.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/LoadSqlWriter.java
@@ -37,8 +37,8 @@ public class LoadSqlWriter extends AbstractSqlWriter {
@Override
public void writeSelect(List<SqlHandler<?>> handlers) throws OseeCoreException {
- String txAlias = getAliasManager().getFirstAlias(TableEnum.TXS_TABLE);
- String artJoinAlias = getAliasManager().getFirstAlias(TableEnum.ARTIFACT_JOIN_TABLE);
+ String txAlias = getLastAlias(TableEnum.TXS_TABLE);
+ String artJoinAlias = getLastAlias(TableEnum.ARTIFACT_JOIN_TABLE);
write("SELECT%s ", getSqlHint());
write("%s.gamma_id, %s.mod_type, %s.branch_id, %s.transaction_id", txAlias, txAlias, txAlias, txAlias);
@@ -46,25 +46,24 @@ public class LoadSqlWriter extends AbstractSqlWriter {
write(", %s.transaction_id as stripe_transaction_id", txAlias);
}
write(",\n %s.art_id", artJoinAlias);
- int size = handlers.size();
- for (int index = 0; index < size; index++) {
+ for (SqlHandler<?> handler : handlers) {
+ setHandlerLevel(handler);
write(", ");
- SqlHandler<?> handler = handlers.get(index);
handler.addSelect(this);
}
}
@Override
public void writeGroupAndOrder() throws OseeCoreException {
- String artAlias = getAliasManager().getFirstAlias(TableEnum.ARTIFACT_JOIN_TABLE);
- String txAlias = getAliasManager().getFirstAlias(TableEnum.TXS_TABLE);
+ String artAlias = getLastAlias(TableEnum.ARTIFACT_JOIN_TABLE);
+ String txAlias = getLastAlias(TableEnum.TXS_TABLE);
write("\n ORDER BY %s.branch_id, %s.art_id", txAlias, artAlias);
- if (getAliasManager().hasAlias(TableEnum.ATTRIBUTE_TABLE)) {
- write(", %s.attr_id", getAliasManager().getFirstAlias(TableEnum.ATTRIBUTE_TABLE));
+ if (hasAlias(TableEnum.ATTRIBUTE_TABLE)) {
+ write(", %s.attr_id", getLastAlias(TableEnum.ATTRIBUTE_TABLE));
}
- if (getAliasManager().hasAlias(TableEnum.RELATION_TABLE)) {
- write(", %s.rel_link_id", getAliasManager().getFirstAlias(TableEnum.RELATION_TABLE));
+ if (hasAlias(TableEnum.RELATION_TABLE)) {
+ write(", %s.rel_link_id", getLastAlias(TableEnum.RELATION_TABLE));
}
write(", %s.transaction_id desc", txAlias);
}
@@ -81,7 +80,7 @@ public class LoadSqlWriter extends AbstractSqlWriter {
@Override
public String getTxBranchFilter(String txsAlias, boolean allowDeleted) {
StringBuilder sb = new StringBuilder();
- String artJoinAlias = getAliasManager().getFirstAlias(TableEnum.ARTIFACT_JOIN_TABLE);
+ String artJoinAlias = getLastAlias(TableEnum.ARTIFACT_JOIN_TABLE);
writeTxFilter(txsAlias, artJoinAlias, sb, allowDeleted);
sb.append(" AND ");
sb.append(txsAlias);
@@ -103,10 +102,7 @@ public class LoadSqlWriter extends AbstractSqlWriter {
*/
//@formatter:on
boolean hasTable[] =
- {
- getAliasManager().hasAlias(TableEnum.ARTIFACT_TABLE),
- getAliasManager().hasAlias(TableEnum.ATTRIBUTE_TABLE),
- getAliasManager().hasAlias(TableEnum.RELATION_TABLE)};
+ {hasAlias(TableEnum.ARTIFACT_TABLE), hasAlias(TableEnum.ATTRIBUTE_TABLE), hasAlias(TableEnum.RELATION_TABLE)};
/**********************************************************************
* Allow deleted artifacts applies even if the artifact table is not in the query. The other two only make sense
@@ -181,8 +177,8 @@ public class LoadSqlWriter extends AbstractSqlWriter {
* not made
*/
int count = 0;
- if (getAliasManager().hasAlias(TableEnum.ARTIFACT_TABLE)) {
- List<String> artTables = getAliasManager().getAliases(TableEnum.ARTIFACT_TABLE);
+ if (hasAlias(TableEnum.ARTIFACT_TABLE)) {
+ List<String> artTables = getAliases(TableEnum.ARTIFACT_TABLE);
if (OptionsUtil.areDeletedArtifactsIncluded(getOptions())) {
sb.append("(");
buildTableGamma(sb, artTables, txsAlias);
@@ -192,8 +188,8 @@ public class LoadSqlWriter extends AbstractSqlWriter {
count++;
}
}
- if (getAliasManager().hasAlias(TableEnum.ATTRIBUTE_TABLE)) {
- List<String> attrTables = getAliasManager().getAliases(TableEnum.ATTRIBUTE_TABLE);
+ if (hasAlias(TableEnum.ATTRIBUTE_TABLE)) {
+ List<String> attrTables = getAliases(TableEnum.ATTRIBUTE_TABLE);
if (OptionsUtil.areDeletedAttributesIncluded(getOptions())) {
if (count > 1) {
sb.append(" AND ");
@@ -206,8 +202,8 @@ public class LoadSqlWriter extends AbstractSqlWriter {
count++;
}
}
- if (getAliasManager().hasAlias(TableEnum.RELATION_TABLE)) {
- List<String> relationTables = getAliasManager().getAliases(TableEnum.RELATION_TABLE);
+ if (hasAlias(TableEnum.RELATION_TABLE)) {
+ List<String> relationTables = getAliases(TableEnum.RELATION_TABLE);
if (OptionsUtil.areDeletedAttributesIncluded(getOptions())) {
if (count > 1) {
sb.append(" AND ");
@@ -265,7 +261,7 @@ public class LoadSqlWriter extends AbstractSqlWriter {
sb.append(".transaction_id <= ?");
addParameter(OptionsUtil.getFromTransaction(getOptions()));
}
- String artJoinAlias = getAliasManager().getFirstAlias(TableEnum.ARTIFACT_JOIN_TABLE);
+ String artJoinAlias = getLastAlias(TableEnum.ARTIFACT_JOIN_TABLE);
sb.append(" AND ");
sb.append(txsAlias);
sb.append(".branch_id = ");
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImpl.java
index 7a6cba5892e..e8bd52f8099 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlContextFactoryImpl.java
@@ -18,7 +18,6 @@ import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.ds.Criteria;
-import org.eclipse.osee.orcs.core.ds.CriteriaSet;
import org.eclipse.osee.orcs.core.ds.QueryData;
import org.eclipse.osee.orcs.data.HasBranch;
import org.eclipse.osee.orcs.db.internal.SqlProvider;
@@ -63,10 +62,10 @@ public class ArtifactQuerySqlContextFactoryImpl implements QuerySqlContextFactor
private QuerySqlContext createQueryContext(OrcsSession session, QueryData queryData, QueryType queryType) throws OseeCoreException {
QuerySqlContext context = createContext(session, queryData);
- CriteriaSet criteriaSet = queryData.getCriteriaSet();
AbstractSqlWriter writer = createQueryWriter(context, queryData, queryType);
- List<SqlHandler<?>> handlers = handlerFactory.createHandlers(criteriaSet);
+
+ List<SqlHandler<?>> handlers = handlerFactory.createHandlers(queryData.getCriteriaSets());
writer.build(handlers);
return context;
}
@@ -86,7 +85,7 @@ public class ArtifactQuerySqlContextFactoryImpl implements QuerySqlContextFactor
private IOseeBranch getBranchToSearch(QueryData queryData) throws OseeCoreException {
IOseeBranch branch = null;
- Iterable<? extends Criteria> criterias = queryData.getCriteriaSet();
+ Iterable<? extends Criteria> criterias = queryData.getAllCriteria();
Optional<? extends Criteria> item = Iterables.tryFind(criterias, new Predicate<Criteria>() {
@Override
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlWriter.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlWriter.java
index 00a5073b6ab..ea04f551919 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlWriter.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/ArtifactQuerySqlWriter.java
@@ -38,8 +38,8 @@ public class ArtifactQuerySqlWriter extends AbstractSqlWriter {
}
private void writeSelectHelper() throws OseeCoreException {
- String txAlias = getAliasManager().getFirstAlias(TableEnum.TXS_TABLE);
- String artAlias = getAliasManager().getFirstAlias(TableEnum.ARTIFACT_TABLE);
+ String txAlias = getLastAlias(TableEnum.TXS_TABLE);
+ String artAlias = getLastAlias(TableEnum.ARTIFACT_TABLE);
write("SELECT%s ", getSqlHint());
if (OptionsUtil.isHistorical(getOptions())) {
@@ -56,7 +56,7 @@ public class ArtifactQuerySqlWriter extends AbstractSqlWriter {
write("SELECT count(xTable.art_id) FROM (\n ");
writeSelectHelper();
} else {
- String artAlias = getAliasManager().getFirstAlias(TableEnum.ARTIFACT_TABLE);
+ String artAlias = getLastAlias(TableEnum.ARTIFACT_TABLE);
write("SELECT%s count(%s.art_id)", getSqlHint(), artAlias);
}
} else {
@@ -67,13 +67,13 @@ public class ArtifactQuerySqlWriter extends AbstractSqlWriter {
@Override
public void writeGroupAndOrder() throws OseeCoreException {
if (OptionsUtil.isHistorical(getOptions())) {
- String txAlias = getAliasManager().getFirstAlias(TableEnum.TXS_TABLE);
- String artAlias = getAliasManager().getFirstAlias(TableEnum.ARTIFACT_TABLE);
+ String txAlias = getLastAlias(TableEnum.TXS_TABLE);
+ String artAlias = getLastAlias(TableEnum.ARTIFACT_TABLE);
write("\n GROUP BY %s.art_id, %s.branch_id", artAlias, txAlias);
}
if (!isCountQueryType()) {
- String txAlias = getAliasManager().getFirstAlias(TableEnum.TXS_TABLE);
- String artAlias = getAliasManager().getFirstAlias(TableEnum.ARTIFACT_TABLE);
+ String txAlias = getLastAlias(TableEnum.TXS_TABLE);
+ String artAlias = getLastAlias(TableEnum.ARTIFACT_TABLE);
write("\n ORDER BY %s.art_id, %s.branch_id", artAlias, txAlias);
} else {
if (OptionsUtil.isHistorical(getOptions())) {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryFilterFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryFilterFactoryImpl.java
index 3eab8d2fb90..0459f815f2a 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryFilterFactoryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QueryFilterFactoryImpl.java
@@ -68,7 +68,7 @@ public class QueryFilterFactoryImpl implements QueryFilterFactory {
@Override
public ArtifactDataCountHandler createHandler(HasCancellation cancellation, QueryData queryData, QuerySqlContext queryContext, LoadDataHandler handler) throws Exception {
- CriteriaSet criteriaSet = queryData.getCriteriaSet();
+ CriteriaSet criteriaSet = queryData.getLastCriteriaSet();
Set<CriteriaAttributeKeywords> criterias = criteriaSet.getCriteriaByType(CriteriaAttributeKeywords.class);
ArtifactDataCountHandler countingHandler;
if (criterias.isEmpty()) {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlContextFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlContextFactoryImpl.java
index 83a15588cb7..6dadf689adf 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlContextFactoryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlContextFactoryImpl.java
@@ -15,7 +15,6 @@ import org.eclipse.osee.framework.database.IOseeDatabaseService;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
-import org.eclipse.osee.orcs.core.ds.CriteriaSet;
import org.eclipse.osee.orcs.core.ds.QueryData;
import org.eclipse.osee.orcs.db.internal.SqlProvider;
import org.eclipse.osee.orcs.db.internal.search.QuerySqlContext;
@@ -59,10 +58,9 @@ public class QuerySqlContextFactoryImpl implements QuerySqlContextFactory {
private QuerySqlContext createQueryContext(OrcsSession session, QueryData queryData, QueryType queryType) throws OseeCoreException {
QuerySqlContext context = new QuerySqlContext(session, queryData.getOptions());
- CriteriaSet criteriaSet = queryData.getCriteriaSet();
AbstractSqlWriter writer =
new QuerySqlWriter(logger, dbService, sqlProvider, context, queryType, table, idColumn);
- List<SqlHandler<?>> handlers = handlerFactory.createHandlers(criteriaSet);
+ List<SqlHandler<?>> handlers = handlerFactory.createHandlers(queryData.getCriteriaSets());
writer.build(handlers);
return context;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlWriter.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlWriter.java
index 36d7fe6597c..759f3b95a6e 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlWriter.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/engines/QuerySqlWriter.java
@@ -38,7 +38,7 @@ public class QuerySqlWriter extends AbstractSqlWriter {
@Override
public void writeSelect(List<SqlHandler<?>> handlers) throws OseeCoreException {
- String tableAlias = getAliasManager().getFirstAlias(table);
+ String tableAlias = getLastAlias(table);
if (isCountQueryType()) {
write("SELECT%s count(%s.%s)", getSqlHint(), tableAlias, idColumn);
} else {
@@ -67,7 +67,7 @@ public class QuerySqlWriter extends AbstractSqlWriter {
@Override
public void writeGroupAndOrder() throws OseeCoreException {
if (!isCountQueryType()) {
- String tableAlias = getAliasManager().getFirstAlias(table);
+ String tableAlias = getLastAlias(table);
write("\n ORDER BY %s.%s", tableAlias, idColumn);
}
}
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
index 97f1aa0663c..692d680e8c4 100644
--- 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
@@ -145,18 +145,30 @@ public class AttributeTokenSqlHandler extends SqlHandler<CriteriaAttributeKeywor
@Override
public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException {
+ boolean artTableAdded = false;
+ boolean txsTableAdded = false;
+
if (!Strings.isValid(artAlias)) {
artAlias = writer.getAliases(TableEnum.ARTIFACT_TABLE).iterator().next();
+ } else {
+ artTableAdded = true;
}
if (!Strings.isValid(txsAlias)) {
txsAlias = writer.getAliases(TableEnum.TXS_TABLE).iterator().next();
+ } else {
+ txsTableAdded = true;
}
writer.write("%s.art_id = %s.art_id", artAlias, attrAlias);
- writer.writeAndLn();
- writer.write(writer.getTxBranchFilter(txsAlias));
- writer.writeAndLn();
- writer.write("%s.gamma_id = %s.gamma_id", txsAlias, artAlias);
+
+ if (artTableAdded) {
+ writer.writeAndLn();
+ writer.write("%s.gamma_id = %s.gamma_id", txsAlias, artAlias);
+ }
+ if (txsTableAdded) {
+ writer.writeAndLn();
+ writer.write(writer.getTxBranchFilter(txsAlias));
+ }
return true;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelatedToSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelatedToSqlHandler.java
index b4fb46b39ce..77c2c9ac84c 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelatedToSqlHandler.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelatedToSqlHandler.java
@@ -51,13 +51,10 @@ public class RelatedToSqlHandler extends SqlHandler<CriteriaRelatedTo> {
sb.append(TableEnum.ID_JOIN_TABLE.getName());
sb.append(" ");
sb.append(jIdAlias);
- } else {
- sb.append("\n");
}
List<String> aliases = writer.getAliases(TableEnum.ARTIFACT_TABLE);
if (!aliases.isEmpty()) {
int aSize = aliases.size();
- sb.append(" ");
for (int index = 0; index < aSize; index++) {
String artAlias = aliases.get(index);
sb.append(", ");
@@ -65,9 +62,8 @@ public class RelatedToSqlHandler extends SqlHandler<CriteriaRelatedTo> {
sb.append(" ");
sb.append(artAlias);
}
- sb.append("\n");
}
- sb.append(" WHERE txs.gamma_id = rel.gamma_id AND \n");
+ sb.append("\n WHERE txs.gamma_id = rel.gamma_id AND \n");
sb.append(getPredicate(writer, "txs", "rel"));
sb.append(" AND ");
sb.append(writer.getAllChangesTxBranchFilter("txs"));
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelationTypeFollowSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelationTypeFollowSqlHandler.java
new file mode 100644
index 00000000000..d6b0fa49b38
--- /dev/null
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/RelationTypeFollowSqlHandler.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2014 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.jdk.core.type.OseeCoreException;
+import org.eclipse.osee.orcs.core.ds.OptionsUtil;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeFollow;
+import org.eclipse.osee.orcs.db.internal.sql.AbstractSqlWriter;
+import org.eclipse.osee.orcs.db.internal.sql.SqlHandler;
+import org.eclipse.osee.orcs.db.internal.sql.TableEnum;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class RelationTypeFollowSqlHandler extends SqlHandler<CriteriaRelationTypeFollow> {
+
+ private CriteriaRelationTypeFollow criteria;
+
+ private String artAlias0;
+ private String txsAlias0;
+
+ private String relAlias1;
+ private String txsAlias1;
+
+ private String artAlias2;
+ private String txsAlias2;
+
+ @Override
+ public void setData(CriteriaRelationTypeFollow criteria) {
+ this.criteria = criteria;
+ }
+
+ @Override
+ public void addTables(AbstractSqlWriter writer) throws OseeCoreException {
+ List<String> artAliases = writer.getAliases(TableEnum.ARTIFACT_TABLE);
+ if (artAliases.isEmpty()) {
+ artAlias0 = writer.addTable(TableEnum.ARTIFACT_TABLE);
+ txsAlias0 = writer.addTable(TableEnum.TXS_TABLE);
+ } else {
+ artAlias0 = artAliases.iterator().next();
+ }
+ relAlias1 = writer.addTable(TableEnum.RELATION_TABLE);
+ txsAlias1 = writer.addTable(TableEnum.TXS_TABLE);
+
+ // Set to next Level
+ writer.nextAliasLevel();
+
+ artAlias2 = writer.addTable(TableEnum.ARTIFACT_TABLE);
+ txsAlias2 = writer.addTable(TableEnum.TXS_TABLE);
+ }
+
+ @Override
+ public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException {
+ boolean includeDeletedRelations = OptionsUtil.areDeletedRelationsIncluded(writer.getOptions());
+ IRelationTypeSide typeSide = criteria.getType();
+
+ if (txsAlias0 != null && artAlias0 != null) {
+ writer.write(artAlias0);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias0);
+ writer.write(".gamma_id");
+ writer.write(" AND ");
+ writer.write(writer.getTxBranchFilter(txsAlias0, includeDeletedRelations));
+ writer.write("\n AND \n");
+ }
+
+ writer.write(relAlias1);
+ writer.write(".rel_link_type_id = ?");
+ writer.addParameter(typeSide.getGuid());
+
+ ////////////////////// Source - Side /////////////
+ String aOrbArtId = typeSide.getSide().isSideA() ? ".b_art_id" : ".a_art_id";
+ writer.write(" AND ");
+ writer.write(relAlias1);
+ writer.write(aOrbArtId);
+ writer.write(" = ");
+ writer.write(artAlias0);
+ writer.write(".art_id");
+
+ writer.write(" AND ");
+ writer.write(relAlias1);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias1);
+ writer.write(".gamma_id");
+ writer.write(" AND ");
+ writer.write(writer.getTxBranchFilter(txsAlias1, includeDeletedRelations));
+
+ ////////////////////// Destination - Side /////////////
+ String oppositeAOrBartId = typeSide.getSide().isSideA() ? ".a_art_id" : ".b_art_id";
+ writer.write("\n AND \n");
+ writer.write(relAlias1);
+ writer.write(oppositeAOrBartId);
+ writer.write(" = ");
+ writer.write(artAlias2);
+ writer.write(".art_id");
+
+ writer.write(" AND ");
+ writer.write(artAlias2);
+ writer.write(".gamma_id = ");
+ writer.write(txsAlias2);
+ writer.write(".gamma_id");
+ writer.write(" AND ");
+ writer.write(writer.getTxBranchFilter(txsAlias2, includeDeletedRelations));
+ return true;
+ }
+
+ @Override
+ public int getPriority() {
+ return SqlHandlerPriority.FOLLOW_RELATION_TYPES.ordinal();
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java
index caf62c7eb6f..9d798b0eba3 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerFactoryUtil.java
@@ -27,13 +27,14 @@ import org.eclipse.osee.orcs.core.ds.criteria.CriteriaAuthorIds;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchAncestorOf;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchArchived;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchChildOf;
-import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchUuids;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchName;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchState;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchType;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaBranchUuids;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaCommitIds;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaDateRange;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaDateWithOperator;
+import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeFollow;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelatedTo;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeExists;
import org.eclipse.osee.orcs.core.ds.criteria.CriteriaRelationTypeNotExists;
@@ -78,6 +79,7 @@ public final class SqlHandlerFactoryUtil {
handleMap.put(CriteriaAttributeOther.class, AttributeOtherSqlHandler.class);
handleMap.put(CriteriaAttributeKeywords.class, AttributeTokenSqlHandler.class);
handleMap.put(CriteriaAllArtifacts.class, AllArtifactsSqlHandler.class);
+ handleMap.put(CriteriaRelationTypeFollow.class, RelationTypeFollowSqlHandler.class);
return new SqlHandlerFactoryImpl(logger, identityService, tagProcessor, handleMap);
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerPriority.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerPriority.java
index 74a64bbc115..c0aa260c0df 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerPriority.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/SqlHandlerPriority.java
@@ -22,5 +22,6 @@ public enum SqlHandlerPriority {
ATTRIBUTE_TYPE_EXISTS,
RELATION_TYPE_EXISTS,
RELATED_TO_ART_IDS,
- ALL_ARTIFACTS;
+ ALL_ARTIFACTS,
+ FOLLOW_RELATION_TYPES;
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AbstractSqlWriter.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AbstractSqlWriter.java
index 685820563a0..a6a64a845f1 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AbstractSqlWriter.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AbstractSqlWriter.java
@@ -46,6 +46,7 @@ public abstract class AbstractSqlWriter implements HasOptions {
private final SqlProvider sqlProvider;
private final SqlContext context;
private final QueryType queryType;
+ private int level = 0;
public AbstractSqlWriter(Log logger, IOseeDatabaseService dbService, SqlProvider sqlProvider, SqlContext context, QueryType queryType) {
this.logger = logger;
@@ -61,17 +62,26 @@ public abstract class AbstractSqlWriter implements HasOptions {
public void build(List<SqlHandler<?>> handlers) throws OseeCoreException {
Conditions.checkNotNullOrEmpty(handlers, "SqlHandlers");
- output.delete(0, output.length());
+ reset();
write(handlers);
- context.setSql(toString());
+ String sql = toString();
+ context.setSql(sql);
if (logger.isTraceEnabled()) {
logger.trace("Sql Writer - [%s]", context);
}
}
+ private void reset() {
+ output.delete(0, output.length());
+ tableEntries.clear();
+ withClauses.clear();
+ aliasManager.reset();
+ level = 0;
+ }
+
public boolean isCountQueryType() {
return QueryType.COUNT == queryType;
}
@@ -129,18 +139,11 @@ public abstract class AbstractSqlWriter implements HasOptions {
protected void computeWithClause(List<SqlHandler<?>> handlers) throws OseeCoreException {
for (SqlHandler<?> handler : handlers) {
+ setHandlerLevel(handler);
handler.addWithTables(this);
}
}
- public String getNextAlias(AliasEntry table) {
- return getAliasManager().getNextAlias(table);
- }
-
- protected SqlAliasManager getAliasManager() {
- return aliasManager;
- }
-
public SqlContext getContext() {
return context;
}
@@ -167,14 +170,20 @@ public abstract class AbstractSqlWriter implements HasOptions {
protected void computeTables(List<SqlHandler<?>> handlers) throws OseeCoreException {
for (SqlHandler<?> handler : handlers) {
+ setHandlerLevel(handler);
handler.addTables(this);
}
}
+ protected void setHandlerLevel(SqlHandler<?> handler) {
+ level = handler.getLevel();
+ }
+
protected void writePredicates(List<SqlHandler<?>> handlers) throws OseeCoreException {
int size = handlers.size();
for (int index = 0; index < size; index++) {
SqlHandler<?> handler = handlers.get(index);
+ setHandlerLevel(handler);
boolean modified = handler.addPredicates(this);
if (modified && index + 1 < size) {
writeAndLn();
@@ -195,8 +204,32 @@ public abstract class AbstractSqlWriter implements HasOptions {
}
}
+ protected boolean hasAlias(TableEnum table) {
+ return getAliasManager().hasAlias(table, level);
+ }
+
public List<String> getAliases(TableEnum table) {
- return getAliasManager().getAliases(table);
+ return getAliasManager().getAliases(table, level);
+ }
+
+ public String getFirstAlias(TableEnum table) {
+ return getAliasManager().getFirstAlias(table, level);
+ }
+
+ public String getLastAlias(TableEnum table) {
+ return getAliasManager().getLastAlias(table);
+ }
+
+ public String getNextAlias(AliasEntry table) {
+ return getAliasManager().getNextAlias(table);
+ }
+
+ public void nextAliasLevel() {
+ getAliasManager().nextLevel();
+ }
+
+ private SqlAliasManager getAliasManager() {
+ return aliasManager;
}
public void addTable(String table) {
@@ -204,8 +237,8 @@ public abstract class AbstractSqlWriter implements HasOptions {
}
public String addTable(AliasEntry table) {
- String alias = getAliasManager().getNextAlias(table);
- tableEntries.add(String.format("%s %s", table.getEntry(), alias));
+ String alias = getNextAlias(table);
+ tableEntries.add(String.format("%s %s", table.getName(), alias));
return alias;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AliasEntry.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AliasEntry.java
index d67169e99ce..5e2809f6412 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AliasEntry.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/AliasEntry.java
@@ -15,7 +15,7 @@ package org.eclipse.osee.orcs.db.internal.sql;
*/
public interface AliasEntry {
- String getAliasPrefix();
+ String getPrefix();
- String getEntry();
+ String getName();
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlAliasManager.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlAliasManager.java
index 03e8d8815e6..7e512529330 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlAliasManager.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlAliasManager.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.orcs.db.internal.sql;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
@@ -21,44 +22,91 @@ import java.util.Map;
*/
public class SqlAliasManager {
- private final HashMap<String, Alias> aliases = new HashMap<String, Alias>();
- private final Map<AliasEntry, List<String>> usedAliases = new HashMap<AliasEntry, List<String>>();
+ private final HashMap<String, Alias> aliasCounter = new HashMap<String, Alias>();
+ private final List<Map<String, LinkedList<String>>> usedAliases = new ArrayList<Map<String, LinkedList<String>>>();
+
+ private int level = 0;
+
+ private int getLevel() {
+ return level;
+ }
+
+ private Map<String, LinkedList<String>> getAliasByLevel(int level) {
+ if (level < usedAliases.size()) {
+ return usedAliases.get(level);
+ } else {
+ return Collections.emptyMap();
+ }
+ }
public boolean hasAlias(AliasEntry table) {
- return usedAliases.get(table) != null;
+ int level = getLevel();
+ return hasAlias(table, level);
}
- public String getFirstAlias(AliasEntry table) {
- return getAliases(table).get(0);
+ public boolean hasAlias(AliasEntry table, int level) {
+ return !getAliases(table, level).isEmpty();
}
- public List<String> getAliases(AliasEntry table) {
- List<String> values = usedAliases.get(table);
- return values != null ? values : Collections.<String> emptyList();
+ public List<String> getAliases(AliasEntry table, int level) {
+ List<String> linkedList = getAliasByLevel(level).get(table.getPrefix());
+ return linkedList != null ? linkedList : Collections.<String> emptyList();
+ }
+
+ public String getFirstAlias(TableEnum table, int level) {
+ return getAliases(table, level).get(0);
+ }
+
+ public String getLastAlias(AliasEntry table) {
+ int currentLevel = getLevel();
+ LinkedList<String> values = getAliasByLevel(currentLevel).get(table.getPrefix());
+ String toReturn = null;
+ if (values != null) {
+ toReturn = values.getLast();
+ }
+ return toReturn;
}
public String getNextAlias(AliasEntry table) {
- Alias alias = aliases.get(table.getAliasPrefix());
+ String prefix = table.getPrefix();
+
+ Alias alias = aliasCounter.get(prefix);
if (alias == null) {
- alias = new Alias(table.getAliasPrefix());
- aliases.put(table.getAliasPrefix(), alias);
+ alias = new Alias(prefix);
+ aliasCounter.put(prefix, alias);
}
- String toReturn = alias.next();
- putUsedAlias(table, toReturn);
- return toReturn;
+ String aliasValue = alias.next();
+
+ int level = getLevel();
+ putAlias(level, prefix, aliasValue);
+ return aliasValue;
}
- private void putUsedAlias(AliasEntry table, String alias) {
- List<String> values = usedAliases.get(table);
+ private void putAlias(int level, String prefix, String alias) {
+ Map<String, LinkedList<String>> map = null;
+ if (level < usedAliases.size()) {
+ map = usedAliases.get(level);
+ }
+ if (map == null) {
+ map = new HashMap<String, LinkedList<String>>();
+ usedAliases.add(level, map);
+ }
+
+ LinkedList<String> values = map.get(prefix);
if (values == null) {
values = new LinkedList<String>();
- usedAliases.put(table, values);
+ map.put(prefix, values);
}
values.add(alias);
}
+ public void nextLevel() {
+ level++;
+ }
+
public void reset() {
- for (Alias alias : aliases.values()) {
+ level = 0;
+ for (Alias alias : aliasCounter.values()) {
alias.reset();
}
usedAliases.clear();
@@ -85,4 +133,5 @@ public class SqlAliasManager {
aliasSuffix = 1;
}
}
+
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandler.java
index a48242c1342..809008c4c18 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandler.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandler.java
@@ -23,6 +23,7 @@ public abstract class SqlHandler<T extends Criteria> implements HasPriority {
private Log logger;
private IdentityLocator idService;
+ private int level;
public void setIdentityService(IdentityLocator idService) {
this.idService = idService;
@@ -40,6 +41,14 @@ public abstract class SqlHandler<T extends Criteria> implements HasPriority {
return logger;
}
+ public int getLevel() {
+ return level;
+ }
+
+ public void setLevel(int level) {
+ this.level = level;
+ }
+
@Override
public abstract int getPriority();
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactory.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactory.java
index a8c05ae1da2..e06cefef0b0 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactory.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactory.java
@@ -20,7 +20,9 @@ import org.eclipse.osee.orcs.core.ds.CriteriaSet;
*/
public interface SqlHandlerFactory {
- List<SqlHandler<?>> createHandlers(CriteriaSet criteriaSet) throws OseeCoreException;
+ List<SqlHandler<?>> createHandlers(CriteriaSet... criteriaSet) throws OseeCoreException;
+
+ List<SqlHandler<?>> createHandlers(Iterable<CriteriaSet> criteriaSets) throws OseeCoreException;
SqlHandler<?> createHandler(Criteria criteria) throws OseeCoreException;
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactoryImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactoryImpl.java
index c1a4b457342..a013e0abfdf 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactoryImpl.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlHandlerFactoryImpl.java
@@ -11,12 +11,13 @@
package org.eclipse.osee.orcs.db.internal.sql;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
-import org.eclipse.osee.framework.jdk.core.util.PriorityComparator;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.core.ds.Criteria;
import org.eclipse.osee.orcs.core.ds.CriteriaSet;
@@ -29,7 +30,7 @@ import org.eclipse.osee.orcs.db.internal.search.tagger.TagProcessor;
*/
public class SqlHandlerFactoryImpl implements SqlHandlerFactory {
- private static final PriorityComparator comparator = new PriorityComparator();
+ private static final SqlHandlerComparator HANDLER_COMPARATOR = new SqlHandlerComparator();
private final Map<Class<? extends Criteria>, Class<? extends SqlHandler<?>>> handleMap;
@@ -49,16 +50,30 @@ public class SqlHandlerFactoryImpl implements SqlHandlerFactory {
}
@Override
- public List<SqlHandler<?>> createHandlers(CriteriaSet criteriaSet) throws OseeCoreException {
+ public List<SqlHandler<?>> createHandlers(CriteriaSet... criteriaSet) throws OseeCoreException {
+ return createHandlers(Arrays.asList(criteriaSet));
+ }
+
+ @Override
+ public List<SqlHandler<?>> createHandlers(Iterable<CriteriaSet> criteriaSets) throws OseeCoreException {
List<SqlHandler<?>> handlers = new ArrayList<SqlHandler<?>>();
+ int level = 0;
+ for (CriteriaSet criteriaSet : criteriaSets) {
+ addHandlers(handlers, level, criteriaSet);
+ level++;
+ }
+ Collections.sort(handlers, HANDLER_COMPARATOR);
+ return handlers;
+ }
+
+ private void addHandlers(List<SqlHandler<?>> handlers, int index, CriteriaSet criteriaSet) {
for (Criteria criteria : criteriaSet) {
SqlHandler<?> handler = createHandler(criteria);
if (handler != null) {
+ handler.setLevel(index);
handlers.add(handler);
}
}
- Collections.sort(handlers, comparator);
- return handlers;
}
@Override
@@ -91,4 +106,16 @@ public class SqlHandlerFactoryImpl implements SqlHandlerFactory {
return handler;
}
+ private static final class SqlHandlerComparator implements Comparator<SqlHandler<?>> {
+
+ @Override
+ public int compare(SqlHandler<?> left, SqlHandler<?> right) {
+ int result = left.getLevel() - right.getLevel();
+ if (result == 0) {
+ result = left.getPriority() - right.getPriority();
+ }
+ return result;
+ }
+
+ }
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlUtil.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlUtil.java
index b54579d7649..40aed88efae 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlUtil.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/SqlUtil.java
@@ -24,12 +24,12 @@ public final class SqlUtil {
public static AliasEntry newAlias(final String name, final String prefix) {
return new AliasEntry() {
@Override
- public String getAliasPrefix() {
+ public String getPrefix() {
return prefix;
}
@Override
- public String getEntry() {
+ public String getName() {
return name;
}
};
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java
index c92e519519a..0f2dd9e3836 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/sql/TableEnum.java
@@ -33,18 +33,14 @@ public enum TableEnum implements AliasEntry {
this.aliasPrefix = aliasPrefix;
}
+ @Override
public String getName() {
return tableName;
}
@Override
- public String getAliasPrefix() {
+ public String getPrefix() {
return aliasPrefix;
}
- @Override
- public String getEntry() {
- return tableName;
- }
-
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java
index d7405be68d1..16f2e98d24b 100644
--- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java
+++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsQueryTest.java
@@ -17,6 +17,8 @@ import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
@@ -34,10 +36,12 @@ import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.orcs.ApplicationContext;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.OrcsBranch;
+import org.eclipse.osee.orcs.data.ArtifactId;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.AttributeReadable;
import org.eclipse.osee.orcs.data.BranchReadable;
import org.eclipse.osee.orcs.data.HasLocalId;
+import org.eclipse.osee.orcs.data.TransactionReadable;
import org.eclipse.osee.orcs.db.mock.OsgiService;
import org.eclipse.osee.orcs.search.Match;
import org.eclipse.osee.orcs.search.QueryBuilder;
@@ -320,6 +324,102 @@ public class OrcsQueryTest {
}
}
+ @Test
+ public void testFollowRelationType1() throws Exception {
+ QueryBuilder builder = factory.fromBranch(TestBranches.SAW_Bld_1) //
+ .andIsOfType(CoreArtifactTypes.RootArtifact)//
+ .followRelation(CoreRelationTypes.Default_Hierarchical__Child);
+
+ ResultSet<ArtifactReadable> results = builder.getResults();
+ assertEquals(8, results.size());
+
+ Iterator<String> iterator = getNames(results).iterator();
+ assertEquals("Hardware Requirements", iterator.next());
+ assertEquals("Integration Tests", iterator.next());
+ assertEquals("SAW Product Decomposition", iterator.next());
+ assertEquals("Software Requirements", iterator.next());
+ assertEquals("Subsystem Requirements", iterator.next());
+ assertEquals("System Requirements", iterator.next());
+ assertEquals("Validation Tests", iterator.next());
+ assertEquals("Verification Tests", iterator.next());
+ }
+
+ @Test
+ public void testFollowRelationType2() throws Exception {
+ QueryBuilder builder = factory.fromBranch(TestBranches.SAW_Bld_1) //
+ .andIsOfType(CoreArtifactTypes.RootArtifact)//
+ .followRelation(CoreRelationTypes.Default_Hierarchical__Child)//
+ .andIsOfType(CoreArtifactTypes.Component);
+
+ ResultSet<ArtifactReadable> results = builder.getResults();
+ assertEquals(1, results.size());
+
+ assertEquals("SAW Product Decomposition", results.getExactlyOne().getName());
+ }
+
+ @Test
+ public void testFollowRelationType3() throws Exception {
+ QueryBuilder builder = factory.fromBranch(TestBranches.SAW_Bld_1) //
+ .and(CoreAttributeTypes.Name, "collaboration", QueryOption.TOKEN_MATCH_ORDER__ANY, QueryOption.CASE__IGNORE)//
+ .followRelation(CoreRelationTypes.Default_Hierarchical__Child)//
+ .and(CoreAttributeTypes.Name, "object", QueryOption.TOKEN_MATCH_ORDER__ANY, QueryOption.CASE__IGNORE);
+
+ ResultSet<ArtifactReadable> results = builder.getResults();
+ assertEquals(1, results.size());
+
+ assertEquals("Robot Object", results.getExactlyOne().getName());
+ }
+
+ @Test
+ public void testFollowRelationTypeHistorical() throws Exception {
+ QueryBuilder query = factory.fromBranch(TestBranches.SAW_Bld_2) //
+ .andNameEquals("Robot API") //
+ .andIsOfType(CoreArtifactTypes.SoftwareRequirement)//
+ .followRelation(CoreRelationTypes.Default_Hierarchical__Child)//
+ .and(CoreAttributeTypes.Name, "Robot", QueryOption.CASE__IGNORE, QueryOption.TOKEN_MATCH_ORDER__ANY);
+
+ ResultSet<ArtifactReadable> results = query.getResults();
+ assertEquals(2, results.size());
+
+ Iterator<String> iterator = getNames(results).iterator();
+ assertEquals("Robot Interfaces", iterator.next());
+ assertEquals("Robot collaboration", iterator.next());
+
+ // Add a child
+ ArtifactReadable parent = results.iterator().next().getParent();
+ author = factory.fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne();
+ TransactionBuilder tx =
+ orcsApi.getTransactionFactory(null).createTransaction(TestBranches.SAW_Bld_2, author, "FollowTest");
+ ArtifactId child = tx.createArtifact(CoreArtifactTypes.SoftwareRequirement, "Dummy Robot");
+ tx.relate(parent, CoreRelationTypes.Default_Hierarchical__Child, child);
+ TransactionReadable commitTx = tx.commit();
+ int headTx = commitTx.getLocalId();
+
+ results = query.getResults();
+ assertEquals(3, results.size());
+
+ iterator = getNames(results).iterator();
+ assertEquals("Dummy Robot", iterator.next());
+ assertEquals("Robot Interfaces", iterator.next());
+ assertEquals("Robot collaboration", iterator.next());
+
+ query.fromTransaction(headTx - 1);
+ results = query.getResults();
+ assertEquals(2, results.size());
+
+ iterator = getNames(results).iterator();
+ assertEquals("Robot Interfaces", iterator.next());
+ assertEquals("Robot collaboration", iterator.next());
+ }
+
+ private Set<String> getNames(ResultSet<ArtifactReadable> results) {
+ Set<String> names = new TreeSet<String>();
+ for (ArtifactReadable art : results) {
+ names.add(art.getName());
+ }
+ return names;
+ }
+
private BranchReadable setupNameEqualsArtifacts() throws Exception {
author = factory.fromBranch(CoreBranches.COMMON).andIds(SystemUser.OseeSystem).getResults().getExactlyOne();
IOseeBranch branchToken = TokenFactory.createBranch("TestAndNameEquals");
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 43be1e6d520..41d0e295d2a 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
@@ -204,6 +204,13 @@ public interface QueryBuilder {
QueryBuilder andRelatedToLocalIds(IRelationTypeSide relationTypeSide, Collection<Integer> artifactIds) throws OseeCoreException;
/**
+ * Search related artifacts with specific criteria. Will only follow first level of relations
+ *
+ * @param relationTypeSide the type-side to search on
+ */
+ QueryBuilder followRelation(IRelationTypeSide relationTypeSide);
+
+ /**
* Executes query
*
* @return artifact search results

Back to the top