From 0eb32bee62994f865b0c4da534a7b0cc8b66d9f9 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Thu, 10 Jul 2025 11:28:47 -0400 Subject: [PATCH 1/6] Update RdbmsCentralRepo.java Update Account_ID column if the table has an account_id. --- .../datamodel/RdbmsCentralRepo.java | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index ee017de8422..83746237a60 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -46,6 +46,8 @@ import org.openide.util.NbBundle.Messages; import org.sleuthkit.autopsy.casemodule.Case; import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoAccount.CentralRepoAccountType; +import static org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbUtil.correlationAttribHasAnAccount; +import static org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbUtil.correlationTypeToInstanceTableName; import static org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepoDbUtil.updateSchemaVersion; import org.sleuthkit.autopsy.coreutils.Logger; import org.sleuthkit.autopsy.healthmonitor.HealthMonitor; @@ -1668,7 +1670,14 @@ public void addAttributeInstanceBulk(CorrelationAttributeInstance eamArtifact) t @Override public void commitAttributeInstancesBulk() throws CentralRepoException { List artifactTypes = getDefinedCorrelationTypes(); - + + Map correlationHasAccount = new HashMap<>(); + for (CorrelationAttributeInstance.Type artifactType : artifactTypes) { + String tableName = correlationTypeToInstanceTableName(artifactType); + Boolean isAccount = Boolean.valueOf(correlationAttribHasAnAccount(artifactType)); + correlationHasAccount.put(correlationTypeToInstanceTableName(artifactType), Boolean.valueOf(correlationAttribHasAnAccount(artifactType))); + } + Connection conn = connect(); PreparedStatement bulkPs = null; @@ -1680,14 +1689,23 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { for (String tableName : bulkArtifacts.keySet()) { - String sql - = "INSERT INTO " - + tableName - + " (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id) " - + "VALUES ((SELECT id FROM cases WHERE case_uid=? LIMIT 1), " - + "(SELECT id FROM data_sources WHERE datasource_obj_id=? AND case_id=? LIMIT 1), ?, ?, ?, ?, ?) " - + getConflictClause(); - + String sql; + if (correlationHasAccount.get(tableName)) { + sql = "INSERT INTO " + + tableName + + " (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id, account_id) " + + "VALUES ((SELECT id FROM cases WHERE case_uid=? LIMIT 1), " + + "(SELECT id FROM data_sources WHERE datasource_obj_id=? AND case_id=? LIMIT 1), ?, ?, ?, ?, ?, ?) " + + getConflictClause(); + } else { + sql = "INSERT INTO " + + tableName + + " (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id) " + + "VALUES ((SELECT id FROM cases WHERE case_uid=? LIMIT 1), " + + "(SELECT id FROM data_sources WHERE datasource_obj_id=? AND case_id=? LIMIT 1), ?, ?, ?, ?, ?) " + + getConflictClause(); + } + bulkPs = conn.prepareStatement(sql); Collection eamArtifacts = bulkArtifacts.get(tableName); @@ -1730,6 +1748,9 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { bulkPs.setString(7, eamArtifact.getComment()); } bulkPs.setLong(8, eamArtifact.getFileObjectId()); + if (correlationHasAccount.get(tableName)) { + bulkPs.setLong(9, eamArtifact.getAccountId()); + } bulkPs.addBatch(); } else { logger.log(Level.WARNING, ("Artifact value too long for central repository." From 4ebda3ec610f94c62f3b1eea288a92c86552a36f Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Mon, 6 Apr 2026 11:15:43 -0400 Subject: [PATCH 2/6] updates based on CodeRabbit review updates based on CodeRabbit review --- .../centralrepository/datamodel/RdbmsCentralRepo.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index 83746237a60..9b7a7af14d6 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -1674,8 +1674,8 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { Map correlationHasAccount = new HashMap<>(); for (CorrelationAttributeInstance.Type artifactType : artifactTypes) { String tableName = correlationTypeToInstanceTableName(artifactType); - Boolean isAccount = Boolean.valueOf(correlationAttribHasAnAccount(artifactType)); - correlationHasAccount.put(correlationTypeToInstanceTableName(artifactType), Boolean.valueOf(correlationAttribHasAnAccount(artifactType))); + Boolean isAccount = correlationAttribHasAnAccount(artifactType); + correlationHasAccount.put(tableName, isAccount); } Connection conn = connect(); @@ -1749,7 +1749,11 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { } bulkPs.setLong(8, eamArtifact.getFileObjectId()); if (correlationHasAccount.get(tableName)) { - bulkPs.setLong(9, eamArtifact.getAccountId()); + if (eamArtifact.getAccountId() != null && eamArtifact.getAccountId() >= 0) { + bulkPs.setLong(9, eamArtifact.getAccountId()); + } else { + bulkPs.setNull(9, Types.INTEGER); + } } bulkPs.addBatch(); } else { From 4ab61003e00c1a20236c5994419804725315577a Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Mon, 6 Apr 2026 16:52:15 -0400 Subject: [PATCH 3/6] Update RdbmsCentralRepo.java address coderabbitai comments --- .../autopsy/centralrepository/datamodel/RdbmsCentralRepo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index 9b7a7af14d6..924748d2e44 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -1690,7 +1690,7 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { for (String tableName : bulkArtifacts.keySet()) { String sql; - if (correlationHasAccount.get(tableName)) { + if (correlationHasAccount.getOrDefault(tableName, false)) { sql = "INSERT INTO " + tableName + " (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id, account_id) " From caf47169835ce80622d404da955063c0a61d15e3 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Tue, 7 Apr 2026 11:12:17 -0400 Subject: [PATCH 4/6] fixes suggested by CodeRabbit Fixes suggested by codeRabbit --- .../centralrepository/datamodel/RdbmsCentralRepo.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index 924748d2e44..4d1f4310c2a 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -1688,9 +1688,9 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { } for (String tableName : bulkArtifacts.keySet()) { - + final boolean tableHasAccount = correlationHasAccount.getOrDefault(tableName, false); String sql; - if (correlationHasAccount.getOrDefault(tableName, false)) { + if (tableHasAccount) { sql = "INSERT INTO " + tableName + " (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id, account_id) " @@ -1748,7 +1748,7 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { bulkPs.setString(7, eamArtifact.getComment()); } bulkPs.setLong(8, eamArtifact.getFileObjectId()); - if (correlationHasAccount.get(tableName)) { + if (tableHasAccount) { if (eamArtifact.getAccountId() != null && eamArtifact.getAccountId() >= 0) { bulkPs.setLong(9, eamArtifact.getAccountId()); } else { From 8fa78a32d36ffbc791865d46b4bb45a318f56b11 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Tue, 7 Apr 2026 11:26:32 -0400 Subject: [PATCH 5/6] Update RdbmsCentralRepo.java Coderabbit suggested fix --- .../centralrepository/datamodel/RdbmsCentralRepo.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index 4d1f4310c2a..ead00b6b63e 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -1749,8 +1749,9 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { } bulkPs.setLong(8, eamArtifact.getFileObjectId()); if (tableHasAccount) { - if (eamArtifact.getAccountId() != null && eamArtifact.getAccountId() >= 0) { - bulkPs.setLong(9, eamArtifact.getAccountId()); + Long accountId = eamArtifact.getAccountId(); + if (accountId != null && accountId >= 0) { + bulkPs.setLong(9, accountId); } else { bulkPs.setNull(9, Types.INTEGER); } From f3ee5b565ba44b3c7e0f8e2bf8c12d20f5baec11 Mon Sep 17 00:00:00 2001 From: Mark McKinnon Date: Thu, 9 Apr 2026 12:53:22 -0400 Subject: [PATCH 6/6] Update RdbmsCentralRepo.java Update to use doescolumnexist --- .../centralrepository/datamodel/RdbmsCentralRepo.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java index ead00b6b63e..4b16b2032e7 100644 --- a/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java +++ b/Core/src/org/sleuthkit/autopsy/centralrepository/datamodel/RdbmsCentralRepo.java @@ -1671,13 +1671,6 @@ public void addAttributeInstanceBulk(CorrelationAttributeInstance eamArtifact) t public void commitAttributeInstancesBulk() throws CentralRepoException { List artifactTypes = getDefinedCorrelationTypes(); - Map correlationHasAccount = new HashMap<>(); - for (CorrelationAttributeInstance.Type artifactType : artifactTypes) { - String tableName = correlationTypeToInstanceTableName(artifactType); - Boolean isAccount = correlationAttribHasAnAccount(artifactType); - correlationHasAccount.put(tableName, isAccount); - } - Connection conn = connect(); PreparedStatement bulkPs = null; @@ -1688,7 +1681,7 @@ public void commitAttributeInstancesBulk() throws CentralRepoException { } for (String tableName : bulkArtifacts.keySet()) { - final boolean tableHasAccount = correlationHasAccount.getOrDefault(tableName, false); + final boolean tableHasAccount = doesColumnExist(conn, tableName, "account_id"); String sql; if (tableHasAccount) { sql = "INSERT INTO "