diff options
author | Roberto E. Escobar | 2014-10-02 22:14:46 +0000 |
---|---|---|
committer | Roberto E. Escobar | 2014-10-02 22:40:19 +0000 |
commit | f80f15758129ad0c615226317130bffc6409b7d7 (patch) | |
tree | 38eb0972fa65c3086a2434474af0090387a2cb20 | |
parent | 6d69d568a5ed86c91762d92a15912870aa3a91a8 (diff) | |
download | org.eclipse.osee-f80f15758129ad0c615226317130bffc6409b7d7.tar.gz org.eclipse.osee-f80f15758129ad0c615226317130bffc6409b7d7.tar.xz org.eclipse.osee-f80f15758129ad0c615226317130bffc6409b7d7.zip |
feature[ats_ATS112693]: Add get prior tx support to TxQuery
Change-Id: I242dccee6828f32cb34b17ecdd2ec34cd3b64c95
8 files changed, 175 insertions, 1 deletions
diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaTxGetPrior.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaTxGetPrior.java new file mode 100644 index 00000000000..add5a95c2b9 --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/ds/criteria/CriteriaTxGetPrior.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.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 CriteriaTxGetPrior extends Criteria { + + private final int txId; + + public CriteriaTxGetPrior(int txId) { + super(); + this.txId = txId; + } + + public int getTxId() { + return txId; + } + + @Override + public void checkValid(Options options) throws OseeCoreException { + super.checkValid(options); + Conditions.checkExpressionFailOnTrue(txId < 0, "TxId [%s] is invalid. Must be >= 0", txId); + } + + @Override + public String toString() { + return "CriteriaTxGetPrior [txId=" + txId + "]"; + } + +} diff --git a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionCriteriaFactory.java b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionCriteriaFactory.java index 8098f132715..dcd39669eb0 100644 --- a/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionCriteriaFactory.java +++ b/plugins/org.eclipse.osee.orcs.core/src/org/eclipse/osee/orcs/core/internal/search/TransactionCriteriaFactory.java @@ -24,6 +24,7 @@ import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxArtifactGuids; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxBranchIds; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxComment; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxGetHead; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxGetPrior; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxIdWithOperator; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxIdWithTwoOperators; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxIds; @@ -92,4 +93,8 @@ public class TransactionCriteriaFactory { return new CriteriaTxGetHead(branchUuid); } + public Criteria newGetPriorTx(int txId) { + return new CriteriaTxGetPrior(txId); + } + }
\ No newline at end of file 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 bc0af2851bc..feeddc973a9 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 @@ -266,6 +266,13 @@ public class TransactionQueryImpl implements TransactionQuery { return this; } + @Override + public TransactionQuery andIsPriorTx(int txId) throws OseeCoreException { + Criteria criteria = criteriaFactory.newGetPriorTx(txId); + addAndCheck(queryData, criteria); + return this; + } + private QueryData checkAndCloneQueryData() throws OseeCoreException { QueryData queryData = getQueryData().clone(); CriteriaSet criteriaSet = queryData.getLastCriteriaSet(); diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/TxQuerySqlContextFactoryImplTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/TxQuerySqlContextFactoryImplTest.java index 935c97d26ec..28c706e571d 100644 --- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/TxQuerySqlContextFactoryImplTest.java +++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/internal/search/engines/TxQuerySqlContextFactoryImplTest.java @@ -35,6 +35,7 @@ import org.eclipse.osee.orcs.core.ds.criteria.CriteriaCommitIds; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaDateWithOperator; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxBranchIds; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxComment; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxGetPrior; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxIdWithOperator; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxIds; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxType; @@ -267,6 +268,31 @@ public class TxQuerySqlContextFactoryImplTest { } + @Test + public void testQueryTxPrior() throws Exception { + String expected = + "SELECT/*+ ordered */ txd1.*\n" + // + " FROM \n" + // + "osee_tx_details txd1\n" + // + " WHERE \n" + // + "txd1.transaction_id = (SELECT max(td2.transaction_id) FROM osee_tx_details td1,osee_tx_details td2 WHERE td1.transaction_id = ? AND td1.branch_id = td2.branch_id AND td1.transaction_id > td2.transaction_id)\n" + // + " ORDER BY txd1.transaction_id"; + + queryData.addCriteria(prior(3)); + + QuerySqlContext context = queryEngine.createQueryContext(session, queryData); + + assertEquals(expected, context.getSql()); + + List<Object> parameters = context.getParameters(); + assertEquals(1, parameters.size()); + List<AbstractJoinQuery> joins = context.getJoins(); + assertEquals(0, joins.size()); + + Iterator<Object> iterator = parameters.iterator(); + assertEquals(3, iterator.next()); + } + private static Criteria id(Integer... values) { return new CriteriaTxIds(Arrays.asList(values)); } @@ -299,4 +325,7 @@ public class TxQuerySqlContextFactoryImplTest { return new CriteriaCommitIds(ids); } + private static Criteria prior(Integer value) { + return new CriteriaTxGetPrior(value); + } } 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 9d798b0eba3..e15077b5151 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 @@ -34,9 +34,9 @@ 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.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; @@ -44,6 +44,7 @@ import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxArtifactGuids; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxBranchIds; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxComment; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxGetHead; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxGetPrior; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxIdWithOperator; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxIdWithTwoOperators; import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxIds; @@ -117,6 +118,7 @@ public final class SqlHandlerFactoryUtil { handleMap.put(CriteriaTxArtifactGuids.class, TxArtifactGuidSqlHandler.class); handleMap.put(CriteriaCommitIds.class, TxCommitArtIdSqlHandler.class); handleMap.put(CriteriaTxGetHead.class, TxGetHeadSqlHandler.class); + handleMap.put(CriteriaTxGetPrior.class, TxGetPriorSqlHandler.class); return new SqlHandlerFactoryImpl(logger, identityService, handleMap); } diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/TxGetPriorSqlHandler.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/TxGetPriorSqlHandler.java new file mode 100644 index 00000000000..7422658dd8d --- /dev/null +++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/handlers/TxGetPriorSqlHandler.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * 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.jdk.core.type.OseeCoreException; +import org.eclipse.osee.orcs.core.ds.criteria.CriteriaTxGetPrior; +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 TxGetPriorSqlHandler extends SqlHandler<CriteriaTxGetPrior> { + + private CriteriaTxGetPrior criteria; + + private String txdAlias; + + @Override + public void setData(CriteriaTxGetPrior criteria) { + this.criteria = criteria; + } + + @Override + public void addTables(AbstractSqlWriter writer) { + List<String> aliases = writer.getAliases(TableEnum.TX_DETAILS_TABLE); + if (aliases.isEmpty()) { + txdAlias = writer.addTable(TableEnum.TX_DETAILS_TABLE); + } else { + txdAlias = aliases.iterator().next(); + } + } + + @Override + public boolean addPredicates(AbstractSqlWriter writer) throws OseeCoreException { + writer.write(txdAlias); + writer.write(".transaction_id = "); + writer.write("(SELECT max(td2.transaction_id) FROM "); + writer.write(TableEnum.TX_DETAILS_TABLE.getName()); + writer.write(" td1,"); + writer.write(TableEnum.TX_DETAILS_TABLE.getName()); + writer.write(" td2"); + writer.write(" WHERE "); + writer.write("td1"); + writer.write(".transaction_id = ?"); + writer.write(" AND "); + writer.write("td1.branch_id = td2.branch_id"); + writer.write(" AND "); + writer.write("td1.transaction_id > td2.transaction_id)"); + writer.addParameter(criteria.getTxId()); + return true; + } + + @Override + public int getPriority() { + return TxSqlHandlerPriority.TX_ID.ordinal(); + } +} diff --git a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTxQueryTest.java b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTxQueryTest.java index 5ba345408aa..e5545b289ab 100644 --- a/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTxQueryTest.java +++ b/plugins/org.eclipse.osee.orcs.test/src/org/eclipse/osee/orcs/api/OrcsTxQueryTest.java @@ -636,6 +636,22 @@ public class OrcsTxQueryTest { //@formatter:on } + @Test + public void testGetPriorTx() throws OseeCoreException { + TransactionQuery query = factory.transactionQuery(); + query.andIsPriorTx(24); + + ResultSet<TransactionReadable> results = query.getResults(); + assertEquals(1, results.size()); + assertEquals(1, query.getCount()); + + Iterator<TransactionReadable> it = results.iterator(); + assertTx(it.next(), 14, NonBaselined, "2013-05-06 14:18:07.204", "SimpleTemplateProviderTask", 570, 0, 0); + + Iterator<Integer> ids = query.getResultsAsIds().iterator(); + assertEquals(Integer.valueOf(14), ids.next()); + } + private static void assertTx(TransactionReadable actual, Integer localId, TransactionDetailsType type, String date, String comment, long branchUuid, int authorId, int commitId) { assertEquals(localId, actual.getLocalId()); assertEquals(type, actual.getTxType()); diff --git a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/TransactionQuery.java b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/TransactionQuery.java index e69108eb71d..fa3d063212c 100644 --- a/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/TransactionQuery.java +++ b/plugins/org.eclipse.osee.orcs/src/org/eclipse/osee/orcs/search/TransactionQuery.java @@ -82,6 +82,8 @@ public interface TransactionQuery { TransactionQuery andIsHead(IOseeBranch branch) throws OseeCoreException; + TransactionQuery andIsPriorTx(int txId) throws OseeCoreException; + ResultSet<TransactionReadable> getResults() throws OseeCoreException; ResultSet<Integer> getResultsAsIds() throws OseeCoreException; |