Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRyan D. Brooks2016-04-21 17:23:13 +0000
committerAngel Avila2016-04-21 17:23:13 +0000
commitee98c5442130c551f55899f183b7770f870c9a06 (patch)
treec8f183e71e5b2e5238e8a9384461c4cc0a66881a
parentcb879478a3ea400494308e482478b813bed59f64 (diff)
downloadorg.eclipse.osee-ee98c5442130c551f55899f183b7770f870c9a06.tar.gz
org.eclipse.osee-ee98c5442130c551f55899f183b7770f870c9a06.tar.xz
org.eclipse.osee-ee98c5442130c551f55899f183b7770f870c9a06.zip
refactor: Remove usage of JdbcClient.getStatement
-rw-r--r--plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java108
-rw-r--r--plugins/org.eclipse.osee.framework.core.model.test/src/org/eclipse/osee/framework/core/model/mocks/MockOseeTransactionDataAccessor.java2
-rw-r--r--plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/ITransactionDataAccessor.java6
-rw-r--r--plugins/org.eclipse.osee.framework.core.model/src/org/eclipse/osee/framework/core/model/cache/TransactionCache.java2
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java30
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeAttributes.java15
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/UpdateMergeBranch.java49
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java2
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java27
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java72
-rw-r--r--plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/utility/InvalidTxCurrentsAndModTypes.java58
-rw-r--r--plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/database/AbstractDatabaseStorage.java14
-rw-r--r--plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/JdbcClient.java4
-rw-r--r--plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/JdbcClientImpl.java9
-rw-r--r--plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSessionDatabaseStore.java30
-rw-r--r--plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java16
-rw-r--r--plugins/org.eclipse.osee.orcs.db/OSGI-INF/convert.type.ids.xml9
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseConflictAccessor.java26
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/OseeInfoDataAccessor.java11
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/InvalidTxCurrentsAndModTypesCallable.java46
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/OrcsTypeLoaderCallable.java28
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/ChangeItemLoader.java20
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenBranches.java52
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenTxsOnTheSameBranch.java78
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/ConvertLocalTypeIdCommand.java130
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/IdTranslator.java14
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/SavePointManager.java20
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/export/DbTableExportItem.java137
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderImpl.java4
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java10
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/ArtifactQueryContextLoadExecutor.java28
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java18
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/callable/producer/IndexBranchesDatabaseCallable.java42
-rw-r--r--plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/data/GammaQueueIndexerDataSourceLoader.java38
34 files changed, 403 insertions, 752 deletions
diff --git a/plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java b/plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java
index 35116d1ee78..7e1d91e5565 100644
--- a/plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java
+++ b/plugins/org.eclipse.osee.framework.access/src/org/eclipse/osee/framework/access/internal/AccessControlService.java
@@ -25,6 +25,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Consumer;
import java.util.logging.Level;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -73,8 +74,8 @@ import org.eclipse.osee.framework.skynet.core.event.filter.IEventFilter;
import org.eclipse.osee.framework.skynet.core.event.listener.EventQosType;
import org.eclipse.osee.framework.skynet.core.event.listener.IArtifactEventListener;
import org.eclipse.osee.framework.skynet.core.event.model.AccessArtifactLockTopicEvent;
-import org.eclipse.osee.framework.skynet.core.event.model.AccessTopicEventPayload;
import org.eclipse.osee.framework.skynet.core.event.model.AccessTopicEvent;
+import org.eclipse.osee.framework.skynet.core.event.model.AccessTopicEventPayload;
import org.eclipse.osee.framework.skynet.core.event.model.ArtifactEvent;
import org.eclipse.osee.framework.skynet.core.event.model.Sender;
import org.eclipse.osee.framework.skynet.core.utility.DbUtil;
@@ -213,80 +214,61 @@ public class AccessControlService implements IAccessControlService {
private void populateBranchAccessControlList() throws OseeCoreException {
ensurePopulated();
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- chStmt.runPreparedQuery(GET_ALL_BRANCH_ACCESS_CONTROL_LIST);
- while (chStmt.next()) {
- Integer subjectId = chStmt.getInt("privilege_entity_id");
- Long branchUuid = chStmt.getLong("branch_id");
- Long subjectArtifactTypeId = chStmt.getLong("art_type_id");
- PermissionEnum permission = PermissionEnum.getPermission(chStmt.getInt("permission_id"));
- BranchAccessObject branchAccessObject = BranchAccessObject.getBranchAccessObject(branchUuid);
-
- accessControlListCache.put(subjectId, branchAccessObject, permission);
- objectToSubjectCache.put(branchAccessObject, subjectId);
-
- ArtifactType subjectArtifactType = getArtifactTypeCache().getById(subjectArtifactTypeId);
- if (subjectArtifactType != null && subjectArtifactType.inheritsFrom(CoreArtifactTypes.UserGroup)) {
- populateGroupMembers(subjectId);
- }
+ Consumer<JdbcStatement> consumer = stmt -> {
+ Integer subjectId = stmt.getInt("privilege_entity_id");
+ Long branchUuid = stmt.getLong("branch_id");
+ Long subjectArtifactTypeId = stmt.getLong("art_type_id");
+ PermissionEnum permission = PermissionEnum.getPermission(stmt.getInt("permission_id"));
+ BranchAccessObject branchAccessObject = BranchAccessObject.getBranchAccessObject(branchUuid);
+
+ accessControlListCache.put(subjectId, branchAccessObject, permission);
+ objectToSubjectCache.put(branchAccessObject, subjectId);
+
+ ArtifactType subjectArtifactType = getArtifactTypeCache().getById(subjectArtifactTypeId);
+ if (subjectArtifactType != null && subjectArtifactType.inheritsFrom(CoreArtifactTypes.UserGroup)) {
+ populateGroupMembers(subjectId);
}
- } finally {
- chStmt.close();
- }
+ };
+ getJdbcClient().runQuery(consumer, GET_ALL_BRANCH_ACCESS_CONTROL_LIST);
}
private void populateArtifactAccessControlList() throws OseeCoreException {
ensurePopulated();
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- chStmt.runPreparedQuery(GET_ALL_ARTIFACT_ACCESS_CONTROL_LIST);
-
- while (chStmt.next()) {
- Integer subjectId = chStmt.getInt("privilege_entity_id");
- Integer objectId = chStmt.getInt("art_id");
- Long branchUuid = chStmt.getLong("branch_id");
- Long subjectArtifactTypeId = chStmt.getLong("art_type_id");
- PermissionEnum permission = PermissionEnum.getPermission(chStmt.getInt("permission_id"));
-
- if (permission != null) {
- if (permission.equals(PermissionEnum.LOCK)) {
- artifactLockCache.put(branchUuid, objectId, subjectId);
- } else {
- AccessObject accessObject =
- ArtifactAccessObject.getArtifactAccessObject(objectId, TokenFactory.createBranch(branchUuid));
- cacheAccessObject(objectId, subjectId, permission, accessObject);
-
- ArtifactType subjectArtifactType = getArtifactTypeCache().getById(subjectArtifactTypeId);
- if (subjectArtifactType != null && subjectArtifactType.inheritsFrom(CoreArtifactTypes.UserGroup)) {
- populateGroupMembers(subjectId);
- }
+
+ Consumer<JdbcStatement> consumer = stmt -> {
+ Integer subjectId = stmt.getInt("privilege_entity_id");
+ Integer objectId = stmt.getInt("art_id");
+ Long branchUuid = stmt.getLong("branch_id");
+ Long subjectArtifactTypeId = stmt.getLong("art_type_id");
+ PermissionEnum permission = PermissionEnum.getPermission(stmt.getInt("permission_id"));
+
+ if (permission != null) {
+ if (permission.equals(PermissionEnum.LOCK)) {
+ artifactLockCache.put(branchUuid, objectId, subjectId);
+ } else {
+ AccessObject accessObject =
+ ArtifactAccessObject.getArtifactAccessObject(objectId, TokenFactory.createBranch(branchUuid));
+ cacheAccessObject(objectId, subjectId, permission, accessObject);
+
+ ArtifactType subjectArtifactType = getArtifactTypeCache().getById(subjectArtifactTypeId);
+ if (subjectArtifactType != null && subjectArtifactType.inheritsFrom(CoreArtifactTypes.UserGroup)) {
+ populateGroupMembers(subjectId);
}
}
}
- } finally {
- chStmt.close();
- }
+ };
+
+ getJdbcClient().runQuery(consumer, GET_ALL_ARTIFACT_ACCESS_CONTROL_LIST);
}
private void populateGroupMembers(Integer groupId) throws OseeCoreException {
ensurePopulated();
if (!groupToSubjectsCache.containsKey(groupId)) {
- Integer groupMember;
-
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- chStmt.runPreparedQuery(USER_GROUP_MEMBERS, groupId, CoreRelationTypes.Users_User.getGuid());
-
- // get group members and populate subjectToGroupCache
- while (chStmt.next()) {
- groupMember = chStmt.getInt("b_art_id");
- subjectToGroupCache.put(groupMember, groupId);
- groupToSubjectsCache.put(groupId, groupMember);
- }
- } finally {
- chStmt.close();
- }
+ getJdbcClient().runQuery(stmt -> {
+ Integer groupMember = stmt.getInt("b_art_id");
+ subjectToGroupCache.put(groupMember, groupId);
+ groupToSubjectsCache.put(groupId, groupMember);
+ } , USER_GROUP_MEMBERS, groupId, CoreRelationTypes.Users_User.getGuid());
}
}
@@ -675,7 +657,7 @@ public class AccessControlService implements IAccessControlService {
if (isArtifact) {
event.addArtifact(((ArtifactAccessObject) accessControlledObject).getArtId());
}
-
+
OseeEventManager.kickAccessTopicEvent(this, event, AccessTopicEvent.ACCESS_ARTIFACT_MODIFIED);
}
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 6cff0cb704f..b27a397db9d 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
@@ -56,7 +56,7 @@ public class MockOseeTransactionDataAccessor implements ITransactionDataAccessor
// }
@Override
- public void loadTransactionRecord(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException {
+ public void loadTransactionRecords(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException {
wasLoadCalled = true;
}
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 6de12ef1de2..1955d5515a4 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
@@ -24,15 +24,15 @@ public interface ITransactionDataAccessor {
/**
* Loads a specific set of transaction records
- *
+ *
* @param cache to populate
* @param transaction ids to load
*/
- public void loadTransactionRecord(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException;
+ public void loadTransactionRecords(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException;
/**
* Load a specific branch transaction type
- *
+ *
* @see {@link TransactionVersion}
* @param cache to populate
* @param branch to load
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 f16e389323d..0408054d351 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
@@ -156,7 +156,7 @@ public class TransactionCache implements IOseeLoadingCache<TransactionRecord> {
}
if (!toLoad.isEmpty()) {
- accessor.loadTransactionRecord(this, toLoad);
+ accessor.loadTransactionRecords(this, toLoad);
}
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java
index 466d5be49f3..53b17bed2eb 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.framework.core.server.internal.session;
import java.util.Date;
import java.util.Random;
+import java.util.function.Consumer;
import org.eclipse.osee.framework.core.server.internal.util.CharJoinQuery;
import org.eclipse.osee.framework.core.server.internal.util.DatabaseJoinAccessor;
import org.eclipse.osee.framework.core.server.internal.util.IJoinAccessor;
@@ -63,23 +64,18 @@ public final class DatabaseSessionQuery implements ISessionQuery {
}
private void querySessions(ISessionCollector collector, String sql, Object... params) throws OseeCoreException {
- JdbcStatement chStmt = jdbcClient.getStatement();
- try {
- chStmt.runPreparedQuery(sql, params);
- while (chStmt.next()) {
- String sessionGuid = chStmt.getString("session_id");
- String userId = chStmt.getString("user_id");
- Date creationDate = chStmt.getTimestamp("created_on");
- String clientVersion = chStmt.getString("client_version");
- String clientMachineName = chStmt.getString("client_machine_name");
- String clientAddress = chStmt.getString("client_address");
- int clientPort = chStmt.getInt("client_port");
- collector.collect(sessionGuid, userId, creationDate, clientVersion, clientMachineName, clientAddress,
- clientPort);
- }
- } finally {
- chStmt.close();
- }
+ Consumer<JdbcStatement> consumer = stmt -> {
+ String sessionGuid = stmt.getString("session_id");
+ String userId = stmt.getString("user_id");
+ Date creationDate = stmt.getTimestamp("created_on");
+ String clientVersion = stmt.getString("client_version");
+ String clientMachineName = stmt.getString("client_machine_name");
+ String clientAddress = stmt.getString("client_address");
+ int clientPort = stmt.getInt("client_port");
+ collector.collect(sessionGuid, userId, creationDate, clientVersion, clientMachineName, clientAddress,
+ clientPort);
+ };
+ jdbcClient.runQuery(consumer, sql, params);
}
private int getNewQueryId() {
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeAttributes.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeAttributes.java
index 4c0022727a7..93fa2308af0 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeAttributes.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/PurgeAttributes.java
@@ -27,7 +27,6 @@ import org.eclipse.osee.framework.skynet.core.utility.IdJoinQuery;
import org.eclipse.osee.framework.skynet.core.utility.JoinUtility;
import org.eclipse.osee.jdbc.JdbcConnection;
import org.eclipse.osee.jdbc.JdbcConstants;
-import org.eclipse.osee.jdbc.JdbcStatement;
/**
* @author Jeff C. Phillips
@@ -78,17 +77,9 @@ public class PurgeAttributes extends AbstractDbTxOperation {
IdJoinQuery txsJoin = JoinUtility.createIdJoinQuery(getJdbcClient());
try {
attributeJoin.store();
- JdbcStatement chStmt = getJdbcClient().getStatement();
-
- try {
- chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, SELECT_ATTR_GAMMAS, attributeJoin.getQueryId());
- while (chStmt.next()) {
- txsJoin.add(chStmt.getInt("gamma_id"));
- }
- txsJoin.store();
- } finally {
- chStmt.close();
- }
+ getJdbcClient().runQuery(stmt -> txsJoin.add(stmt.getInt("gamma_id")), JdbcConstants.JDBC__MAX_FETCH_SIZE,
+ SELECT_ATTR_GAMMAS, attributeJoin.getQueryId());
+ txsJoin.store();
} finally {
attributeJoin.delete();
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/UpdateMergeBranch.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/UpdateMergeBranch.java
index d08522157f6..9cb1807ed48 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/UpdateMergeBranch.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/artifact/UpdateMergeBranch.java
@@ -31,7 +31,6 @@ import org.eclipse.osee.framework.skynet.core.utility.ArtifactJoinQuery;
import org.eclipse.osee.framework.skynet.core.utility.JoinUtility;
import org.eclipse.osee.jdbc.JdbcClient;
import org.eclipse.osee.jdbc.JdbcConnection;
-import org.eclipse.osee.jdbc.JdbcStatement;
/**
* @author Theron Virgin
@@ -187,48 +186,18 @@ public class UpdateMergeBranch extends AbstractDbTxOperation {
private Collection<Integer> getAllMergeArtifacts(BranchId branch) throws OseeCoreException {
Collection<Integer> artSet = new HashSet<>();
- long time = System.currentTimeMillis();
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.MERGE_GET_ARTIFACTS_FOR_BRANCH), branch.getUuid());
- while (chStmt.next()) {
- artSet.add(chStmt.getInt("art_id"));
- }
- if (DEBUG) {
- System.out.println(String.format(" Getting Artifacts that are on the Merge Branch Completed in %s",
- Lib.getElapseString(time)));
- time = System.currentTimeMillis();
- }
+ getJdbcClient().runQuery(stmt -> artSet.add(stmt.getInt("art_id")),
+ ServiceUtil.getSql(OseeSql.MERGE_GET_ARTIFACTS_FOR_BRANCH), branch.getUuid());
- chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.MERGE_GET_ATTRIBUTES_FOR_BRANCH), branch.getUuid());
- while (chStmt.next()) {
- artSet.add(chStmt.getInt("art_id"));
- }
- if (DEBUG) {
- System.out.println(String.format(
- " Getting Attributes that are on the Merge Branch Completed in %s", Lib.getElapseString(time)));
- time = System.currentTimeMillis();
- }
+ getJdbcClient().runQuery(stmt -> artSet.add(stmt.getInt("art_id")),
+ ServiceUtil.getSql(OseeSql.MERGE_GET_ATTRIBUTES_FOR_BRANCH), branch.getUuid());
+
+ getJdbcClient().runQuery(stmt -> {
+ artSet.add(stmt.getInt("a_art_id"));
+ artSet.add(stmt.getInt("b_art_id"));
+ } , ServiceUtil.getSql(OseeSql.MERGE_GET_RELATIONS_FOR_BRANCH), branch.getUuid());
- chStmt.runPreparedQuery(ServiceUtil.getSql(OseeSql.MERGE_GET_RELATIONS_FOR_BRANCH), branch.getUuid());
- while (chStmt.next()) {
- artSet.add(chStmt.getInt("a_art_id"));
- artSet.add(chStmt.getInt("b_art_id"));
- }
- } finally {
- chStmt.close();
- }
- if (DEBUG) {
- System.out.println(String.format(" Getting Relations that are on the Merge Branch Completed in %s",
- Lib.getElapseString(time)));
- System.out.println(" Found the following Artifacts on the Merge Branch");
- System.out.print(" ");
- for (Integer integer : artSet) {
- System.out.print(integer + ", ");
- }
- System.out.print("\n");
- }
return artSet;
}
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java
index dc5f65c89df..1a1e289258a 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/ClientCachingServiceProxy.java
@@ -73,7 +73,7 @@ public class ClientCachingServiceProxy implements IOseeCachingService {
JdbcClient jdbcClient = jdbcService.getClient();
txCache = new TransactionCache();
- txCache.setAccessor(new DatabaseTransactionRecordAccessor(jdbcClient, new TransactionRecordFactory()));
+ txCache.setAccessor(new DatabaseTransactionRecordAccessor(jdbcClient, txCache, new TransactionRecordFactory()));
branchCache = new BranchCache(new DatabaseBranchAccessor(jdbcClient, txCache), txCache);
artifactTypeCache = new ArtifactTypeCache();
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java
index 34f8de608aa..29f9a0b6f35 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseBranchAccessor.java
@@ -8,6 +8,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.function.Consumer;
import java.util.logging.Level;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.osee.framework.core.enums.BranchArchivedState;
@@ -80,7 +81,7 @@ public class DatabaseBranchAccessor implements IOseeDataAccessor<Branch> {
}
branchToSourceTx.put(branch, stmt.getInt("parent_transaction_id"));
branchToBaseTx.put(branch, stmt.getInt("baseline_transaction_id"));
- }, JDBC__MAX_FETCH_SIZE, SELECT_BRANCHES);
+ } , JDBC__MAX_FETCH_SIZE, SELECT_BRANCHES);
}
private static Branch create(Long branchId, String name, BranchType branchType, BranchState branchState, boolean isArchived, boolean inheritAccessControl) throws OseeCoreException {
@@ -179,21 +180,15 @@ public class DatabaseBranchAccessor implements IOseeDataAccessor<Branch> {
}
private void loadMergeBranches(IOseeCache<Branch> cache) throws OseeCoreException {
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- chStmt.runPreparedQuery(1000, SELECT_MERGE_BRANCHES);
- while (chStmt.next()) {
- Branch sourceBranch = cache.getById(chStmt.getLong("source_branch_id"));
- Branch destBranch = cache.getById(chStmt.getLong("dest_branch_id"));
-
- MergeBranch mergeBranch = (MergeBranch) cache.getById(chStmt.getLong("merge_branch_id"));
- mergeBranch.setSourceBranch(sourceBranch);
- mergeBranch.setDestinationBranch(destBranch);
- }
- } finally {
- chStmt.close();
- }
-
+ Consumer<JdbcStatement> consumer = stmt -> {
+ Branch sourceBranch = cache.getById(stmt.getLong("source_branch_id"));
+ Branch destBranch = cache.getById(stmt.getLong("dest_branch_id"));
+ MergeBranch mergeBranch = (MergeBranch) cache.getById(stmt.getLong("merge_branch_id"));
+
+ mergeBranch.setSourceBranch(sourceBranch);
+ mergeBranch.setDestinationBranch(destBranch);
+ };
+ getJdbcClient().runQuery(consumer, 1000, SELECT_MERGE_BRANCHES);
}
@Override
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java
index d8f18dce076..ce7d34d8037 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/internal/accessors/DatabaseTransactionRecordAccessor.java
@@ -12,7 +12,6 @@ import org.eclipse.osee.framework.core.model.TransactionRecordFactory;
import org.eclipse.osee.framework.core.model.cache.ITransactionDataAccessor;
import org.eclipse.osee.framework.core.model.cache.TransactionCache;
import org.eclipse.osee.framework.core.sql.OseeSql;
-import org.eclipse.osee.framework.jdk.core.type.MutableInteger;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
@@ -46,14 +45,16 @@ public class DatabaseTransactionRecordAccessor implements ITransactionDataAccess
private final JdbcClient jdbcClient;
private final TransactionRecordFactory factory;
+ private final TransactionCache cache;
- public DatabaseTransactionRecordAccessor(JdbcClient jdbcClient, TransactionRecordFactory factory) {
+ public DatabaseTransactionRecordAccessor(JdbcClient jdbcClient, TransactionCache cache, TransactionRecordFactory factory) {
+ this.cache = cache;
this.jdbcClient = jdbcClient;
this.factory = factory;
}
@Override
- public void loadTransactionRecord(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException {
+ public void loadTransactionRecords(TransactionCache cache, Collection<Integer> transactionIds) throws OseeCoreException {
if (transactionIds.isEmpty()) {
return;
}
@@ -65,13 +66,13 @@ public class DatabaseTransactionRecordAccessor implements ITransactionDataAccess
}
joinQuery.store();
- loadTransactions(cache, transactionIds.size(), SELECT_TRANSACTIONS_BY_QUERY_ID, joinQuery.getQueryId());
+ loadTransactions(transactionIds.size(), SELECT_TRANSACTIONS_BY_QUERY_ID, joinQuery.getQueryId());
} finally {
joinQuery.delete();
}
} else {
- loadTransaction(cache, SELECT_BY_TRANSACTION, transactionIds.iterator().next());
+ loadTransaction(SELECT_BY_TRANSACTION, transactionIds.iterator().next());
}
}
@@ -80,11 +81,10 @@ public class DatabaseTransactionRecordAccessor implements ITransactionDataAccess
TransactionRecord toReturn = null;
switch (transactionType) {
case BASE:
- toReturn =
- loadTransaction(cache, SELECT_BASE_TRANSACTION, branch.getUuid(), TransactionDetailsType.Baselined);
+ toReturn = loadTransaction(SELECT_BASE_TRANSACTION, branch.getUuid(), TransactionDetailsType.Baselined);
break;
case HEAD:
- toReturn = loadTransaction(cache, SELECT_HEAD_TRANSACTION, branch.getUuid(), branch.getUuid());
+ toReturn = loadTransaction(SELECT_HEAD_TRANSACTION, branch.getUuid(), branch.getUuid());
break;
default:
throw new OseeStateException("Transaction Type [%s] is not supported", transactionType);
@@ -92,52 +92,24 @@ public class DatabaseTransactionRecordAccessor implements ITransactionDataAccess
return toReturn;
}
- 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) {
- JdbcStatement chStmt = jdbcClient.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 TransactionRecord loadInternalTransaction(JdbcStatement stmt) {
+ IOseeBranch branch = BranchManager.getBranch(stmt.getLong("branch_id"));
+ int transactionNumber = stmt.getInt("transaction_id");
+ String comment = stmt.getString("osee_comment");
+ Date timestamp = stmt.getTimestamp("time");
+ int authorArtId = stmt.getInt("author");
+ int commitArtId = stmt.getInt("commit_art_id");
+ TransactionDetailsType txType = TransactionDetailsType.toEnum(stmt.getInt("tx_type"));
+ return factory.createOrUpdate(cache, transactionNumber, branch, comment, timestamp, authorArtId, commitArtId,
+ txType);
}
- private TransactionRecord loadTransaction(TransactionCache cache, String query, Object... parameters) throws OseeCoreException {
- return loadFromTransaction(cache, 1, new MutableInteger(0), query, parameters);
+ private void loadTransactions(int expectedCount, String query, int queryId) throws OseeCoreException {
+ jdbcClient.runQuery(this::loadInternalTransaction, query, queryId);
}
- private TransactionRecord loadFromTransaction(TransactionCache cache, int expectedCount, MutableInteger numberLoaded, String query, Object... parameters) throws OseeCoreException {
- JdbcStatement chStmt = jdbcClient.getStatement();
- TransactionRecord record = null;
- int count = 0;
- try {
- chStmt.runPreparedQuery(expectedCount, query, parameters);
- while (chStmt.next()) {
- count++;
- IOseeBranch branch = BranchManager.getBranch(chStmt.getLong("branch_id"));
- int transactionNumber = chStmt.getInt("transaction_id");
- String comment = chStmt.getString("osee_comment");
- Date timestamp = chStmt.getTimestamp("time");
- int authorArtId = chStmt.getInt("author");
- int commitArtId = chStmt.getInt("commit_art_id");
- TransactionDetailsType txType = TransactionDetailsType.toEnum(chStmt.getInt("tx_type"));
-
- record = factory.createOrUpdate(cache, transactionNumber, branch, comment, timestamp, authorArtId,
- commitArtId, txType);
- }
- numberLoaded.setValue(count);
- } finally {
- chStmt.close();
- }
- return record;
+ private TransactionRecord loadTransaction(String query, Object... parameters) throws OseeCoreException {
+ return jdbcClient.fetchObject(null, this::loadInternalTransaction, query, parameters);
}
@Override
diff --git a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/utility/InvalidTxCurrentsAndModTypes.java b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/utility/InvalidTxCurrentsAndModTypes.java
index b8a566c5873..5eecee65aa6 100644
--- a/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/utility/InvalidTxCurrentsAndModTypes.java
+++ b/plugins/org.eclipse.osee.framework.skynet.core/src/org/eclipse/osee/framework/skynet/core/utility/InvalidTxCurrentsAndModTypes.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.framework.skynet.core.utility;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Consumer;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.data.ApplicabilityId;
import org.eclipse.osee.framework.core.enums.ModificationType;
@@ -49,15 +50,10 @@ public class InvalidTxCurrentsAndModTypes extends AbstractOperation {
private final JdbcClient jdbcClient;
public InvalidTxCurrentsAndModTypes(String operationName, String tableName, String columnName, OperationLogger logger, boolean isFixOperationEnabled, boolean archived) throws OseeDataStoreException {
- this(ConnectionHandler.getJdbcClient(), operationName, tableName, columnName, logger, isFixOperationEnabled,
- archived);
- }
-
- private InvalidTxCurrentsAndModTypes(JdbcClient jdbcClient, String operationName, String tableName, String columnName, OperationLogger logger, boolean isFixOperationEnabled, boolean archived) {
super(
"InvalidTxCurrentsAndModTypes " + operationName + tableName + " fix:" + isFixOperationEnabled + " archived:" + archived,
Activator.PLUGIN_ID, logger);
- this.jdbcClient = jdbcClient;
+ this.jdbcClient = ConnectionHandler.getJdbcClient();
this.tableName = tableName;
this.columnName = columnName;
this.isFixOperationEnabled = isFixOperationEnabled;
@@ -179,40 +175,32 @@ public class InvalidTxCurrentsAndModTypes extends AbstractOperation {
log("Starting " + getName());
checkForCancelledStatus(monitor);
-
- JdbcStatement chStmt = getJdbcClient().getStatement();
String sql = String.format(SELECT_ADDRESSES, columnName, tableName, txsTableName, columnName);
- try {
- chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, sql);
- monitor.worked(calculateWork(0.40));
-
- Address previousAddress = null;
- while (chStmt.next()) {
- checkForCancelledStatus(monitor);
- ModificationType modType = ModificationType.getMod(chStmt.getInt("mod_type"));
- TxChange txCurrent = TxChange.getChangeType(chStmt.getInt("tx_current"));
- TransactionDetailsType type = TransactionDetailsType.toEnum(chStmt.getInt("tx_type"));
- ApplicabilityId appId = ApplicabilityId.valueOf(chStmt.getLong("app_id"));
- Address address = new Address(type.isBaseline(), chStmt.getLong("branch_id"), chStmt.getInt(columnName),
- chStmt.getInt("transaction_id"), chStmt.getLong("gamma_id"), modType, appId, txCurrent);
-
- if (!address.isSimilar(previousAddress)) {
- if (!addresses.isEmpty()) {
- consolidateAddressing();
- }
- addresses.clear();
- }
+ monitor.worked(calculateWork(0.40));
+ Address[] previousAddress = new Address[1];
- addresses.add(address);
- previousAddress = address;
+ Consumer<JdbcStatement> consumer = stmt -> {
+ checkForCancelledStatus(monitor);
+ ModificationType modType = ModificationType.getMod(stmt.getInt("mod_type"));
+ TxChange txCurrent = TxChange.getChangeType(stmt.getInt("tx_current"));
+ TransactionDetailsType type = TransactionDetailsType.toEnum(stmt.getInt("tx_type"));
+ ApplicabilityId appId = ApplicabilityId.valueOf(stmt.getLong("app_id"));
+ Address address = new Address(type.isBaseline(), stmt.getLong("branch_id"), stmt.getInt(columnName),
+ stmt.getInt("transaction_id"), stmt.getLong("gamma_id"), modType, appId, txCurrent);
+
+ if (!address.isSimilar(previousAddress[0])) {
+ if (!addresses.isEmpty()) {
+ consolidateAddressing();
+ }
+ addresses.clear();
}
- monitor.worked(calculateWork(0.5));
- } finally {
- chStmt.close();
- }
+ addresses.add(address);
+ previousAddress[0] = address;
+ };
+ getJdbcClient().runQuery(consumer, JdbcConstants.JDBC__MAX_FETCH_SIZE, sql);
+ monitor.worked(calculateWork(0.5));
fixIssues(monitor);
-
log("Completed " + getName());
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/database/AbstractDatabaseStorage.java b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/database/AbstractDatabaseStorage.java
index 871198b53fa..21f219d6df6 100644
--- a/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/database/AbstractDatabaseStorage.java
+++ b/plugins/org.eclipse.osee.jaxrs.server/src/org/eclipse/osee/jaxrs/server/database/AbstractDatabaseStorage.java
@@ -100,16 +100,10 @@ public abstract class AbstractDatabaseStorage<T> {
@Override
protected ResultSet<T> innerCall() throws Exception {
List<T> list = new LinkedList<>();
- JdbcStatement chStmt = jdbcClient.getStatement();
- try {
- chStmt.runPreparedQuery(query, data);
- while (chStmt.next()) {
- T data = readData(chStmt);
- list.add(data);
- }
- } finally {
- chStmt.close();
- }
+ getJdbcClient().runQuery(stmt -> {
+ T data = readData(stmt);
+ list.add(data);
+ } , query, data);
return ResultSets.newResultSet(list);
}
};
diff --git a/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/JdbcClient.java b/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/JdbcClient.java
index 8873ce4e856..4fd1f44a125 100644
--- a/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/JdbcClient.java
+++ b/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/JdbcClient.java
@@ -28,9 +28,9 @@ public interface JdbcClient {
JdbcStatement getStatement(int resultSetType, int resultSetConcurrency);
- void runQuery(Consumer<JdbcStatement> consumer, String query, Object... data);
+ int runQuery(Consumer<JdbcStatement> consumer, String query, Object... data);
- void runQuery(Consumer<JdbcStatement> consumer, int fetchSize, String query, Object... data);
+ int runQuery(Consumer<JdbcStatement> consumer, int fetchSize, String query, Object... data);
<R> R fetchObject(R defaultValue, Function<JdbcStatement, R> function, String query, Object... data);
diff --git a/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/JdbcClientImpl.java b/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/JdbcClientImpl.java
index d900532090a..dcb4ed9b92b 100644
--- a/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/JdbcClientImpl.java
+++ b/plugins/org.eclipse.osee.jdbc/src/org/eclipse/osee/jdbc/internal/JdbcClientImpl.java
@@ -363,18 +363,21 @@ public final class JdbcClientImpl implements JdbcClient {
}
@Override
- public void runQuery(Consumer<JdbcStatement> consumer, String query, Object... data) {
- runQuery(consumer, 0, query, data);
+ public int runQuery(Consumer<JdbcStatement> consumer, String query, Object... data) {
+ return runQuery(consumer, 0, query, data);
}
@Override
- public void runQuery(Consumer<JdbcStatement> consumer, int fetchSize, String query, Object... data) {
+ public int runQuery(Consumer<JdbcStatement> consumer, int fetchSize, String query, Object... data) {
+ int rowCount = 0;
try (JdbcStatement stmt = getStatement()) {
stmt.runPreparedQuery(fetchSize, query, data);
while (stmt.next()) {
consumer.accept(stmt);
+ rowCount++;
}
}
+ return rowCount;
}
@Override
diff --git a/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSessionDatabaseStore.java b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSessionDatabaseStore.java
index 661d56f407f..2d8c91fe77c 100644
--- a/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSessionDatabaseStore.java
+++ b/plugins/org.eclipse.osee.orcs.account.admin/src/org/eclipse/osee/orcs/account/admin/internal/AccountSessionDatabaseStore.java
@@ -15,6 +15,7 @@ import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
+import java.util.function.Consumer;
import org.eclipse.osee.account.admin.AccountSession;
import org.eclipse.osee.executor.admin.CancellableCallable;
import org.eclipse.osee.framework.core.data.ArtifactId;
@@ -87,24 +88,19 @@ public class AccountSessionDatabaseStore implements AccountSessionStorage {
@Override
protected ResultSet<AccountSession> innerCall() throws Exception {
List<AccountSession> list = new LinkedList<>();
- JdbcStatement chStmt = jdbcClient.getStatement();
- try {
- chStmt.runPreparedQuery(query, data);
- while (chStmt.next()) {
- long accountId = chStmt.getLong("account_id");
- String sessionToken = chStmt.getString("session_token");
- Date createdOn = chStmt.getTimestamp("created_on");
- Date lastAccessedOn = chStmt.getTimestamp("last_accessed_on");
- String accessedFrom = chStmt.getString("accessed_from");
- String accessDetails = chStmt.getString("access_details");
+ Consumer<JdbcStatement> consumer = stmt -> {
+ long accountId = stmt.getLong("account_id");
+ String sessionToken = stmt.getString("session_token");
+ Date createdOn = stmt.getTimestamp("created_on");
+ Date lastAccessedOn = stmt.getTimestamp("last_accessed_on");
+ String accessedFrom = stmt.getString("accessed_from");
+ String accessDetails = stmt.getString("access_details");
ArtifactId artId = ArtifactId.valueOf(accountId);
- AccountSession session = factory.newAccountSession(artId, sessionToken, createdOn, lastAccessedOn,
- accessedFrom, accessDetails);
- list.add(session);
- }
- } finally {
- chStmt.close();
- }
+ AccountSession session = factory.newAccountSession(artId, sessionToken, createdOn, lastAccessedOn,
+ accessedFrom, accessDetails);
+ list.add(session);
+ };
+ jdbcClient.runQuery(consumer, query, data);
return ResultSets.newResultSet(list);
}
};
diff --git a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java
index d9612a2c206..3449192bcee 100644
--- a/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java
+++ b/plugins/org.eclipse.osee.orcs.db.test/src/org/eclipse/osee/orcs/db/intergration/PurgeAttributeTest.java
@@ -40,7 +40,6 @@ public class PurgeAttributeTest {
@Test
public void testPurgeAttribute() throws Exception {
JdbcClient jdbcClient = jdbcService.getClient();
- JdbcStatement stmt = jdbcClient.getStatement();
int prePurgeAttributeCount = getCount(jdbcClient, "osee_attribute");
int preAttributeRows = getCount(jdbcClient, "osee_attribute where value = 'Software Requirements'");
@@ -49,11 +48,9 @@ public class PurgeAttributeTest {
int prePurgeTxsCount = getCount(jdbcClient, "osee_txs");
- stmt.runPreparedQuery("select attr_id from osee_attribute where value = 'Software Requirements'");
List<Long> toPurge = new LinkedList<>();
- while (stmt.next()) {
- toPurge.add(stmt.getLong("attr_id"));
- }
+ jdbcClient.runQuery(stmt -> toPurge.add(stmt.getLong("attr_id")),
+ "select attr_id from osee_attribute where value = 'Software Requirements'");
PurgeAttributesDatabaseTxCallable callable =
new PurgeAttributesDatabaseTxCallable(null, null, jdbcClient, sqlJoinFactory, toPurge, null);
@@ -71,11 +68,12 @@ public class PurgeAttributeTest {
}
private int getCount(JdbcClient jdbcClient, String table) {
- JdbcStatement stmt = jdbcClient.getStatement();
int toReturn = -1;
- stmt.runPreparedQuery("select count(1) from " + table);
- while (stmt.next()) {
- toReturn = stmt.getInt(1);
+ try (JdbcStatement chStmt = jdbcClient.getStatement()) {
+ chStmt.runPreparedQuery("select count(1) from " + table);
+ while (chStmt.next()) {
+ toReturn = chStmt.getInt(1);
+ }
}
return toReturn;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/convert.type.ids.xml b/plugins/org.eclipse.osee.orcs.db/OSGI-INF/convert.type.ids.xml
deleted file mode 100644
index db47463ba96..00000000000
--- a/plugins/org.eclipse.osee.orcs.db/OSGI-INF/convert.type.ids.xml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
- <implementation class="org.eclipse.osee.orcs.db.internal.console.ConvertLocalTypeIdCommand"/>
- <service>
- <provide interface="org.eclipse.osee.console.admin.ConsoleCommand"/>
- </service>
- <reference bind="setLogger" cardinality="1..1" interface="org.eclipse.osee.logger.Log" name="Log" policy="static"/>
- <reference bind="setJdbcService" cardinality="1..1" interface="org.eclipse.osee.jdbc.JdbcService" name="JdbcService" policy="static" target="(osgi.binding=orcs.jdbc.service)"/>
-</scr:component>
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseConflictAccessor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseConflictAccessor.java
index e7710d54a0b..da55134acc1 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseConflictAccessor.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/DatabaseConflictAccessor.java
@@ -14,6 +14,7 @@ package org.eclipse.osee.orcs.db.internal.accessor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.function.Consumer;
import org.eclipse.osee.framework.core.enums.ConflictStatus;
import org.eclipse.osee.framework.core.enums.ConflictType;
import org.eclipse.osee.framework.core.enums.StorageState;
@@ -48,21 +49,16 @@ public class DatabaseConflictAccessor {
}
public void load(Collection<Conflict> conflicts, MergeBranch mergeBranch) throws OseeCoreException {
- JdbcStatement statement = getJdbcClient().getStatement();
- try {
- statement.runPreparedQuery(SELECT_CONFLICTS, mergeBranch.getUuid());
- while (statement.next()) {
- int uniqueId = statement.getInt("conflict_id");
- Long sourceGammaId = statement.getLong("source_gamma_id");
- Long destGammaId = statement.getLong("dest_gamma_id");
- ConflictType conflictType = ConflictType.valueOf(statement.getInt("conflict_type"));
- ConflictStatus status = ConflictStatus.valueOf(statement.getInt("status"));
- conflicts.add(new Conflict(StorageState.LOADED, uniqueId, conflictType, mergeBranch, status, sourceGammaId,
- destGammaId));
- }
- } finally {
- statement.close();
- }
+ Consumer<JdbcStatement> consumer = stmt -> {
+ int uniqueId = stmt.getInt("conflict_id");
+ Long sourceGammaId = stmt.getLong("source_gamma_id");
+ Long destGammaId = stmt.getLong("dest_gamma_id");
+ ConflictType conflictType = ConflictType.valueOf(stmt.getInt("conflict_type"));
+ ConflictStatus status = ConflictStatus.valueOf(stmt.getInt("status"));
+ conflicts.add(
+ new Conflict(StorageState.LOADED, uniqueId, conflictType, mergeBranch, status, sourceGammaId, destGammaId));
+ };
+ getJdbcClient().runQuery(consumer, SELECT_CONFLICTS, mergeBranch.getUuid());
}
public void store(Collection<Conflict> conflicts) throws OseeCoreException {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/OseeInfoDataAccessor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/OseeInfoDataAccessor.java
index e298081af11..05dce39cb6e 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/OseeInfoDataAccessor.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/accessor/OseeInfoDataAccessor.java
@@ -22,7 +22,6 @@ import org.eclipse.osee.jdbc.JdbcClient;
import org.eclipse.osee.jdbc.JdbcConnection;
import org.eclipse.osee.jdbc.JdbcDbType;
import org.eclipse.osee.jdbc.JdbcService;
-import org.eclipse.osee.jdbc.JdbcStatement;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.core.ds.DataStoreConstants;
import org.eclipse.osee.orcs.core.ds.KeyValueDataAccessor;
@@ -163,15 +162,7 @@ public class OseeInfoDataAccessor implements KeyValueDataAccessor {
@Override
public Set<String> getKeys() throws OseeCoreException {
Set<String> keys = new HashSet<>();
- JdbcStatement chStmt = jdbcClient.getStatement();
- try {
- chStmt.runPreparedQuery(GET_KEYS_SQL);
- while (chStmt.next()) {
- keys.add(chStmt.getString("osee_key"));
- }
- } finally {
- chStmt.close();
- }
+ jdbcClient.runQuery(stmt -> keys.add(stmt.getString("osee_key")), GET_KEYS_SQL);
return keys;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/InvalidTxCurrentsAndModTypesCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/InvalidTxCurrentsAndModTypesCallable.java
index a591826b342..4603c7422a2 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/InvalidTxCurrentsAndModTypesCallable.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/InvalidTxCurrentsAndModTypesCallable.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.orcs.db.internal.callable;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Consumer;
import org.eclipse.osee.framework.core.data.ApplicabilityId;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.enums.TransactionDetailsType;
@@ -159,34 +160,29 @@ public class InvalidTxCurrentsAndModTypesCallable extends AbstractDatastoreTxCal
protected Void handleTxWork(JdbcConnection connection) {
checkForCancelled();
- JdbcStatement chStmt = getJdbcClient().getStatement();
String sql = String.format(SELECT_ADDRESSES, columnName, tableName, txsTableName, columnName);
- try {
- chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, sql);
-
- Address previousAddress = null;
- while (chStmt.next()) {
- checkForCancelled();
- ModificationType modType = ModificationType.getMod(chStmt.getInt("mod_type"));
- TxChange txCurrent = TxChange.getChangeType(chStmt.getInt("tx_current"));
- TransactionDetailsType type = TransactionDetailsType.toEnum(chStmt.getInt("tx_type"));
- ApplicabilityId appId = ApplicabilityId.valueOf(chStmt.getLong("app_id"));
- Address address = new Address(type.isBaseline(), chStmt.getLong("branch_id"), chStmt.getInt(columnName),
- chStmt.getInt("transaction_id"), chStmt.getLong("gamma_id"), modType, appId, txCurrent);
-
- if (!address.isSimilar(previousAddress)) {
- if (!addresses.isEmpty()) {
- consolidateAddressing();
- }
- addresses.clear();
- }
+ Address[] previousAddress = new Address[1];
- addresses.add(address);
- previousAddress = address;
+ Consumer<JdbcStatement> consumer = stmt -> {
+ checkForCancelled();
+ ModificationType modType = ModificationType.getMod(stmt.getInt("mod_type"));
+ TxChange txCurrent = TxChange.getChangeType(stmt.getInt("tx_current"));
+ TransactionDetailsType type = TransactionDetailsType.toEnum(stmt.getInt("tx_type"));
+ ApplicabilityId appId = ApplicabilityId.valueOf(stmt.getLong("app_id"));
+ Address address = new Address(type.isBaseline(), stmt.getLong("branch_id"), stmt.getInt(columnName),
+ stmt.getInt("transaction_id"), stmt.getLong("gamma_id"), modType, appId, txCurrent);
+
+ if (!address.isSimilar(previousAddress[0])) {
+ if (!addresses.isEmpty()) {
+ consolidateAddressing();
+ }
+ addresses.clear();
}
- } finally {
- chStmt.close();
- }
+
+ addresses.add(address);
+ previousAddress[0] = address;
+ };
+ getJdbcClient().runQuery(consumer, JdbcConstants.JDBC__MAX_FETCH_SIZE, sql);
fixIssues();
return null;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/OrcsTypeLoaderCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/OrcsTypeLoaderCallable.java
index 8cdfba35d09..4ffe786baa2 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/OrcsTypeLoaderCallable.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/callable/OrcsTypeLoaderCallable.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.osee.orcs.db.internal.callable;
-import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
@@ -18,6 +17,9 @@ import java.net.URI;
import java.util.Collection;
import java.util.LinkedHashSet;
import org.eclipse.osee.framework.core.data.OrcsTypesData;
+import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
+import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
+import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.CoreTupleTypes;
import org.eclipse.osee.framework.core.enums.TxChange;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
@@ -29,7 +31,6 @@ import org.eclipse.osee.framework.resource.management.IResourceLocator;
import org.eclipse.osee.framework.resource.management.IResourceManager;
import org.eclipse.osee.framework.resource.management.StandardOptions;
import org.eclipse.osee.jdbc.JdbcClient;
-import org.eclipse.osee.jdbc.JdbcStatement;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsSession;
@@ -43,8 +44,8 @@ public class OrcsTypeLoaderCallable extends AbstractDatastoreCallable<IResource>
*/
private static final String LOAD_OSEE_TYPE_DEF_URIS =
"select uri from osee_tuple2 t2, osee_txs txs1, osee_attribute attr, osee_txs txs2 where tuple_type = ? and " //
- + "t2.gamma_id = txs1.gamma_id and txs1.branch_id = ? and txs1.tx_current = ? and e1 = ? and e2 = attr.attr_id and " //
- + "attr.gamma_id = txs2.gamma_id and txs2.branch_id = txs1.branch_id and txs2.tx_current = ?";
+ + "t2.gamma_id = txs1.gamma_id and txs1.branch_id = ? and txs1.tx_current = ? and e1 = ? and e2 = attr.attr_id and " //
+ + "attr.gamma_id = txs2.gamma_id and txs2.branch_id = txs1.branch_id and txs2.tx_current = ?";
private final IResourceManager resourceManager;
@@ -66,20 +67,11 @@ public class OrcsTypeLoaderCallable extends AbstractDatastoreCallable<IResource>
private Collection<String> findOseeTypeData() throws OseeCoreException {
Collection<String> paths = new LinkedHashSet<>();
- JdbcStatement chStmt = null;
- try {
- chStmt = getJdbcClient().getStatement();
-
- chStmt.runPreparedQuery(LOAD_OSEE_TYPE_DEF_URIS, CoreTupleTypes.OseeTypeDef, COMMON,
- TxChange.CURRENT.getValue(), OrcsTypesData.OSEE_TYPE_VERSION, TxChange.CURRENT.getValue());
-
- while (chStmt.next()) {
- String uri = chStmt.getString("uri");
- paths.add(uri);
- }
- } finally {
- Lib.close(chStmt);
- }
+ getJdbcClient().runQuery(stmt -> {
+ String uri = stmt.getString("uri");
+ paths.add(uri);
+ } , LOAD_OSEE_TYPE_DEF_URIS, CoreTupleTypes.OseeTypeDef, CoreBranches.COMMON,
+ TxChange.CURRENT.getValue(), OrcsTypesData.OSEE_TYPE_VERSION, TxChange.CURRENT.getValue());
return paths;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/ChangeItemLoader.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/ChangeItemLoader.java
index 303acb4242b..9f8416c7258 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/ChangeItemLoader.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/ChangeItemLoader.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.orcs.db.internal.change;
import java.util.HashMap;
import org.eclipse.osee.framework.core.data.ApplicabilityId;
+import java.util.function.Consumer;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.model.change.ChangeItem;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
@@ -60,17 +61,12 @@ public class ChangeItemLoader {
}
public void loadItemIdsBasedOnGammas(ChangeItemFactory factory, int queryId, HashMap<Integer, ChangeItem> changesByItemId, IdJoinQuery idJoin) throws OseeCoreException {
- JdbcStatement chStmt = jdbcClient.getStatement();
- try {
- chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, factory.getLoadByGammaQuery(), queryId);
- while (chStmt.next()) {
- ChangeItem item = factory.createItem(chStmt);
- Integer itemId = item.getItemId();
- changesByItemId.put(itemId, item);
- idJoin.add(itemId);
- }
- } finally {
- chStmt.close();
- }
+ Consumer<JdbcStatement> consumer = stmt -> {
+ ChangeItem item = factory.createItem(stmt);
+ Integer itemId = item.getItemId();
+ changesByItemId.put(itemId, item);
+ idJoin.add(itemId);
+ };
+ jdbcClient.runQuery(consumer, JdbcConstants.JDBC__MAX_FETCH_SIZE, factory.getLoadByGammaQuery(), queryId);
}
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenBranches.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenBranches.java
index ddbeba2aabe..283045003c0 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenBranches.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenBranches.java
@@ -14,6 +14,7 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.function.Consumer;
import org.eclipse.osee.framework.core.data.ApplicabilityId;
import org.eclipse.osee.framework.core.data.RelationalConstants;
import org.eclipse.osee.framework.core.enums.ModificationType;
@@ -102,23 +103,18 @@ public class LoadDeltasBetweenBranches extends AbstractDatastoreCallable<List<Ch
}
private void loadSourceBranchChanges(TransactionJoinQuery txJoin, int sourceBaselineTxId) throws OseeCoreException {
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, SELECT_SOURCE_BRANCH_CHANGES, sourceBranchId,
- TxChange.NOT_CURRENT.getValue(), sourceBaselineTxId, sourceBranchId, sourceBaselineTxId);
- while (chStmt.next()) {
- checkForCancelled();
- Long gammaId = chStmt.getLong("gamma_id");
- ModificationType modType = ModificationType.getMod(chStmt.getInt("mod_type"));
- ApplicabilityId appId = ApplicabilityId.valueOf(chStmt.getLong("app_id"));
-
- txJoin.add(gammaId, -1);
- changeByGammaId.put(gammaId, new Pair<ModificationType, ApplicabilityId>(modType, appId));
- }
- txJoin.store();
- } finally {
- chStmt.close();
- }
+ Consumer<JdbcStatement> consumer = stmt -> {
+ checkForCancelled();
+ Long gammaId = stmt.getLong("gamma_id");
+ ModificationType modType = ModificationType.getMod(stmt.getInt("mod_type"));
+ ApplicabilityId appId = ApplicabilityId.valueOf(stmt.getLong("app_id"));
+
+ txJoin.add(gammaId, -1);
+ changeByGammaId.put(gammaId, new Pair<ModificationType, ApplicabilityId>(modType, appId));
+ };
+ getJdbcClient().runQuery(consumer, JdbcConstants.JDBC__MAX_FETCH_SIZE, SELECT_SOURCE_BRANCH_CHANGES,
+ sourceBranchId, TxChange.NOT_CURRENT.getValue(), sourceBaselineTxId, sourceBranchId, sourceBaselineTxId);
+ txJoin.store();
}
private void loadByItemId(Collection<ChangeItem> changeData, int txJoinId, ChangeItemFactory factory, int sourceBaselineTxId) throws OseeCoreException {
@@ -148,11 +144,10 @@ public class LoadDeltasBetweenBranches extends AbstractDatastoreCallable<List<Ch
}
private void loadCurrentData(String tableName, String columnName, IdJoinQuery idJoin, HashMap<Integer, ChangeItem> changesByItemId, Long txBranchId, Integer txId, boolean isMergeBranch) throws OseeCoreException {
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
+ try (JdbcStatement chStmt = getJdbcClient().getStatement()) {
String query = "select txs.gamma_id, txs.mod_type, txs.app_id, item." + columnName + " from osee_join_id idj, " //
- + tableName + " item, osee_txs txs where idj.query_id = ? and idj.id = item." + columnName + //
- " and item.gamma_id = txs.gamma_id and txs.tx_current <> ? and txs.branch_id = ? and txs.transaction_id <= ?";
+ + tableName + " item, osee_txs txs where idj.query_id = ? and idj.id = item." + columnName + //
+ " and item.gamma_id = txs.gamma_id and txs.tx_current <> ? and txs.branch_id = ? and txs.transaction_id <= ?";
chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, query, idJoin.getQueryId(),
TxChange.NOT_CURRENT.getValue(), txBranchId, txId);
@@ -175,21 +170,16 @@ public class LoadDeltasBetweenBranches extends AbstractDatastoreCallable<List<Ch
change.getDestinationVersion().setApplicabilityId(appId);
}
}
- } finally {
- chStmt.close();
}
}
private void loadNonCurrentSourceData(String tableName, String idColumnName, IdJoinQuery idJoin, HashMap<Integer, ChangeItem> changesByItemId, String columnValueName, int sourceBaselineTxId) throws OseeCoreException {
- JdbcStatement chStmt = getJdbcClient().getStatement();
- String query;
-
- try {
+ try (JdbcStatement chStmt = getJdbcClient().getStatement()) {
String valueColumnName = columnValueName != null ? "item." + columnValueName + "," : "";
- query =
+ String query =
"select " + valueColumnName + "item." + idColumnName + ", txs.gamma_id, txs.mod_type, txs.app_id, txs.transaction_id from osee_join_id idj, " //
- + tableName + " item, osee_txs txs where idj.query_id = ? and idj.id = item." + idColumnName + //
- " and item.gamma_id = txs.gamma_id and txs.tx_current = ? and txs.branch_id = ? order by idj.id, txs.transaction_id asc";
+ + tableName + " item, osee_txs txs where idj.query_id = ? and idj.id = item." + idColumnName + //
+ " and item.gamma_id = txs.gamma_id and txs.tx_current = ? and txs.branch_id = ? order by idj.id, txs.transaction_id asc";
chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, query, idJoin.getQueryId(),
TxChange.NOT_CURRENT.getValue(), sourceBranchId);
@@ -222,8 +212,6 @@ public class LoadDeltasBetweenBranches extends AbstractDatastoreCallable<List<Ch
previousItemId = itemId;
}
- } finally {
- chStmt.close();
}
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenTxsOnTheSameBranch.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenTxsOnTheSameBranch.java
index d250a1a8308..de4f9b8b3a8 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenTxsOnTheSameBranch.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/change/LoadDeltasBetweenTxsOnTheSameBranch.java
@@ -15,6 +15,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.osee.framework.core.data.ApplicabilityId;
+import java.util.function.Consumer;
import org.eclipse.osee.framework.core.enums.BranchArchivedState;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.model.change.ChangeItem;
@@ -114,25 +115,21 @@ public class LoadDeltasBetweenTxsOnTheSameBranch extends AbstractDatastoreCallab
}
private void loadChangesAtEndTx(TransactionJoinQuery txJoin, boolean isArchived) throws OseeCoreException {
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
+ Consumer<JdbcStatement> consumer = stmt -> {
+ checkForCancelled();
+ Long gammaId = stmt.getLong("gamma_id");
+ ModificationType modType = ModificationType.getMod(stmt.getInt("mod_type"));
+ ApplicabilityId appId = ApplicabilityId.valueOf(stmt.getLong("app_id"));
- chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE,
- (isArchived ? SELECT_CHANGES_BETWEEN_ARCHIVED_TRANSACTIONS : SELECT_CHANGES_BETWEEN_TRANSACTIONS),
- getBranchId(), getStartTx().getGuid(), getEndTx().getGuid());
- while (chStmt.next()) {
- checkForCancelled();
- Long gammaId = chStmt.getLong("gamma_id");
- ModificationType modType = ModificationType.getMod(chStmt.getInt("mod_type"));
- ApplicabilityId appId = ApplicabilityId.valueOf(chStmt.getLong("app_id"));
+ txJoin.add(gammaId, -1);
+ changeByGammaId.put(gammaId, new Pair<ModificationType, ApplicabilityId>(modType, appId));
+ };
+ getJdbcClient().runQuery(consumer, JdbcConstants.JDBC__MAX_FETCH_SIZE,
+ (isArchived ? SELECT_CHANGES_BETWEEN_ARCHIVED_TRANSACTIONS : SELECT_CHANGES_BETWEEN_TRANSACTIONS),
+ getBranchId(), getStartTx().getGuid(), getEndTx().getGuid());
+
+ txJoin.store();
- txJoin.add(gammaId, -1);
- changeByGammaId.put(gammaId, new Pair<ModificationType, ApplicabilityId>(modType, appId));
- }
- txJoin.store();
- } finally {
- chStmt.close();
- }
}
private void loadByItemId(Collection<ChangeItem> changeData, int txJoinId, ChangeItemFactory factory, boolean isArchived) throws OseeCoreException {
@@ -153,33 +150,26 @@ public class LoadDeltasBetweenTxsOnTheSameBranch extends AbstractDatastoreCallab
}
private void loadCurrentData(String tableName, String columnName, int queryId, HashMap<Integer, ChangeItem> changesByItemId, TransactionReadable transactionLimit, boolean isArchived) throws OseeCoreException {
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- String query = String.format(
- "select txs.gamma_id, txs.mod_type, txs.app_id, item." + columnName + " from osee_join_id idj, " //
- + tableName + " item, %s txs where idj.query_id = ? and idj.id = item." + columnName + //
- " and item.gamma_id = txs.gamma_id and txs.branch_id = ? and txs.transaction_id <= ?",
- isArchived ? "osee_txs_archived" : "osee_txs");
-
- chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, query, queryId, transactionLimit.getBranchId(),
- transactionLimit.getGuid());
-
- while (chStmt.next()) {
- checkForCancelled();
+ String query = String.format("select txs.gamma_id, txs.mod_type, txs.app_id, item." + columnName + " from osee_join_id idj, " //
+ + tableName + " item, %s txs where idj.query_id = ? and idj.id = item." + columnName + //
+ " and item.gamma_id = txs.gamma_id and txs.branch_id = ? and txs.transaction_id <= ?",
+ isArchived ? "osee_txs_archived" : "osee_txs");
+ Consumer<JdbcStatement> consumer = stmt -> {
+ checkForCancelled();
+
+ Integer itemId = stmt.getInt(columnName);
+ Long gammaId = stmt.getLong("gamma_id");
+ ApplicabilityId appId = ApplicabilityId.valueOf(stmt.getLong("app_id"));
+ ModificationType modType = ModificationType.getMod(stmt.getInt("mod_type"));
+
+ ChangeItem change = changesByItemId.get(itemId);
+ change.getDestinationVersion().setModType(modType);
+ change.getDestinationVersion().setGammaId(gammaId);
+ change.getDestinationVersion().setApplicabilityId(appId);
+ change.getBaselineVersion().copy(change.getDestinationVersion());
+ };
+ getJdbcClient().runQuery(consumer, JdbcConstants.JDBC__MAX_FETCH_SIZE, query, queryId,
+ transactionLimit.getBranchId(), transactionLimit.getGuid());
- Integer itemId = chStmt.getInt(columnName);
- Long gammaId = chStmt.getLong("gamma_id");
- ApplicabilityId appId = ApplicabilityId.valueOf(chStmt.getLong("app_id"));
- ModificationType modType = ModificationType.getMod(chStmt.getInt("mod_type"));
-
- ChangeItem change = changesByItemId.get(itemId);
- change.getDestinationVersion().setModType(modType);
- change.getDestinationVersion().setGammaId(gammaId);
- change.getDestinationVersion().setApplicabilityId(appId);
- change.getBaselineVersion().copy(change.getDestinationVersion());
- }
- } finally {
- chStmt.close();
- }
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/ConvertLocalTypeIdCommand.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/ConvertLocalTypeIdCommand.java
deleted file mode 100644
index a32ee83c982..00000000000
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/console/ConvertLocalTypeIdCommand.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Created on Oct 23, 2013
- *
- * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
- */
-package org.eclipse.osee.orcs.db.internal.console;
-
-import java.util.Collection;
-import java.util.concurrent.Callable;
-import org.eclipse.osee.console.admin.Console;
-import org.eclipse.osee.console.admin.ConsoleParameters;
-import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
-import org.eclipse.osee.jdbc.JdbcClient;
-import org.eclipse.osee.jdbc.JdbcConnection;
-import org.eclipse.osee.jdbc.JdbcStatement;
-import org.eclipse.osee.logger.Log;
-import org.eclipse.osee.orcs.OrcsSession;
-import org.eclipse.osee.orcs.db.internal.callable.AbstractDatastoreTxCallable;
-
-public class ConvertLocalTypeIdCommand extends AbstractDatastoreConsoleCommand {
-
- @Override
- public String getName() {
- return "convert_type_ids";
- }
-
- @Override
- public String getDescription() {
- return "Converts local type IDs in artifact, relation, attribute tables based on osee_type_id_map values";
- }
-
- @Override
- public String getUsage() {
- StringBuilder sb = new StringBuilder();
- sb.append("Usage: convert_type_ids -[P|U]\n");
- sb.append("Synopsis:\n");
- sb.append("This command will convert local type ids to remote type ids and vice versa (if needed to go back)\n");
- sb.append("When ran without the -P or -U option, it only prints the numbers of rows in each table.\n");
- sb.append("When ran with the -P option, it converts the database putting remote_ids in for local_ids\n");
- sb.append("When ran with the -U (undo) option, it converts the database putting back local_ids in for remotes\n");
- sb.append("Options:\n");
- sb.append("\tP: Convert the database\n");
- sb.append("\tU: Unconvert the database\n");
- return sb.toString();
- }
-
- @Override
- public Callable<?> createCallable(Console console, ConsoleParameters params) {
- Collection<String> options = params.getOptions();
- boolean runConversion = options.contains("P");
- boolean undoConversion = options.contains("U");
-
- return new ConvertTypeIdsCallable(runConversion, undoConversion, console, getJdbcClient(), getLogger(),
- getSession());
- }
-
- private class ConvertTypeIdsCallable extends AbstractDatastoreTxCallable<Void> {
-
- private final String[] tables = {"osee_artifact", "osee_attribute", "osee_relation_link"};
- private final String[] columns = {"art_type_id", "attr_type_id", "rel_link_type_id"};
- private final boolean runConversion;
- private final boolean undoConversion;
- private final Console console;
- private final JdbcClient jdbcClient;
-
- public ConvertTypeIdsCallable(boolean runConversion, boolean undoConversion, Console console, JdbcClient jdbcClient, Log logger, OrcsSession session) {
- super(logger, session, jdbcClient);
- this.runConversion = runConversion;
- this.undoConversion = undoConversion;
- this.console = console;
- this.jdbcClient = jdbcClient;
- }
-
- private void updateTableIds(JdbcConnection connection) throws OseeCoreException {
- for (int i = 0; i < tables.length; i++) {
- String table = tables[i];
- String column = columns[i];
- String idCol1 = runConversion ? "remote_id" : "local_id";
- String idCol2 = runConversion ? "local_id" : "remote_id";
- String sql = String.format("update %s set %s = (select %s from osee_type_id_map where %s = %s)", table,
- column, idCol1, idCol2, column);
- int rowsUpdated = jdbcClient.runPreparedUpdate(connection, sql);
- console.writeln("[%s] had %d rows updated.", table, rowsUpdated);
- }
- }
-
- private void updateOseeInfo(JdbcConnection connection) throws OseeCoreException {
- String oseeInfoKey = "use.long.type.ids";
- String value = runConversion ? "true" : "false";
- jdbcClient.runPreparedUpdate(connection, "DELETE FROM osee_info WHERE OSEE_KEY = ?", oseeInfoKey);
- jdbcClient.runPreparedUpdate(connection, "INSERT INTO osee_info (OSEE_KEY, OSEE_VALUE) VALUES (?, ?)",
- oseeInfoKey, value);
- }
-
- private void performRowCounts() throws OseeCoreException {
- for (String table : tables) {
- JdbcStatement stmt = jdbcClient.getStatement();
- try {
- String query = String.format("select count(1) from %s", table);
- stmt.runPreparedQuery(query);
- if (stmt.next()) {
- int count = stmt.getInt(1);
- console.writeln("[%s] has %d rows", table, count);
- }
- } finally {
- stmt.close();
- }
- }
- }
-
- @Override
- protected Void handleTxWork(JdbcConnection connection) throws OseeCoreException {
- if (runConversion && undoConversion) {
- console.writeln("Options U and P cannot be specified together");
- return null;
- }
-
- if (runConversion || undoConversion) {
- String op = runConversion ? "Converting" : "Unconverting";
- console.writeln("%s the database...", op);
- updateTableIds(connection);
- updateOseeInfo(connection);
- } else {
- performRowCounts();
- }
- return null;
- }
- }
-
-}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/IdTranslator.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/IdTranslator.java
index 9cb38f75685..a6d324aa82f 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/IdTranslator.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/IdTranslator.java
@@ -21,7 +21,6 @@ import java.util.Set;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.jdbc.JdbcClient;
import org.eclipse.osee.jdbc.JdbcConnection;
-import org.eclipse.osee.jdbc.JdbcStatement;
/**
* @author Roberto E. Escobar
@@ -128,16 +127,9 @@ public class IdTranslator {
}
public void load(String sourceDatabaseId) throws OseeCoreException {
- JdbcStatement chStmt = jdbcClient.getStatement();
- try {
- originalToMapped.clear();
- chStmt.runPreparedQuery(SELECT_IDS_BY_DB_SOURCE_AND_SEQ_NAME, sourceDatabaseId, getSequenceName());
- while (chStmt.next()) {
- originalToMapped.put(chStmt.getLong("original_id"), chStmt.getLong("mapped_id"));
- }
- } finally {
- chStmt.close();
- }
+ originalToMapped.clear();
+ jdbcClient.runQuery(stmt -> originalToMapped.put(stmt.getLong("original_id"), stmt.getLong("mapped_id")),
+ SELECT_IDS_BY_DB_SOURCE_AND_SEQ_NAME, sourceDatabaseId, getSequenceName());
}
public boolean hasItemsToStore() {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/SavePointManager.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/SavePointManager.java
index 0abd7e13e27..f55611034d0 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/SavePointManager.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/SavePointManager.java
@@ -22,7 +22,6 @@ import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.jdbc.JdbcClient;
import org.eclipse.osee.jdbc.JdbcConnection;
-import org.eclipse.osee.jdbc.JdbcStatement;
/**
* @author Roberto E. Escobar
@@ -77,19 +76,12 @@ public class SavePointManager {
}
public void loadSavePoints(String sourceDatabaseId, Date sourceExportDate) throws OseeCoreException {
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- setCurrentSetPointId(LOAD_SAVE_POINT_ID);
- chStmt.runPreparedQuery(QUERY_SAVE_POINTS_FROM_IMPORT_MAP, sourceDatabaseId,
- new Timestamp(sourceExportDate.getTime()));
- while (chStmt.next()) {
- String key = chStmt.getString("save_point_name");
- savePoints.put(key, new SavePoint(key));
- }
- addCurrentSavePointToProcessed();
- } finally {
- chStmt.close();
- }
+ setCurrentSetPointId(LOAD_SAVE_POINT_ID);
+ getJdbcClient().runQuery(stmt -> {
+ String key = stmt.getString("save_point_name");
+ savePoints.put(key, new SavePoint(key));
+ } , QUERY_SAVE_POINTS_FROM_IMPORT_MAP, sourceDatabaseId, new Timestamp(sourceExportDate.getTime()));
+ addCurrentSavePointToProcessed();
}
public String getCurrentSetPointId() {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/export/DbTableExportItem.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/export/DbTableExportItem.java
index 3b41abb5a59..bab6bfc58c1 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/export/DbTableExportItem.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/exchange/export/DbTableExportItem.java
@@ -59,7 +59,7 @@ public class DbTableExportItem extends AbstractXmlExportItem {
this.bindData = bindData;
}
- private JdbcClient getDatabaseService() {
+ private JdbcClient getJdbcClient() {
return jdbcClient;
}
@@ -91,84 +91,81 @@ public class DbTableExportItem extends AbstractXmlExportItem {
}
@Override
- protected void doWork(Appendable appendable) throws Exception {
- JdbcStatement chStmt = getDatabaseService().getStatement();
- try {
- chStmt.runPreparedQuery(JdbcConstants.JDBC__MAX_FETCH_SIZE, query, bindData);
- while (chStmt.next()) {
- processData(appendable, chStmt);
- }
- } finally {
- chStmt.close();
- }
+ protected void doWork(Appendable appendable) {
+ getJdbcClient().runQuery(stmt -> processData(appendable, stmt), JdbcConstants.JDBC__MAX_FETCH_SIZE, query,
+ bindData);
}
- private void processData(Appendable appendable, JdbcStatement chStmt) throws Exception {
- ExportImportXml.openPartialXmlNode(appendable, ExportImportXml.ENTRY);
-
+ private void processData(Appendable appendable, JdbcStatement chStmt) {
try {
- int numberOfColumns = chStmt.getColumnCount();
- for (int columnIndex = 1; columnIndex <= numberOfColumns; columnIndex++) {
- String columnName = chStmt.getColumnName(columnIndex).toLowerCase();
- Object value = chStmt.getObject(columnIndex);
-
- if (columnName.equals("uri")) {
- handleBinaryContent(binaryContentBuffer, value);
- } else if (columnName.equals("value")) {
- handleStringContent(stringContentBuffer, value, ExportImportXml.STRING_CONTENT);
- } else if (columnName.equals(ExportImportXml.OSEE_COMMENT)) {
- handleStringContent(oseeCommentBuffer, value, columnName);
- } else if (columnName.equals(ExportImportXml.BRANCH_NAME)) {
- handleStringContent(branchNameBuffer, value, columnName);
- } else if (columnName.equals(ExportImportXml.RATIONALE)) {
- handleStringContent(rationaleBuffer, value, columnName);
- } else if (columnName.equals(ExportImportXml.ART_TYPE_ID)) {
- handleTypeId(appendable, value);
- } else if (columnName.equals(ExportImportXml.ATTR_TYPE_ID)) {
- handleTypeId(appendable, value);
- } else if (columnName.equals(ExportImportXml.REL_TYPE_ID)) {
- handleTypeId(appendable, value);
- } else {
- Timestamp timestamp = asTimestamp(value);
- if (timestamp != null) {
- ExportImportXml.addXmlAttribute(appendable, columnName, timestamp);
+ ExportImportXml.openPartialXmlNode(appendable, ExportImportXml.ENTRY);
+
+ try {
+ int numberOfColumns = chStmt.getColumnCount();
+ for (int columnIndex = 1; columnIndex <= numberOfColumns; columnIndex++) {
+ String columnName = chStmt.getColumnName(columnIndex).toLowerCase();
+ Object value = chStmt.getObject(columnIndex);
+
+ if (columnName.equals("uri")) {
+ handleBinaryContent(binaryContentBuffer, value);
+ } else if (columnName.equals("value")) {
+ handleStringContent(stringContentBuffer, value, ExportImportXml.STRING_CONTENT);
+ } else if (columnName.equals(ExportImportXml.OSEE_COMMENT)) {
+ handleStringContent(oseeCommentBuffer, value, columnName);
+ } else if (columnName.equals(ExportImportXml.BRANCH_NAME)) {
+ handleStringContent(branchNameBuffer, value, columnName);
+ } else if (columnName.equals(ExportImportXml.RATIONALE)) {
+ handleStringContent(rationaleBuffer, value, columnName);
+ } else if (columnName.equals(ExportImportXml.ART_TYPE_ID)) {
+ handleTypeId(appendable, value);
+ } else if (columnName.equals(ExportImportXml.ATTR_TYPE_ID)) {
+ handleTypeId(appendable, value);
+ } else if (columnName.equals(ExportImportXml.REL_TYPE_ID)) {
+ handleTypeId(appendable, value);
} else {
- try {
- ExportImportXml.addXmlAttribute(appendable, columnName, value);
- } catch (Exception ex) {
- throw new OseeCoreException(ex, "Unable to convert [%s] of raw type [%s] to string.", columnName,
- chStmt.getColumnTypeName(columnIndex));
+ Timestamp timestamp = asTimestamp(value);
+ if (timestamp != null) {
+ ExportImportXml.addXmlAttribute(appendable, columnName, timestamp);
+ } else {
+ try {
+ ExportImportXml.addXmlAttribute(appendable, columnName, value);
+ } catch (Exception ex) {
+ throw new OseeCoreException(ex, "Unable to convert [%s] of raw type [%s] to string.",
+ columnName, chStmt.getColumnTypeName(columnIndex));
+ }
}
}
}
- }
- } finally {
- if (binaryContentBuffer.length() > 0 || stringContentBuffer.length() > 0 || oseeCommentBuffer.length() > 0 || branchNameBuffer.length() > 0 || rationaleBuffer.length() > 0) {
- ExportImportXml.endOpenedPartialXmlNode(appendable);
- if (binaryContentBuffer.length() > 0) {
- appendable.append(binaryContentBuffer);
- binaryContentBuffer.delete(0, binaryContentBuffer.length());
- }
- if (stringContentBuffer.length() > 0) {
- appendable.append(stringContentBuffer);
- stringContentBuffer.delete(0, stringContentBuffer.length());
- }
- if (oseeCommentBuffer.length() > 0) {
- appendable.append(oseeCommentBuffer);
- oseeCommentBuffer.delete(0, oseeCommentBuffer.length());
- }
- if (branchNameBuffer.length() > 0) {
- appendable.append(branchNameBuffer);
- branchNameBuffer.delete(0, branchNameBuffer.length());
- }
- if (rationaleBuffer.length() > 0) {
- appendable.append(rationaleBuffer);
- rationaleBuffer.delete(0, rationaleBuffer.length());
+ } finally {
+ if (binaryContentBuffer.length() > 0 || stringContentBuffer.length() > 0 || oseeCommentBuffer.length() > 0 || branchNameBuffer.length() > 0 || rationaleBuffer.length() > 0) {
+ ExportImportXml.endOpenedPartialXmlNode(appendable);
+ if (binaryContentBuffer.length() > 0) {
+ appendable.append(binaryContentBuffer);
+ binaryContentBuffer.delete(0, binaryContentBuffer.length());
+ }
+ if (stringContentBuffer.length() > 0) {
+ appendable.append(stringContentBuffer);
+ stringContentBuffer.delete(0, stringContentBuffer.length());
+ }
+ if (oseeCommentBuffer.length() > 0) {
+ appendable.append(oseeCommentBuffer);
+ oseeCommentBuffer.delete(0, oseeCommentBuffer.length());
+ }
+ if (branchNameBuffer.length() > 0) {
+ appendable.append(branchNameBuffer);
+ branchNameBuffer.delete(0, branchNameBuffer.length());
+ }
+ if (rationaleBuffer.length() > 0) {
+ appendable.append(rationaleBuffer);
+ rationaleBuffer.delete(0, rationaleBuffer.length());
+ }
+ ExportImportXml.closeXmlNode(appendable, ExportImportXml.ENTRY);
+ } else {
+ ExportImportXml.closePartialXmlNode(appendable);
}
- ExportImportXml.closeXmlNode(appendable, ExportImportXml.ENTRY);
- } else {
- ExportImportXml.closePartialXmlNode(appendable);
}
+ } catch (Exception ex) {
+ throw new OseeCoreException(ex, "Failure during %s processData", getClass().getSimpleName());
}
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderImpl.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderImpl.java
index 45c12632d3a..0c58de8f677 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderImpl.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/DataLoaderImpl.java
@@ -182,12 +182,12 @@ public class DataLoaderImpl implements DataLoader {
private DataLoader withArtifactIds(Collection<Integer> artifactIds) {
loadExecutor =
- new LoadExecutor(sqlLoader, sqlLoader.getDatabaseService(), joinFactory, session, branchId, artifactIds);
+ new LoadExecutor(sqlLoader, sqlLoader.getJdbcClient(), joinFactory, session, branchId, artifactIds);
return this;
}
private DataLoader withArtifactGuids(Collection<String> artifactGuids) {
- loadExecutor = new UuidsLoadExecutor(sqlLoader, sqlLoader.getDatabaseService(), joinFactory, session, branchId,
+ loadExecutor = new UuidsLoadExecutor(sqlLoader, sqlLoader.getJdbcClient(), joinFactory, session, branchId,
artifactGuids);
return this;
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java
index 685ce8af801..dd9ae7a0764 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/SqlObjectLoader.java
@@ -94,7 +94,7 @@ public class SqlObjectLoader {
return sqlProvider;
}
- public JdbcClient getDatabaseService() {
+ public JdbcClient getJdbcClient() {
return jdbcClient;
}
@@ -230,7 +230,7 @@ public class SqlObjectLoader {
protected int loadHeadTransactionId(Long branchId) throws OseeCoreException {
String sql = sqlProvider.getSql(OseeSql.TX_GET_MAX_AS_LARGEST_TX);
- return getDatabaseService().runPreparedQueryFetchObject(RelationalConstants.TRANSACTION_SENTINEL, sql, branchId);
+ return getJdbcClient().runPreparedQueryFetchObject(RelationalConstants.TRANSACTION_SENTINEL, sql, branchId);
}
protected <H> void load(AbstractLoadProcessor<H> processor, H handler, SqlContext loadContext, int fetchSize) throws OseeCoreException {
@@ -240,9 +240,7 @@ public class SqlObjectLoader {
}
long startTime = System.currentTimeMillis();
- JdbcStatement chStmt = null;
- try {
- chStmt = getDatabaseService().getStatement();
+ try (JdbcStatement chStmt = getJdbcClient().getStatement()) {
chStmt.runPreparedQuery(fetchSize, loadContext.getSql(), loadContext.getParameters().toArray());
String processorName = null;
@@ -259,8 +257,6 @@ public class SqlObjectLoader {
logger.trace("Sql Artifact Load [%s] - [%s] processed [%d] rows", Lib.getElapseString(startTime),
processorName, rowCount);
}
- } finally {
- Lib.close(chStmt);
}
} finally {
for (AbstractJoinQuery join : loadContext.getJoins()) {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/ArtifactQueryContextLoadExecutor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/ArtifactQueryContextLoadExecutor.java
index a5197f86f2f..62d9ba6f976 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/ArtifactQueryContextLoadExecutor.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/ArtifactQueryContextLoadExecutor.java
@@ -11,10 +11,10 @@
package org.eclipse.osee.orcs.db.internal.loader.executors;
import java.util.List;
+import java.util.function.Consumer;
import org.eclipse.osee.executor.admin.HasCancellation;
import org.eclipse.osee.framework.core.data.RelationalConstants;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
-import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.jdbc.JdbcClient;
import org.eclipse.osee.jdbc.JdbcStatement;
import org.eclipse.osee.orcs.core.ds.LoadDataHandler;
@@ -70,23 +70,17 @@ public class ArtifactQueryContextLoadExecutor extends AbstractLoadExecutor {
checkCancelled(cancellation);
}
Integer transactionId = OptionsUtil.getFromTransaction(queryContext.getOptions());
- JdbcStatement chStmt = null;
- try {
- chStmt = jdbcClient.getStatement();
+ Consumer<JdbcStatement> consumer = stmt -> {
checkCancelled(cancellation);
- String query = queryContext.getSql();
- List<Object> params = queryContext.getParameters();
- chStmt.runPreparedQuery(fetchSize, query, params.toArray());
- while (chStmt.next()) {
- checkCancelled(cancellation);
- Integer artId = chStmt.getInt("art_id");
- Long branchUuid = chStmt.getLong("branch_id");
- artifactJoin.add(artId, branchUuid, transactionId);
- checkCancelled(cancellation);
- }
- } finally {
- Lib.close(chStmt);
- }
+ Integer artId = stmt.getInt("art_id");
+ Long branchUuid = stmt.getLong("branch_id");
+ artifactJoin.add(artId, branchUuid, transactionId);
+ checkCancelled(cancellation);
+ };
+ checkCancelled(cancellation);
+ String query = queryContext.getSql();
+ List<Object> params = queryContext.getParameters();
+ getJdbcClient().runQuery(consumer, fetchSize, query, params.toArray());
} finally {
for (AbstractJoinQuery join : queryContext.getJoins()) {
try {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java
index f986a19287f..de202f4224d 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/loader/executors/UuidsLoadExecutor.java
@@ -13,9 +13,7 @@ package org.eclipse.osee.orcs.db.internal.loader.executors;
import java.util.Collection;
import org.eclipse.osee.executor.admin.HasCancellation;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
-import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.jdbc.JdbcClient;
-import org.eclipse.osee.jdbc.JdbcStatement;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.ds.LoadDataHandler;
import org.eclipse.osee.orcs.core.ds.Options;
@@ -73,17 +71,11 @@ public class UuidsLoadExecutor extends AbstractLoadExecutor {
Integer transactionId = OptionsUtil.getFromTransaction(options);
- JdbcStatement chStmt = null;
- try {
- chStmt = jdbcClient.getStatement();
- chStmt.runPreparedQuery(artifactIds.size(), GUIDS_TO_IDS, guidJoin.getQueryId());
- while (chStmt.next()) {
- Integer artId = chStmt.getInt("art_id");
- toReturn.add(artId, branchId, transactionId);
- }
- } finally {
- Lib.close(chStmt);
- }
+ getJdbcClient().runQuery(stmt -> {
+ Integer artId = stmt.getInt("art_id");
+ toReturn.add(artId, branchId, transactionId);
+ } , artifactIds.size(), GUIDS_TO_IDS, guidJoin.getQueryId());
+
} finally {
guidJoin.delete();
}
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/callable/producer/IndexBranchesDatabaseCallable.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/callable/producer/IndexBranchesDatabaseCallable.java
index 8e2b0e33ea6..a21b6c1508c 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/callable/producer/IndexBranchesDatabaseCallable.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/callable/producer/IndexBranchesDatabaseCallable.java
@@ -13,7 +13,9 @@ package org.eclipse.osee.orcs.db.internal.search.indexer.callable.producer;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import java.util.function.Consumer;
import org.eclipse.osee.framework.core.data.IAttributeType;
+import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.Triplet;
import org.eclipse.osee.jdbc.JdbcClient;
import org.eclipse.osee.jdbc.JdbcStatement;
@@ -115,30 +117,30 @@ public final class IndexBranchesDatabaseCallable extends AbstractDatastoreCallab
return branchUuids.size();
}
- public void storeAndAddQueryId(TagQueueJoinQuery joinQuery) throws Exception {
- if (!joinQuery.isEmpty()) {
- joinQuery.store();
- consumer.submitTaskId(getSession(), types, collector, joinQuery.getQueryId());
+ public void storeAndAddQueryId(TagQueueJoinQuery joinQuery) {
+ try {
+ if (!joinQuery.isEmpty()) {
+ joinQuery.store();
+ consumer.submitTaskId(getSession(), types, collector, joinQuery.getQueryId());
+ }
+ } catch (Exception ex) {
+ OseeCoreException.wrapAndThrow(ex);
}
}
- private void fetchAndProcessGammas(String query, Object... params) throws Exception {
- JdbcStatement chStmt = getJdbcClient().getStatement();
- try {
- chStmt.runPreparedQuery(query, params);
- TagQueueJoinQuery joinQuery = joinFactory.createTagQueueJoinQuery();
- while (chStmt.next()) {
- long gammaId = chStmt.getLong("gamma_id");
- joinQuery.add(gammaId);
- if (joinQuery.size() >= BATCH_SIZE) {
- storeAndAddQueryId(joinQuery);
- joinQuery = joinFactory.createTagQueueJoinQuery();
- }
+ private void fetchAndProcessGammas(String query, Object... params) {
+ TagQueueJoinQuery queryHolder[] = new TagQueueJoinQuery[1];
+ queryHolder[0] = joinFactory.createTagQueueJoinQuery();
+ Consumer<JdbcStatement> consumer = stmt -> {
+ long gammaId = stmt.getLong("gamma_id");
+ queryHolder[0].add(gammaId);
+ if (queryHolder[0].size() >= BATCH_SIZE) {
+ storeAndAddQueryId(queryHolder[0]);
+ queryHolder[0] = joinFactory.createTagQueueJoinQuery();
}
- storeAndAddQueryId(joinQuery);
- } finally {
- chStmt.close();
- }
+ };
+ getJdbcClient().runQuery(consumer, query, params);
+ storeAndAddQueryId(queryHolder[0]);
}
private String getParamInfo() {
diff --git a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/data/GammaQueueIndexerDataSourceLoader.java b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/data/GammaQueueIndexerDataSourceLoader.java
index 23635475ced..4360fcd1b26 100644
--- a/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/data/GammaQueueIndexerDataSourceLoader.java
+++ b/plugins/org.eclipse.osee.orcs.db/src/org/eclipse/osee/orcs/db/internal/search/indexer/data/GammaQueueIndexerDataSourceLoader.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.orcs.db.internal.search.indexer.data;
+import java.util.function.Consumer;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.resource.management.IResourceManager;
import org.eclipse.osee.jdbc.JdbcClient;
@@ -38,35 +39,26 @@ public class GammaQueueIndexerDataSourceLoader implements IndexedResourceLoader
this.resourceManager = resourceManager;
}
- private boolean loadData(OrcsDataHandler<IndexedResource> handler, int tagQueueQueryId) throws OseeCoreException {
- boolean loaded = false;
- JdbcStatement chStmt = jdbcClient.getStatement();
- try {
- chStmt.runPreparedQuery(LOAD_ATTRIBUTE, tagQueueQueryId);
- while (chStmt.next()) {
- loaded = true;
+ private int loadData(OrcsDataHandler<IndexedResource> handler, int tagQueueQueryId) throws OseeCoreException {
+ Consumer<JdbcStatement> consumer = stmt -> {
+ int itemId = stmt.getInt("attr_id");
+ long typeUuid = stmt.getLong("attr_type_id");
+ long gammaId = stmt.getLong("gamma_id");
+ String uri = stmt.getString("uri");
+ String value = stmt.getString("value");
- int itemId = chStmt.getInt("attr_id");
- long typeUuid = chStmt.getLong("attr_type_id");
- long gammaId = chStmt.getLong("gamma_id");
- String uri = chStmt.getString("uri");
- String value = chStmt.getString("value");
-
- IndexedResource data = createData(itemId, typeUuid, gammaId, value, uri);
- handler.onData(data);
- }
- } finally {
- chStmt.close();
- }
- return loaded;
+ IndexedResource data = createData(itemId, typeUuid, gammaId, value, uri);
+ handler.onData(data);
+ };
+ return jdbcClient.runQuery(consumer, LOAD_ATTRIBUTE, tagQueueQueryId);
}
@Override
public void loadSource(OrcsDataHandler<IndexedResource> handler, int tagQueueQueryId) throws OseeCoreException {
- boolean loadSuccess = loadData(handler, tagQueueQueryId);
+ int count = loadData(handler, tagQueueQueryId);
// Re-try in case query id hasn't been committed to the database
int retry = 0;
- while (!loadSuccess && retry < IndexerConstants.INDEX_QUERY_ID_LOADER_TOTAL_RETRIES) {
+ while (count == 0 && retry < IndexerConstants.INDEX_QUERY_ID_LOADER_TOTAL_RETRIES) {
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
@@ -74,7 +66,7 @@ public class GammaQueueIndexerDataSourceLoader implements IndexedResourceLoader
}
logger.debug("Retrying attribute load from gammas - queryId[%s] attempt[%s of %s]", tagQueueQueryId, retry,
IndexerConstants.INDEX_QUERY_ID_LOADER_TOTAL_RETRIES);
- loadSuccess = loadData(handler, tagQueueQueryId);
+ loadData(handler, tagQueueQueryId);
retry++;
}
}

Back to the top