diff options
author | jmisinco | 2011-11-29 19:59:14 +0000 |
---|---|---|
committer | Ryan D. Brooks | 2011-11-29 19:59:14 +0000 |
commit | 8f17fd28a56580f8c6b2c68c7c31a77af263721a (patch) | |
tree | a26f1e010914f65dee9740194788316bf9488f2d | |
parent | 6095e83b19f6962ab8042b82de221dcbea28b5dd (diff) | |
download | org.eclipse.osee-8f17fd28a56580f8c6b2c68c7c31a77af263721a.tar.gz org.eclipse.osee-8f17fd28a56580f8c6b2c68c7c31a77af263721a.tar.xz org.eclipse.osee-8f17fd28a56580f8c6b2c68c7c31a77af263721a.zip |
bug[ats_XXZRZ]: Null TransactionData returned for invalid transaction ids
8 files changed, 62 insertions, 57 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/cache/DatabaseTransactionRecordAccessor.java b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/cache/DatabaseTransactionRecordAccessor.java index 40bcf83fad6..feef2a63a7a 100644 --- a/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/cache/DatabaseTransactionRecordAccessor.java +++ b/plugins/org.eclipse.osee.framework.core.datastore/src/org/eclipse/osee/framework/core/datastore/cache/DatabaseTransactionRecordAccessor.java @@ -26,6 +26,7 @@ import org.eclipse.osee.framework.database.IOseeDatabaseService; import org.eclipse.osee.framework.database.core.IOseeStatement; import org.eclipse.osee.framework.database.core.IdJoinQuery; import org.eclipse.osee.framework.database.core.JoinUtility; +import org.eclipse.osee.framework.jdk.core.type.MutableInteger; /** * @author Roberto E. Escobar @@ -33,18 +34,21 @@ import org.eclipse.osee.framework.database.core.JoinUtility; public class DatabaseTransactionRecordAccessor implements ITransactionDataAccessor { private static final String SELECT_BASE_TRANSACTION = - "select txd.* from osee_branch ob, osee_tx_details txd WHERE ob.branch_id = ? AND ob.baseline_transaction_id = txd.transaction_id"; + "select * from osee_tx_details where branch_id = ? and tx_type = ?"; private static final String SELECT_BY_TRANSACTION = "select * from osee_tx_details WHERE transaction_id = ?"; - private static final String SELECT_BRANCH_TRANSACTIONS = - "select * from osee_tx_details where branch_id = ? order by transaction_id DESC"; + private static final String SELECT_HEAD_TRANSACTION = + "select * from osee_tx_details where transaction_id = (select max(transaction_id) from osee_tx_details where branch_id = ?) and branch_id = ?"; private static final String SELECT_TRANSACTIONS_BY_QUERY_ID = - "select * from osee_tx_details txd, osee_join_id oji where txd.transaction_id = oji.id and oji.query_id = ?"; + "select * from osee_join_id oji, osee_tx_details txd where oji.query_id = ? and txd.transaction_id = oji.id"; + + private static final String SELECT_NON_EXISTING_TRANSACTIONS_BY_QUERY_ID = + "select oji.id from osee_join_id oji where oji.query_id = ? and not exists (select 1 from osee_tx_details txd where txd.transaction_id = oji.id)"; private static final String GET_PRIOR_TRANSACTION = - "select transaction_id FROM osee_tx_details where branch_id = ? and transaction_id < ? order by transaction_id desc"; + "select max(transaction_id) FROM osee_tx_details where branch_id = ? and transaction_id < ?"; private final IOseeDatabaseService oseeDatabaseService; private final BranchCache branchCache; @@ -74,32 +78,27 @@ public class DatabaseTransactionRecordAccessor implements ITransactionDataAccess } joinQuery.store(); - loadFromTransaction(cache, null, 5000, false, SELECT_TRANSACTIONS_BY_QUERY_ID, joinQuery.getQueryId()); + loadTransactions(cache, transactionIds.size(), SELECT_TRANSACTIONS_BY_QUERY_ID, joinQuery.getQueryId()); } finally { joinQuery.delete(); } } else { - loadFromTransaction(cache, null, 1, SELECT_BY_TRANSACTION, transactionIds.iterator().next()); + loadTransaction(cache, SELECT_BY_TRANSACTION, transactionIds.iterator().next()); } } @Override - public void loadTransactionRecord(TransactionCache cache, Branch branch) throws OseeCoreException { - ensureDependantCachePopulated(); - loadFromTransaction(cache, branch, 1000, SELECT_BRANCH_TRANSACTIONS, branch.getId()); - } - - @Override public TransactionRecord loadTransactionRecord(TransactionCache cache, Branch branch, TransactionVersion transactionType) throws OseeCoreException { ensureDependantCachePopulated(); TransactionRecord toReturn = null; switch (transactionType) { case BASE: - toReturn = loadFirstTransactionRecord(cache, branch, SELECT_BASE_TRANSACTION, branch.getId()); + toReturn = + loadTransaction(cache, SELECT_BASE_TRANSACTION, branch.getId(), TransactionDetailsType.Baselined); break; case HEAD: - toReturn = loadFirstTransactionRecord(cache, branch, SELECT_BRANCH_TRANSACTIONS, branch.getId()); + toReturn = loadTransaction(cache, SELECT_HEAD_TRANSACTION, branch.getId(), branch.getId()); break; default: throw new OseeStateException("Transaction Type [%s] is not supported", transactionType); @@ -107,22 +106,36 @@ public class DatabaseTransactionRecordAccessor implements ITransactionDataAccess return toReturn; } - private TransactionRecord loadFirstTransactionRecord(TransactionCache cache, Branch branch, String query, Object... parameters) throws OseeCoreException { - ensureDependantCachePopulated(); - return loadFromTransaction(cache, branch, 1, true, query, parameters); + private void loadTransactions(TransactionCache cache, int expectedCount, String query, int queryId) throws OseeCoreException { + MutableInteger numberLoaded = new MutableInteger(-1); + loadFromTransaction(cache, expectedCount, numberLoaded, query, queryId); + + if (numberLoaded.getValue() != expectedCount) { + IOseeStatement chStmt = oseeDatabaseService.getStatement(); + try { + chStmt.runPreparedQuery(expectedCount, SELECT_NON_EXISTING_TRANSACTIONS_BY_QUERY_ID, queryId); + while (chStmt.next()) { + int transactionNumber = chStmt.getInt("id"); + factory.getOrCreate(cache, transactionNumber); + } + } finally { + chStmt.close(); + } + } } - private void loadFromTransaction(TransactionCache cache, Branch branch, int fetchSize, String query, Object... parameters) throws OseeCoreException { - ensureDependantCachePopulated(); - loadFromTransaction(cache, branch, fetchSize, false, query, parameters); + private TransactionRecord loadTransaction(TransactionCache cache, String query, Object... parameters) throws OseeCoreException { + return loadFromTransaction(cache, 1, new MutableInteger(0), query, parameters); } - private TransactionRecord loadFromTransaction(TransactionCache cache, Branch branch, int fetchSize, boolean isOnlyReadFirstResult, String query, Object... parameters) throws OseeCoreException { + private TransactionRecord loadFromTransaction(TransactionCache cache, int expectedCount, MutableInteger numberLoaded, String query, Object... parameters) throws OseeCoreException { IOseeStatement chStmt = oseeDatabaseService.getStatement(); TransactionRecord record = null; + int count = 0; try { - chStmt.runPreparedQuery(fetchSize, query, parameters); + chStmt.runPreparedQuery(expectedCount, query, parameters); while (chStmt.next()) { + count++; int branchId = chStmt.getInt("branch_id"); int transactionNumber = chStmt.getInt("transaction_id"); String comment = chStmt.getString("osee_comment"); @@ -134,10 +147,8 @@ public class DatabaseTransactionRecordAccessor implements ITransactionDataAccess record = prepareTransactionRecord(cache, transactionNumber, branchId, comment, timestamp, authorArtId, commitArtId, txType); - if (isOnlyReadFirstResult) { - break; - } } + numberLoaded.setValue(count); } finally { chStmt.close(); } diff --git a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java index 9c2fd414955..ce2fd7d3ac3 100644 --- a/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java +++ b/plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java @@ -62,12 +62,6 @@ public class MockOseeTransactionDataAccessor implements ITransactionDataAccessor @SuppressWarnings("unused") @Override - public void loadTransactionRecord(TransactionCache cache, Branch branch) throws OseeCoreException { - // Empty - } - - @SuppressWarnings("unused") - @Override public TransactionRecord loadTransactionRecord(TransactionCache cache, Branch branch, TransactionVersion transactionType) throws OseeCoreException { return null; } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/TransactionRecord.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/TransactionRecord.java index 5cd77f9453c..f5a4e63817d 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/TransactionRecord.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/TransactionRecord.java @@ -21,6 +21,7 @@ import org.eclipse.osee.framework.core.util.Conditions; * @author Jeff C. Phillips */ public final class TransactionRecord implements IAdaptable { + private static final int NON_EXISTING_BRANCH = -1; private final int transactionNumber; private final TransactionDetailsType txType; @@ -42,6 +43,14 @@ public final class TransactionRecord implements IAdaptable { this.branchCache = null; } + public TransactionRecord(int transactionNumber) { + this(transactionNumber, NON_EXISTING_BRANCH, "INVALID", new Date(0), -1, -1, TransactionDetailsType.INVALID); + } + + public boolean exists() { + return branchId != NON_EXISTING_BRANCH; + } + public int getBranchId() { return branchId; } diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/TransactionRecordFactory.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/TransactionRecordFactory.java index 3706cc425df..eca3e8817ed 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/TransactionRecordFactory.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/TransactionRecordFactory.java @@ -15,24 +15,20 @@ import org.eclipse.osee.framework.core.enums.TransactionDetailsType; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.core.model.cache.IOseeTypeFactory; import org.eclipse.osee.framework.core.model.cache.TransactionCache; -import org.eclipse.osee.framework.core.util.Conditions; /** * @author Roberto E. Escobar */ public class TransactionRecordFactory implements IOseeTypeFactory { - public TransactionRecordFactory() { - } - public TransactionRecord create(int transactionNumber, int branchId, String comment, Date timestamp, int authorArtId, int commitArtId, TransactionDetailsType txType) throws OseeCoreException { - Conditions.checkExpressionFailOnTrue(transactionNumber < 1, "[%s] is not a valid transaction number", - transactionNumber); - Conditions.checkNotNull(timestamp, "timestamp"); - Conditions.checkNotNull(txType, "transaction type"); return new TransactionRecord(transactionNumber, branchId, comment, timestamp, authorArtId, commitArtId, txType); } + public TransactionRecord create(int transactionNumber) { + return new TransactionRecord(transactionNumber); + } + public TransactionRecord createOrUpdate(TransactionCache cache, int transactionNumber, int branchId, String comment, Date timestamp, int authorArtId, int commitArtId, TransactionDetailsType txType) throws OseeCoreException { TransactionRecord record = cache.getById(transactionNumber); if (record == null) { @@ -47,4 +43,13 @@ public class TransactionRecordFactory implements IOseeTypeFactory { cache.cache(record); return record; } + + public TransactionRecord getOrCreate(TransactionCache cache, int transactionNumber) throws OseeCoreException { + TransactionRecord record = cache.getById(transactionNumber); + if (record == null) { + record = new TransactionRecord(transactionNumber); + cache.cache(record); + } + return record; + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java index 58d6b2bbe43..a4be2eb8c13 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java @@ -30,14 +30,6 @@ public interface ITransactionDataAccessor { public void loadTransactionRecord(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException; /** - * Loads all transactions for a specific branch - * - * @param cache to populate - * @param branch to load - */ - public void loadTransactionRecord(TransactionCache cache, Branch branch) throws OseeCoreException; - - /** * Load a specific branch transaction type * * @see {@link TransactionVersion} diff --git a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java index 5171a28ea45..b0f41fa280f 100644 --- a/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java +++ b/plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java @@ -98,9 +98,6 @@ public class TransactionCache implements IOseeCache<String, TransactionRecord> { loadTransactions(Collections.singletonList(txId)); transactionRecord = getById(txId); if (transactionRecord == null) { - if (txId == 1) { // handle bootstrap case for system root branch creation - return null; - } throw new OseeStateException("Transaction Record[%s] was not found", txId); } } diff --git a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/TransactionDetailsType.java b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/TransactionDetailsType.java index b980fd48082..cad2f24be26 100644 --- a/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/TransactionDetailsType.java +++ b/plugins/org.eclipse.osee.framework.core/src/org/eclipse/osee/framework/core/enums/TransactionDetailsType.java @@ -15,6 +15,7 @@ package org.eclipse.osee.framework.core.enums; * @author Jeff C. Phillips */ public enum TransactionDetailsType { + INVALID(-1), NonBaselined(0), Baselined(1), reverted(2); diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java index ce0159f5275..a957b7a0a4e 100644 --- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java +++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/ClientTransactionAccessor.java @@ -54,11 +54,6 @@ public class ClientTransactionAccessor implements ITransactionDataAccessor { } @Override - public void loadTransactionRecord(TransactionCache cache, Branch branch) { - // provided for subclass implementation - } - - @Override public TransactionRecord loadTransactionRecord(TransactionCache cache, Branch branch, TransactionVersion transactionType) { return null; } @@ -87,7 +82,8 @@ public class ClientTransactionAccessor implements ITransactionDataAccessor { @Override public TransactionRecord getOrLoadPriorTransaction(TransactionCache cache, int transactionNumber, int branchId) throws OseeCoreException { int priorTransactionId = - ConnectionHandler.runPreparedQueryFetchInt(-1, GET_PRIOR_TRANSACTION, branchId, transactionNumber); + ConnectionHandler.runPreparedQueryFetchInt(transactionNumber, GET_PRIOR_TRANSACTION, branchId, + transactionNumber); return cache.getOrLoad(priorTransactionId); } } |