19 package org.sleuthkit.autopsy.centralrepository.datamodel;
21 import com.google.common.cache.Cache;
22 import com.google.common.cache.CacheBuilder;
23 import com.google.common.cache.CacheLoader;
24 import java.net.UnknownHostException;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Collection;
28 import java.util.LinkedHashSet;
29 import java.util.stream.Collectors;
30 import java.sql.Connection;
31 import java.sql.PreparedStatement;
32 import java.sql.ResultSet;
33 import java.sql.SQLException;
34 import java.sql.Statement;
35 import java.sql.Types;
36 import java.time.LocalDate;
37 import java.util.HashMap;
40 import java.util.concurrent.ExecutionException;
41 import java.util.concurrent.TimeUnit;
42 import java.util.logging.Level;
48 import org.
sleuthkit.datamodel.CaseDbSchemaVersionNumber;
56 abstract class AbstractSqlEamDb
implements EamDb {
59 static final String SCHEMA_MAJOR_VERSION_KEY =
"SCHEMA_VERSION";
60 static final String SCHEMA_MINOR_VERSION_KEY =
"SCHEMA_MINOR_VERSION";
61 static final String CREATION_SCHEMA_MAJOR_VERSION_KEY =
"CREATION_SCHEMA_MAJOR_VERSION";
62 static final String CREATION_SCHEMA_MINOR_VERSION_KEY =
"CREATION_SCHEMA_MINOR_VERSION";
63 static final CaseDbSchemaVersionNumber CURRENT_DB_SCHEMA_VERSION =
new CaseDbSchemaVersionNumber(1, 2);
67 private int bulkArtifactsCount;
68 protected int bulkArtifactsThreshold;
69 private final Map<String, Collection<CorrelationAttributeInstance>> bulkArtifacts;
70 private static final int CASE_CACHE_TIMEOUT = 5;
71 private static final int DATA_SOURCE_CACHE_TIMEOUT = 5;
73 private static final Cache<String, CorrelationCase> caseCacheByUUID = CacheBuilder.newBuilder()
74 .expireAfterWrite(CASE_CACHE_TIMEOUT, TimeUnit.MINUTES).
76 private static final Cache<Integer, CorrelationCase> caseCacheById = CacheBuilder.newBuilder()
77 .expireAfterWrite(CASE_CACHE_TIMEOUT, TimeUnit.MINUTES).
79 private static final Cache<String, CorrelationDataSource> dataSourceCacheByDsObjectId = CacheBuilder.newBuilder()
80 .expireAfterWrite(DATA_SOURCE_CACHE_TIMEOUT, TimeUnit.MINUTES).
82 private static final Cache<String, CorrelationDataSource> dataSourceCacheById = CacheBuilder.newBuilder()
83 .expireAfterWrite(DATA_SOURCE_CACHE_TIMEOUT, TimeUnit.MINUTES).
86 static final int MAX_VALUE_LENGTH = 256;
90 static final int DEFAULT_BULK_THRESHHOLD = 1000;
98 bulkArtifactsCount = 0;
99 bulkArtifacts =
new HashMap<>();
102 defaultCorrelationTypes.forEach((type) -> {
121 public void newDbInfo(String name, String value)
throws EamDbException {
122 Connection conn = connect();
124 PreparedStatement preparedStatement = null;
125 String sql =
"INSERT INTO db_info (name, value) VALUES (?, ?) "
126 + getConflictClause();
128 preparedStatement = conn.prepareStatement(sql);
129 preparedStatement.setString(1, name);
130 preparedStatement.setString(2, value);
131 preparedStatement.executeUpdate();
132 }
catch (SQLException ex) {
133 throw new EamDbException(
"Error adding new name/value pair to db_info.", ex);
142 public void addDataSourceObjectId(
int rowId,
long dataSourceObjectId)
throws EamDbException {
143 Connection conn = connect();
144 PreparedStatement preparedStatement = null;
145 String sql =
"UPDATE data_sources SET datasource_obj_id=? WHERE id=?";
147 preparedStatement = conn.prepareStatement(sql);
148 preparedStatement.setLong(1, dataSourceObjectId);
149 preparedStatement.setInt(2, rowId);
150 preparedStatement.executeUpdate();
151 }
catch (SQLException ex) {
152 throw new EamDbException(
"Error updating data source object id for data_sources row " + rowId, ex);
169 public String getDbInfo(String name)
throws EamDbException {
170 Connection conn = connect();
172 PreparedStatement preparedStatement = null;
173 ResultSet resultSet = null;
175 String sql =
"SELECT value FROM db_info WHERE name=?";
177 preparedStatement = conn.prepareStatement(sql);
178 preparedStatement.setString(1, name);
179 resultSet = preparedStatement.executeQuery();
180 if (resultSet.next()) {
181 value = resultSet.getString(
"value");
183 }
catch (SQLException ex) {
184 throw new EamDbException(
"Error getting value for name.", ex);
197 protected final void clearCaches() {
198 typeCache.invalidateAll();
199 caseCacheByUUID.invalidateAll();
200 caseCacheById.invalidateAll();
201 dataSourceCacheByDsObjectId.invalidateAll();
202 dataSourceCacheById.invalidateAll();
214 public void updateDbInfo(String name, String value)
throws EamDbException {
215 Connection conn = connect();
217 PreparedStatement preparedStatement = null;
218 String sql =
"UPDATE db_info SET value=? WHERE name=?";
220 preparedStatement = conn.prepareStatement(sql);
221 preparedStatement.setString(1, value);
222 preparedStatement.setString(2, name);
223 preparedStatement.executeUpdate();
224 }
catch (SQLException ex) {
225 throw new EamDbException(
"Error updating value for name.", ex);
246 if (cRCase != null) {
250 Connection conn = connect();
251 PreparedStatement preparedStatement = null;
253 String sql =
"INSERT INTO cases(case_uid, org_id, case_name, creation_date, case_number, "
254 +
"examiner_name, examiner_email, examiner_phone, notes) "
255 +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) "
256 + getConflictClause();
257 ResultSet resultSet = null;
259 preparedStatement = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
261 preparedStatement.setString(1, eamCase.
getCaseUUID());
262 if (null == eamCase.
getOrg()) {
263 preparedStatement.setNull(2, Types.INTEGER);
270 preparedStatement.setNull(5, Types.INTEGER);
275 preparedStatement.setNull(6, Types.INTEGER);
280 preparedStatement.setNull(7, Types.INTEGER);
285 preparedStatement.setNull(8, Types.INTEGER);
289 if (
"".equals(eamCase.
getNotes())) {
290 preparedStatement.setNull(9, Types.INTEGER);
292 preparedStatement.setString(9, eamCase.
getNotes());
295 preparedStatement.executeUpdate();
297 resultSet = preparedStatement.getGeneratedKeys();
298 if (!resultSet.next()) {
299 throw new EamDbException(String.format(
"Failed to INSERT case %s in central repo", eamCase.
getCaseUUID()));
301 int caseID = resultSet.getInt(1);
305 caseCacheByUUID.put(eamCase.
getCaseUUID(), correlationCase);
306 caseCacheById.put(caseID, correlationCase);
307 }
catch (SQLException ex) {
308 throw new EamDbException(
"Error inserting new case.", ex);
326 if (autopsyCase == null) {
327 throw new EamDbException(
"Case is null");
341 return newCase(curCeCase);
346 return getCaseByUUID(autopsyCase.
getName());
355 public void updateCase(
CorrelationCase eamCase)
throws EamDbException {
356 if (eamCase == null) {
357 throw new EamDbException(
"Correlation case is null");
360 Connection conn = connect();
362 PreparedStatement preparedStatement = null;
363 String sql =
"UPDATE cases "
364 +
"SET org_id=?, case_name=?, creation_date=?, case_number=?, examiner_name=?, examiner_email=?, examiner_phone=?, notes=? "
365 +
"WHERE case_uid=?";
368 preparedStatement = conn.prepareStatement(sql);
370 if (null == eamCase.
getOrg()) {
371 preparedStatement.setNull(1, Types.INTEGER);
379 preparedStatement.setNull(4, Types.INTEGER);
384 preparedStatement.setNull(5, Types.INTEGER);
389 preparedStatement.setNull(6, Types.INTEGER);
394 preparedStatement.setNull(7, Types.INTEGER);
398 if (
"".equals(eamCase.
getNotes())) {
399 preparedStatement.setNull(8, Types.INTEGER);
401 preparedStatement.setString(8, eamCase.
getNotes());
404 preparedStatement.setString(9, eamCase.
getCaseUUID());
406 preparedStatement.executeUpdate();
408 caseCacheById.put(eamCase.
getID(), eamCase);
409 caseCacheByUUID.put(eamCase.
getCaseUUID(), eamCase);
410 }
catch (SQLException ex) {
411 throw new EamDbException(
"Error updating case.", ex);
426 public CorrelationCase getCaseByUUID(String caseUUID)
throws EamDbException {
428 return caseCacheByUUID.get(caseUUID, () -> getCaseByUUIDFromCr(caseUUID));
429 }
catch (CacheLoader.InvalidCacheLoadException ignored) {
432 }
catch (ExecutionException ex) {
433 throw new EamDbException(
"Error getting autopsy case from Central repo", ex);
444 private CorrelationCase getCaseByUUIDFromCr(String caseUUID)
throws EamDbException {
445 Connection conn = connect();
448 PreparedStatement preparedStatement = null;
449 ResultSet resultSet = null;
451 String sql =
"SELECT cases.id as case_id, case_uid, case_name, creation_date, case_number, examiner_name, "
452 +
"examiner_email, examiner_phone, notes, organizations.id as org_id, org_name, poc_name, poc_email, poc_phone "
454 +
"LEFT JOIN organizations ON cases.org_id=organizations.id "
455 +
"WHERE case_uid=?";
458 preparedStatement = conn.prepareStatement(sql);
459 preparedStatement.setString(1, caseUUID);
460 resultSet = preparedStatement.executeQuery();
461 if (resultSet.next()) {
462 eamCaseResult = getEamCaseFromResultSet(resultSet);
464 if (eamCaseResult != null) {
466 caseCacheById.put(eamCaseResult.
getID(), eamCaseResult);
468 }
catch (SQLException ex) {
469 throw new EamDbException(
"Error getting case details.", ex);
476 return eamCaseResult;
489 return caseCacheById.get(caseId, () -> getCaseByIdFromCr(caseId));
490 }
catch (CacheLoader.InvalidCacheLoadException ignored) {
493 }
catch (ExecutionException ex) {
494 throw new EamDbException(
"Error getting autopsy case from Central repo", ex);
505 private CorrelationCase getCaseByIdFromCr(
int caseId)
throws EamDbException {
506 Connection conn = connect();
509 PreparedStatement preparedStatement = null;
510 ResultSet resultSet = null;
512 String sql =
"SELECT cases.id as case_id, case_uid, case_name, creation_date, case_number, examiner_name, "
513 +
"examiner_email, examiner_phone, notes, organizations.id as org_id, org_name, poc_name, poc_email, poc_phone "
515 +
"LEFT JOIN organizations ON cases.org_id=organizations.id "
516 +
"WHERE cases.id=?";
518 preparedStatement = conn.prepareStatement(sql);
519 preparedStatement.setInt(1, caseId);
520 resultSet = preparedStatement.executeQuery();
521 if (resultSet.next()) {
522 eamCaseResult = getEamCaseFromResultSet(resultSet);
524 if (eamCaseResult != null) {
526 caseCacheByUUID.put(eamCaseResult.
getCaseUUID(), eamCaseResult);
528 }
catch (SQLException ex) {
529 throw new EamDbException(
"Error getting case details.", ex);
536 return eamCaseResult;
545 public List<CorrelationCase> getCases()
throws EamDbException {
546 Connection conn = connect();
548 List<CorrelationCase> cases =
new ArrayList<>();
550 PreparedStatement preparedStatement = null;
551 ResultSet resultSet = null;
553 String sql =
"SELECT cases.id as case_id, case_uid, case_name, creation_date, case_number, examiner_name, "
554 +
"examiner_email, examiner_phone, notes, organizations.id as org_id, org_name, poc_name, poc_email, poc_phone "
556 +
"LEFT JOIN organizations ON cases.org_id=organizations.id";
559 preparedStatement = conn.prepareStatement(sql);
560 resultSet = preparedStatement.executeQuery();
561 while (resultSet.next()) {
562 eamCaseResult = getEamCaseFromResultSet(resultSet);
563 cases.add(eamCaseResult);
565 }
catch (SQLException ex) {
566 throw new EamDbException(
"Error getting all cases.", ex);
586 private static String getDataSourceByDSObjectIdCacheKey(
int caseId, Long dataSourceObjectId) {
587 return "Case" + caseId +
"DsObjectId" + dataSourceObjectId;
599 private static String getDataSourceByIdCacheKey(
int caseId,
int dataSourceId) {
600 return "Case" + caseId +
"Id" + dataSourceId;
611 throw new EamDbException(
"Case ID is -1");
612 }
else if (eamDataSource.getID() != -1) {
614 return eamDataSource;
616 Connection conn = connect();
618 PreparedStatement preparedStatement = null;
620 String sql =
"INSERT INTO data_sources(device_id, case_id, name, datasource_obj_id) VALUES (?, ?, ?, ?) "
621 + getConflictClause();
622 ResultSet resultSet = null;
624 preparedStatement = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
626 preparedStatement.setString(1, eamDataSource.
getDeviceID());
627 preparedStatement.setInt(2, eamDataSource.
getCaseID());
628 preparedStatement.setString(3, eamDataSource.
getName());
631 preparedStatement.executeUpdate();
632 resultSet = preparedStatement.getGeneratedKeys();
633 if (!resultSet.next()) {
634 throw new EamDbException(String.format(
"Failed to INSERT data source %s in central repo", eamDataSource.
getName()));
636 int dataSourceId = resultSet.getInt(1);
639 dataSourceCacheById.put(getDataSourceByIdCacheKey(dataSource.
getCaseID(), dataSource.getID()), dataSource);
641 }
catch (SQLException ex) {
642 throw new EamDbException(
"Error inserting new data source.", ex);
664 if (correlationCase == null) {
665 throw new EamDbException(
"Correlation case is null");
668 return dataSourceCacheByDsObjectId.get(getDataSourceByDSObjectIdCacheKey(correlationCase.
getID(), dataSourceObjectId), () -> getDataSourceFromCr(correlationCase, dataSourceObjectId));
669 }
catch (CacheLoader.InvalidCacheLoadException ignored) {
672 }
catch (ExecutionException ex) {
673 throw new EamDbException(
"Error getting data source from central repository", ex);
690 Connection conn = connect();
693 PreparedStatement preparedStatement = null;
694 ResultSet resultSet = null;
696 String sql =
"SELECT * FROM data_sources WHERE datasource_obj_id=? AND case_id=?";
699 preparedStatement = conn.prepareStatement(sql);
700 preparedStatement.setLong(1, dataSourceObjectId);
701 preparedStatement.setInt(2, correlationCase.
getID());
702 resultSet = preparedStatement.executeQuery();
703 if (resultSet.next()) {
704 eamDataSourceResult = getEamDataSourceFromResultSet(resultSet);
706 if (eamDataSourceResult != null) {
707 dataSourceCacheById.put(getDataSourceByIdCacheKey(correlationCase.
getID(), eamDataSourceResult.getID()), eamDataSourceResult);
709 }
catch (SQLException ex) {
710 throw new EamDbException(
"Error getting data source.", ex);
717 return eamDataSourceResult;
731 if (correlationCase == null) {
732 throw new EamDbException(
"Correlation case is null");
735 return dataSourceCacheById.get(getDataSourceByIdCacheKey(correlationCase.
getID(), dataSourceId), () -> getDataSourceByIdFromCr(correlationCase, dataSourceId));
736 }
catch (CacheLoader.InvalidCacheLoadException ignored) {
739 }
catch (ExecutionException ex) {
740 throw new EamDbException(
"Error getting data source from central repository", ex);
754 Connection conn = connect();
757 PreparedStatement preparedStatement = null;
758 ResultSet resultSet = null;
760 String sql =
"SELECT * FROM data_sources WHERE id=? AND case_id=?";
763 preparedStatement = conn.prepareStatement(sql);
764 preparedStatement.setInt(1, dataSourceId);
765 preparedStatement.setInt(2, correlationCase.
getID());
766 resultSet = preparedStatement.executeQuery();
767 if (resultSet.next()) {
768 eamDataSourceResult = getEamDataSourceFromResultSet(resultSet);
770 if (eamDataSourceResult != null) {
771 dataSourceCacheByDsObjectId.put(getDataSourceByDSObjectIdCacheKey(correlationCase.
getID(), eamDataSourceResult.
getDataSourceObjectID()), eamDataSourceResult);
773 }
catch (SQLException ex) {
774 throw new EamDbException(
"Error getting data source.", ex);
781 return eamDataSourceResult;
790 public List<CorrelationDataSource> getDataSources()
throws EamDbException {
791 Connection conn = connect();
793 List<CorrelationDataSource> dataSources =
new ArrayList<>();
795 PreparedStatement preparedStatement = null;
796 ResultSet resultSet = null;
798 String sql =
"SELECT * FROM data_sources";
801 preparedStatement = conn.prepareStatement(sql);
802 resultSet = preparedStatement.executeQuery();
803 while (resultSet.next()) {
804 eamDataSourceResult = getEamDataSourceFromResultSet(resultSet);
805 dataSources.add(eamDataSourceResult);
807 }
catch (SQLException ex) {
808 throw new EamDbException(
"Error getting all data sources.", ex);
826 checkAddArtifactInstanceNulls(eamArtifact);
828 Connection conn = connect();
830 PreparedStatement preparedStatement = null;
837 +
"(case_id, data_source_id, value, file_path, known_status, comment, file_obj_id) "
838 +
"VALUES (?, ?, ?, ?, ?, ?, ?) "
839 + getConflictClause();
842 preparedStatement = conn.prepareStatement(sql);
848 preparedStatement.setString(4, eamArtifact.
getFilePath().toLowerCase());
849 preparedStatement.setByte(5, eamArtifact.
getKnownStatus().getFileKnownValue());
852 preparedStatement.setNull(6, Types.INTEGER);
854 preparedStatement.setString(6, eamArtifact.
getComment());
858 preparedStatement.executeUpdate();
861 }
catch (SQLException ex) {
862 throw new EamDbException(
"Error inserting new artifact into artifacts table.", ex);
870 if (eamArtifact == null) {
871 throw new EamDbException(
"CorrelationAttribute is null");
874 throw new EamDbException(
"Correlation type is null");
877 throw new EamDbException(
"Correlation value is null");
880 throw new EamDbException(
"Artifact value too long for central repository."
881 +
"\nCorrelationArtifact ID: " + eamArtifact.
getID()
887 throw new EamDbException(
"CorrelationAttributeInstance case is null");
890 throw new EamDbException(
"CorrelationAttributeInstance data source is null");
893 throw new EamDbException(
"CorrelationAttributeInstance known status is null");
913 Connection conn = connect();
915 List<CorrelationAttributeInstance> artifactInstances =
new ArrayList<>();
918 PreparedStatement preparedStatement = null;
919 ResultSet resultSet = null;
930 +
" cases.case_name, cases.case_uid, data_sources.id AS data_source_id, data_sources.name, device_id, file_path, known_status, comment, data_sources.case_id, data_sources.datasource_obj_id FROM "
932 +
" LEFT JOIN cases ON "
934 +
".case_id=cases.id"
935 +
" LEFT JOIN data_sources ON "
937 +
".data_source_id=data_sources.id"
941 preparedStatement = conn.prepareStatement(sql);
942 preparedStatement.setString(1, normalizedValue);
943 resultSet = preparedStatement.executeQuery();
944 while (resultSet.next()) {
945 artifactInstance = getEamArtifactInstanceFromResultSet(resultSet, aType);
946 artifactInstances.add(artifactInstance);
948 }
catch (SQLException ex) {
949 throw new EamDbException(
"Error getting artifact instances by artifactType and artifactValue.", ex);
956 return artifactInstances;
973 throw new EamDbException(
"Correlation type is null");
975 if (filePath == null) {
976 throw new EamDbException(
"Correlation value is null");
978 Connection conn = connect();
980 List<CorrelationAttributeInstance> artifactInstances =
new ArrayList<>();
983 PreparedStatement preparedStatement = null;
984 ResultSet resultSet = null;
995 +
" cases.case_name, cases.case_uid, data_sources.id AS data_source_id, data_sources.name, device_id, file_path, known_status, comment, data_sources.case_id, data_sources.datasource_obj_id FROM "
997 +
" LEFT JOIN cases ON "
999 +
".case_id=cases.id"
1000 +
" LEFT JOIN data_sources ON "
1002 +
".data_source_id=data_sources.id"
1003 +
" WHERE file_path=?";
1006 preparedStatement = conn.prepareStatement(sql);
1007 preparedStatement.setString(1, filePath.toLowerCase());
1008 resultSet = preparedStatement.executeQuery();
1009 while (resultSet.next()) {
1011 artifactInstance = getEamArtifactInstanceFromResultSet(resultSet, aType);
1012 artifactInstances.add(artifactInstance);
1014 logger.log(Level.INFO,
"Unable to get artifact instance from resultset.", ex);
1017 }
catch (SQLException ex) {
1018 throw new EamDbException(
"Error getting artifact instances by artifactType and artifactValue.", ex);
1025 return artifactInstances;
1042 Connection conn = connect();
1044 Long instanceCount = 0L;
1045 PreparedStatement preparedStatement = null;
1046 ResultSet resultSet = null;
1050 =
"SELECT count(*) FROM "
1055 preparedStatement = conn.prepareStatement(sql);
1056 preparedStatement.setString(1, normalizedValue);
1057 resultSet = preparedStatement.executeQuery();
1059 instanceCount = resultSet.getLong(1);
1060 }
catch (SQLException ex) {
1061 throw new EamDbException(
"Error getting count of artifact instances by artifactType and artifactValue.", ex);
1068 return instanceCount;
1073 if (corAttr == null) {
1074 throw new EamDbException(
"CorrelationAttribute is null");
1077 Double uniqueCaseDataSourceTuples = getCountUniqueDataSources().doubleValue();
1078 Double commonalityPercentage = uniqueTypeValueTuples / uniqueCaseDataSourceTuples * 100;
1079 return commonalityPercentage.intValue();
1096 Connection conn = connect();
1098 Long instanceCount = 0L;
1099 PreparedStatement preparedStatement = null;
1100 ResultSet resultSet = null;
1104 =
"SELECT count(*) FROM (SELECT DISTINCT case_id, data_source_id FROM "
1106 +
" WHERE value=?) AS "
1108 +
"_distinct_case_data_source_tuple";
1111 preparedStatement = conn.prepareStatement(sql);
1112 preparedStatement.setString(1, normalizedValue);
1113 resultSet = preparedStatement.executeQuery();
1115 instanceCount = resultSet.getLong(1);
1116 }
catch (SQLException ex) {
1117 throw new EamDbException(
"Error counting unique caseDisplayName/dataSource tuples having artifactType and artifactValue.", ex);
1124 return instanceCount;
1128 public Long getCountUniqueDataSources()
throws EamDbException {
1129 Connection conn = connect();
1131 Long instanceCount = 0L;
1132 PreparedStatement preparedStatement = null;
1133 ResultSet resultSet = null;
1135 String stmt =
"SELECT count(*) FROM data_sources";
1138 preparedStatement = conn.prepareStatement(stmt);
1139 resultSet = preparedStatement.executeQuery();
1141 instanceCount = resultSet.getLong(1);
1142 }
catch (SQLException ex) {
1143 throw new EamDbException(
"Error counting data sources.", ex);
1150 return instanceCount;
1165 public Long getCountArtifactInstancesByCaseDataSource(
CorrelationDataSource correlationDataSource)
throws EamDbException {
1166 Connection conn = connect();
1168 Long instanceCount = 0L;
1170 PreparedStatement preparedStatement = null;
1171 ResultSet resultSet = null;
1174 String sql =
"SELECT 0 ";
1179 +=
"+ (SELECT count(*) FROM "
1181 +
" WHERE data_source_id=" + correlationDataSource.getID() +
")";
1184 preparedStatement = conn.prepareStatement(sql);
1186 resultSet = preparedStatement.executeQuery();
1188 instanceCount = resultSet.getLong(1);
1189 }
catch (SQLException ex) {
1190 throw new EamDbException(
"Error counting artifact instances by caseName/dataSource.", ex);
1197 return instanceCount;
1211 throw new EamDbException(
"Correlation type is null");
1214 synchronized (bulkArtifacts) {
1216 bulkArtifactsCount++;
1218 if (bulkArtifactsCount >= bulkArtifactsThreshold) {
1219 commitAttributeInstancesBulk();
1229 protected abstract String getConflictClause();
1236 public void commitAttributeInstancesBulk()
throws EamDbException {
1239 Connection conn = connect();
1240 PreparedStatement bulkPs = null;
1243 synchronized (bulkArtifacts) {
1244 if (bulkArtifactsCount == 0) {
1248 for (String tableName : bulkArtifacts.keySet()) {
1253 +
" (case_id, data_source_id, value, file_path, known_status, comment, file_obj_id) "
1254 +
"VALUES ((SELECT id FROM cases WHERE case_uid=? LIMIT 1), "
1255 +
"(SELECT id FROM data_sources WHERE datasource_obj_id=? AND case_id=? LIMIT 1), ?, ?, ?, ?, ?) "
1256 + getConflictClause();
1258 bulkPs = conn.prepareStatement(sql);
1260 Collection<CorrelationAttributeInstance> eamArtifacts = bulkArtifacts.get(tableName);
1266 throw new EamDbException(
"CorrelationAttributeInstance case is null for: "
1267 +
"\n\tCorrelationArtifact ID: " + eamArtifact.
getID()
1272 throw new EamDbException(
"CorrelationAttributeInstance data source is null for: "
1273 +
"\n\tCorrelationArtifact ID: " + eamArtifact.
getID()
1278 throw new EamDbException(
"CorrelationAttributeInstance known status is null for: "
1279 +
"\n\tCorrelationArtifact ID: " + eamArtifact.
getID()
1282 +
"\n\tEam Instance: "
1293 bulkPs.setByte(6, eamArtifact.
getKnownStatus().getFileKnownValue());
1295 bulkPs.setNull(7, Types.INTEGER);
1297 bulkPs.setString(7, eamArtifact.
getComment());
1302 logger.log(Level.WARNING, (
"Artifact value too long for central repository."
1303 +
"\n\tCorrelationArtifact ID: " + eamArtifact.
getID()
1306 +
"\n\tEam Instance: "
1309 +
"\n\t\tFilePath: " + eamArtifact.
getFilePath());
1315 bulkPs.executeBatch();
1316 bulkArtifacts.get(tableName).clear();
1323 bulkArtifactsCount = 0;
1325 }
catch (SQLException ex) {
1326 throw new EamDbException(
"Error inserting bulk artifacts.", ex);
1337 public void bulkInsertCases(List<CorrelationCase> cases)
throws EamDbException {
1338 if (cases == null) {
1339 throw new EamDbException(
"cases argument is null");
1342 if (cases.isEmpty()) {
1346 Connection conn = connect();
1349 PreparedStatement bulkPs = null;
1351 String sql =
"INSERT INTO cases(case_uid, org_id, case_name, creation_date, case_number, "
1352 +
"examiner_name, examiner_email, examiner_phone, notes) "
1353 +
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) "
1354 + getConflictClause();
1355 bulkPs = conn.prepareStatement(sql);
1359 if (null == eamCase.
getOrg()) {
1360 bulkPs.setNull(2, Types.INTEGER);
1368 bulkPs.setNull(5, Types.INTEGER);
1373 bulkPs.setNull(6, Types.INTEGER);
1378 bulkPs.setNull(7, Types.INTEGER);
1383 bulkPs.setNull(8, Types.INTEGER);
1387 if (
"".equals(eamCase.
getNotes())) {
1388 bulkPs.setNull(9, Types.INTEGER);
1390 bulkPs.setString(9, eamCase.
getNotes());
1398 if (counter >= bulkArtifactsThreshold) {
1399 bulkPs.executeBatch();
1404 bulkPs.executeBatch();
1405 }
catch (SQLException ex) {
1406 throw new EamDbException(
"Error inserting bulk cases.", ex);
1425 if (eamArtifact == null) {
1426 throw new EamDbException(
"CorrelationAttributeInstance is null");
1429 throw new EamDbException(
"Correlation case is null");
1432 throw new EamDbException(
"Correlation data source is null");
1434 Connection conn = connect();
1435 PreparedStatement preparedQuery = null;
1441 +
"WHERE case_id=? "
1442 +
"AND data_source_id=? "
1444 +
"AND file_path=?";
1447 preparedQuery = conn.prepareStatement(sqlUpdate);
1448 preparedQuery.setString(1, eamArtifact.
getComment());
1452 preparedQuery.setString(5, eamArtifact.
getFilePath().toLowerCase());
1453 preparedQuery.executeUpdate();
1454 }
catch (SQLException ex) {
1455 throw new EamDbException(
"Error getting/setting artifact instance comment=" + eamArtifact.
getComment(), ex);
1480 if (correlationCase == null) {
1481 throw new EamDbException(
"Correlation case is null");
1484 Connection conn = connect();
1486 PreparedStatement preparedStatement = null;
1487 ResultSet resultSet = null;
1494 =
"SELECT id, value, file_path, known_status, comment FROM "
1496 +
" WHERE case_id=?"
1497 +
" AND file_obj_id=?";
1499 preparedStatement = conn.prepareStatement(sql);
1500 preparedStatement.setInt(1, correlationCase.
getID());
1501 preparedStatement.setInt(2, (
int) objectID);
1502 resultSet = preparedStatement.executeQuery();
1503 if (resultSet.next()) {
1504 int instanceId = resultSet.getInt(1);
1505 String value = resultSet.getString(2);
1506 String filePath = resultSet.getString(3);
1507 int knownStatus = resultSet.getInt(4);
1508 String comment = resultSet.getString(5);
1511 instanceId, correlationCase, correlationDataSource, filePath, comment, TskData.FileKnown.valueOf((byte) knownStatus), objectID);
1513 }
catch (SQLException ex) {
1514 throw new EamDbException(
"Error getting notable artifact instances.", ex);
1521 return correlationAttributeInstance;
1542 if (correlationCase == null) {
1543 throw new EamDbException(
"Correlation case is null");
1545 if (correlationDataSource == null) {
1546 throw new EamDbException(
"Correlation data source is null");
1548 if (filePath == null) {
1549 throw new EamDbException(
"Correlation file path is null");
1552 Connection conn = connect();
1554 PreparedStatement preparedStatement = null;
1555 ResultSet resultSet = null;
1563 =
"SELECT id, known_status, comment FROM "
1565 +
" WHERE case_id=?"
1566 +
" AND data_source_id=?"
1568 +
" AND file_path=?";
1570 preparedStatement = conn.prepareStatement(sql);
1571 preparedStatement.setInt(1, correlationCase.
getID());
1572 preparedStatement.setInt(2, correlationDataSource.getID());
1573 preparedStatement.setString(3, normalizedValue);
1574 preparedStatement.setString(4, filePath.toLowerCase());
1575 resultSet = preparedStatement.executeQuery();
1576 if (resultSet.next()) {
1577 int instanceId = resultSet.getInt(1);
1578 int knownStatus = resultSet.getInt(2);
1579 String comment = resultSet.getString(3);
1582 instanceId, correlationCase, correlationDataSource, filePath, comment, TskData.FileKnown.valueOf((byte) knownStatus), null);
1584 }
catch (SQLException ex) {
1585 throw new EamDbException(
"Error getting notable artifact instances.", ex);
1592 return correlationAttributeInstance;
1606 public void setAttributeInstanceKnownStatus(
CorrelationAttributeInstance eamArtifact, TskData.FileKnown knownStatus)
throws EamDbException {
1607 if (eamArtifact == null) {
1608 throw new EamDbException(
"CorrelationAttribute is null");
1610 if (knownStatus == null) {
1611 throw new EamDbException(
"Known status is null");
1615 throw new EamDbException(
"Correlation case is null");
1618 throw new EamDbException(
"Correlation data source is null");
1621 Connection conn = connect();
1623 PreparedStatement preparedUpdate = null;
1624 PreparedStatement preparedQuery = null;
1625 ResultSet resultSet = null;
1632 +
" WHERE case_id=? "
1633 +
"AND data_source_id=? "
1635 +
"AND file_path=?";
1640 +
" SET known_status=?, comment=? "
1644 preparedQuery = conn.prepareStatement(sqlQuery);
1648 preparedQuery.setString(4, eamArtifact.
getFilePath());
1649 resultSet = preparedQuery.executeQuery();
1650 if (resultSet.next()) {
1651 int instance_id = resultSet.getInt(
"id");
1652 preparedUpdate = conn.prepareStatement(sqlUpdate);
1654 preparedUpdate.setByte(1, knownStatus.getFileKnownValue());
1659 preparedUpdate.setNull(2, Types.INTEGER);
1661 preparedUpdate.setString(2, eamArtifact.
getComment());
1663 preparedUpdate.setInt(3, instance_id);
1665 preparedUpdate.executeUpdate();
1673 if (null == correlationCaseWithId) {
1680 addArtifactInstance(eamArtifact);
1683 }
catch (SQLException ex) {
1684 throw new EamDbException(
"Error getting/setting artifact instance knownStatus=" + knownStatus.getName(), ex);
1706 Connection conn = connect();
1708 List<CorrelationAttributeInstance> artifactInstances =
new ArrayList<>();
1711 PreparedStatement preparedStatement = null;
1712 ResultSet resultSet = null;
1723 +
"cases.case_name, cases.case_uid, data_sources.id AS data_source_id, data_sources.name, device_id, file_path, known_status, comment, data_sources.case_id, data_sources.datasource_obj_id FROM "
1725 +
" LEFT JOIN cases ON "
1727 +
".case_id=cases.id"
1728 +
" LEFT JOIN data_sources ON "
1730 +
".data_source_id=data_sources.id"
1731 +
" WHERE value=? AND known_status=?";
1734 preparedStatement = conn.prepareStatement(sql);
1735 preparedStatement.setString(1, normalizedValue);
1736 preparedStatement.setByte(2, TskData.FileKnown.BAD.getFileKnownValue());
1737 resultSet = preparedStatement.executeQuery();
1738 while (resultSet.next()) {
1739 artifactInstance = getEamArtifactInstanceFromResultSet(resultSet, aType);
1740 artifactInstances.add(artifactInstance);
1742 }
catch (SQLException ex) {
1743 throw new EamDbException(
"Error getting notable artifact instances.", ex);
1750 return artifactInstances;
1766 if (aType == null) {
1767 throw new EamDbException(
"Correlation type is null");
1770 Connection conn = connect();
1772 List<CorrelationAttributeInstance> artifactInstances =
new ArrayList<>();
1775 PreparedStatement preparedStatement = null;
1776 ResultSet resultSet = null;
1780 =
"SELECT cases.case_name, cases.case_uid, data_sources.name, device_id, file_path, known_status, comment, data_sources.case_id, id, value, file_obj_id, data_sources.datasource_obj_id FROM "
1782 +
" LEFT JOIN cases ON "
1784 +
".case_id=cases.id"
1785 +
" LEFT JOIN data_sources ON "
1787 +
".data_source_id=data_sources.id"
1788 +
" WHERE known_status=?"
1794 preparedStatement = conn.prepareStatement(sql);
1795 preparedStatement.setByte(1, TskData.FileKnown.BAD.getFileKnownValue());
1796 resultSet = preparedStatement.executeQuery();
1797 while (resultSet.next()) {
1799 artifactInstance = getEamArtifactInstanceFromResultSet(resultSet, aType);
1800 artifactInstances.add(artifactInstance);
1802 logger.log(Level.INFO,
"Unable to get artifact instance from resultset.", ex);
1805 }
catch (SQLException ex) {
1806 throw new EamDbException(
"Error getting notable artifact instances.", ex);
1813 return artifactInstances;
1829 Connection conn = connect();
1831 Long badInstances = 0L;
1832 PreparedStatement preparedStatement = null;
1833 ResultSet resultSet = null;
1837 =
"SELECT count(*) FROM "
1839 +
" WHERE value=? AND known_status=?";
1842 preparedStatement = conn.prepareStatement(sql);
1843 preparedStatement.setString(1, normalizedValue);
1844 preparedStatement.setByte(2, TskData.FileKnown.BAD.getFileKnownValue());
1845 resultSet = preparedStatement.executeQuery();
1847 badInstances = resultSet.getLong(1);
1848 }
catch (SQLException ex) {
1849 throw new EamDbException(
"Error getting count of notable artifact instances.", ex);
1856 return badInstances;
1876 Connection conn = connect();
1878 Collection<String> caseNames =
new LinkedHashSet<>();
1880 PreparedStatement preparedStatement = null;
1881 ResultSet resultSet = null;
1885 =
"SELECT DISTINCT case_name FROM "
1887 +
" INNER JOIN cases ON "
1889 +
".case_id=cases.id WHERE "
1893 +
".known_status=?";
1896 preparedStatement = conn.prepareStatement(sql);
1897 preparedStatement.setString(1, normalizedValue);
1898 preparedStatement.setByte(2, TskData.FileKnown.BAD.getFileKnownValue());
1899 resultSet = preparedStatement.executeQuery();
1900 while (resultSet.next()) {
1901 caseNames.add(resultSet.getString(
"case_name"));
1903 }
catch (SQLException ex) {
1904 throw new EamDbException(
"Error getting notable artifact instances.", ex);
1911 return caseNames.stream().collect(Collectors.toList());
1922 public void deleteReferenceSet(
int referenceSetID)
throws EamDbException {
1923 deleteReferenceSetEntries(referenceSetID);
1924 deleteReferenceSetEntry(referenceSetID);
1934 private void deleteReferenceSetEntry(
int referenceSetID)
throws EamDbException {
1935 Connection conn = connect();
1937 PreparedStatement preparedStatement = null;
1938 String sql =
"DELETE FROM reference_sets WHERE id=?";
1941 preparedStatement = conn.prepareStatement(sql);
1942 preparedStatement.setInt(1, referenceSetID);
1943 preparedStatement.executeUpdate();
1944 }
catch (SQLException ex) {
1945 throw new EamDbException(
"Error deleting reference set " + referenceSetID, ex);
1960 private void deleteReferenceSetEntries(
int referenceSetID)
throws EamDbException {
1961 Connection conn = connect();
1963 PreparedStatement preparedStatement = null;
1964 String sql =
"DELETE FROM %s WHERE reference_set_id=?";
1970 preparedStatement = conn.prepareStatement(String.format(sql, fileTableName));
1971 preparedStatement.setInt(1, referenceSetID);
1972 preparedStatement.executeUpdate();
1973 }
catch (SQLException ex) {
1974 throw new EamDbException(
"Error deleting files from reference set " + referenceSetID, ex);
1995 public boolean referenceSetIsValid(
int referenceSetID, String setName, String version)
throws EamDbException {
1996 EamGlobalSet refSet = this.getReferenceSetByID(referenceSetID);
1997 if (refSet == null) {
2034 Connection conn = connect();
2036 Long matchingInstances = 0L;
2037 PreparedStatement preparedStatement = null;
2038 ResultSet resultSet = null;
2039 String sql =
"SELECT count(*) FROM %s WHERE value=? AND reference_set_id=?";
2044 preparedStatement = conn.prepareStatement(String.format(sql, fileTableName));
2045 preparedStatement.setString(1, normalizeValued);
2046 preparedStatement.setInt(2, referenceSetID);
2047 resultSet = preparedStatement.executeQuery();
2049 matchingInstances = resultSet.getLong(1);
2050 }
catch (SQLException ex) {
2051 throw new EamDbException(
"Error determining if value (" + normalizeValued +
") is in reference set " + referenceSetID, ex);
2058 return 0 < matchingInstances;
2080 Connection conn = connect();
2082 Long badInstances = 0L;
2083 PreparedStatement preparedStatement = null;
2084 ResultSet resultSet = null;
2085 String sql =
"SELECT count(*) FROM %s WHERE value=? AND known_status=?";
2089 preparedStatement.setString(1, normalizeValued);
2090 preparedStatement.setByte(2, TskData.FileKnown.BAD.getFileKnownValue());
2091 resultSet = preparedStatement.executeQuery();
2093 badInstances = resultSet.getLong(1);
2094 }
catch (SQLException ex) {
2095 throw new EamDbException(
"Error determining if artifact is notable by reference.", ex);
2102 return 0 < badInstances;
2116 throw new EamDbException(
"Correlation type is null");
2119 if (instanceTableCallback == null) {
2120 throw new EamDbException(
"Callback interface is null");
2123 Connection conn = connect();
2124 PreparedStatement preparedStatement = null;
2125 ResultSet resultSet = null;
2127 StringBuilder sql =
new StringBuilder();
2128 sql.append(
"select * from ");
2129 sql.append(tableName);
2132 preparedStatement = conn.prepareStatement(sql.toString());
2133 resultSet = preparedStatement.executeQuery();
2134 instanceTableCallback.
process(resultSet);
2135 }
catch (SQLException ex) {
2136 throw new EamDbException(
"Error getting all artifact instances from instances table", ex);
2156 throw new EamDbException(
"Correlation type is null");
2159 if (instanceTableCallback == null) {
2160 throw new EamDbException(
"Callback interface is null");
2163 if (whereClause == null) {
2164 throw new EamDbException(
"Where clause is null");
2167 Connection conn = connect();
2168 PreparedStatement preparedStatement = null;
2169 ResultSet resultSet = null;
2171 StringBuilder sql =
new StringBuilder(300);
2172 sql.append(
"select * from ")
2175 .append(whereClause);
2178 preparedStatement = conn.prepareStatement(sql.toString());
2179 resultSet = preparedStatement.executeQuery();
2180 instanceTableCallback.
process(resultSet);
2181 }
catch (SQLException ex) {
2182 throw new EamDbException(
"Error getting all artifact instances from instances table", ex);
2192 if (eamOrg == null) {
2193 throw new EamDbException(
"EamOrganization is null");
2194 }
else if (eamOrg.
getOrgID() != -1) {
2195 throw new EamDbException(
"EamOrganization already has an ID");
2198 Connection conn = connect();
2199 ResultSet generatedKeys = null;
2200 PreparedStatement preparedStatement = null;
2201 String sql =
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?) "
2202 + getConflictClause();
2205 preparedStatement = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
2206 preparedStatement.setString(1, eamOrg.
getName());
2207 preparedStatement.setString(2, eamOrg.
getPocName());
2208 preparedStatement.setString(3, eamOrg.
getPocEmail());
2209 preparedStatement.setString(4, eamOrg.
getPocPhone());
2211 preparedStatement.executeUpdate();
2212 generatedKeys = preparedStatement.getGeneratedKeys();
2213 if (generatedKeys.next()) {
2214 eamOrg.setOrgID((
int) generatedKeys.getLong(1));
2217 throw new SQLException(
"Creating user failed, no ID obtained.");
2219 }
catch (SQLException ex) {
2220 throw new EamDbException(
"Error inserting new organization.", ex);
2236 public List<EamOrganization> getOrganizations()
throws EamDbException {
2237 Connection conn = connect();
2239 List<EamOrganization> orgs =
new ArrayList<>();
2240 PreparedStatement preparedStatement = null;
2241 ResultSet resultSet = null;
2242 String sql =
"SELECT * FROM organizations";
2245 preparedStatement = conn.prepareStatement(sql);
2246 resultSet = preparedStatement.executeQuery();
2247 while (resultSet.next()) {
2248 orgs.add(getEamOrganizationFromResultSet(resultSet));
2252 }
catch (SQLException ex) {
2253 throw new EamDbException(
"Error getting all organizations.", ex);
2271 public EamOrganization getOrganizationByID(
int orgID)
throws EamDbException {
2272 Connection conn = connect();
2274 PreparedStatement preparedStatement = null;
2275 ResultSet resultSet = null;
2276 String sql =
"SELECT * FROM organizations WHERE id=?";
2279 preparedStatement = conn.prepareStatement(sql);
2280 preparedStatement.setInt(1, orgID);
2281 resultSet = preparedStatement.executeQuery();
2283 return getEamOrganizationFromResultSet(resultSet);
2285 }
catch (SQLException ex) {
2286 throw new EamDbException(
"Error getting organization by id.", ex);
2304 public EamOrganization getReferenceSetOrganization(
int referenceSetID)
throws EamDbException {
2306 EamGlobalSet globalSet = getReferenceSetByID(referenceSetID);
2307 if (globalSet == null) {
2308 throw new EamDbException(
"Reference set with ID " + referenceSetID +
" not found");
2310 return (getOrganizationByID(globalSet.
getOrgID()));
2322 throw new EamDbException(
"EamOrganization is null");
2324 throw new EamDbException(
"Organization has -1 row ID");
2337 public void updateOrganization(
EamOrganization updatedOrganization)
throws EamDbException {
2338 testArgument(updatedOrganization);
2340 Connection conn = connect();
2341 PreparedStatement preparedStatement = null;
2342 String sql =
"UPDATE organizations SET org_name = ?, poc_name = ?, poc_email = ?, poc_phone = ? WHERE id = ?";
2344 preparedStatement = conn.prepareStatement(sql);
2345 preparedStatement.setString(1, updatedOrganization.
getName());
2346 preparedStatement.setString(2, updatedOrganization.
getPocName());
2347 preparedStatement.setString(3, updatedOrganization.
getPocEmail());
2348 preparedStatement.setString(4, updatedOrganization.
getPocPhone());
2349 preparedStatement.setInt(5, updatedOrganization.
getOrgID());
2350 preparedStatement.executeUpdate();
2351 }
catch (SQLException ex) {
2352 throw new EamDbException(
"Error updating organization.", ex);
2360 public void deleteOrganization(
EamOrganization organizationToDelete)
throws EamDbException {
2361 testArgument(organizationToDelete);
2363 Connection conn = connect();
2364 PreparedStatement checkIfUsedStatement = null;
2365 ResultSet resultSet = null;
2366 String checkIfUsedSql =
"SELECT (select count(*) FROM cases WHERE org_id=?) + (select count(*) FROM reference_sets WHERE org_id=?)";
2367 PreparedStatement deleteOrgStatement = null;
2368 String deleteOrgSql =
"DELETE FROM organizations WHERE id=?";
2370 checkIfUsedStatement = conn.prepareStatement(checkIfUsedSql);
2371 checkIfUsedStatement.setInt(1, organizationToDelete.
getOrgID());
2372 checkIfUsedStatement.setInt(2, organizationToDelete.
getOrgID());
2373 resultSet = checkIfUsedStatement.executeQuery();
2375 if (resultSet.getLong(1) > 0) {
2376 throw new EamDbException(
"Can not delete organization which is currently in use by a case or reference set in the central repository.");
2378 deleteOrgStatement = conn.prepareStatement(deleteOrgSql);
2379 deleteOrgStatement.setInt(1, organizationToDelete.
getOrgID());
2380 deleteOrgStatement.executeUpdate();
2381 }
catch (SQLException ex) {
2382 throw new EamDbException(
"Error executing query when attempting to delete organization by id.", ex);
2401 public int newReferenceSet(
EamGlobalSet eamGlobalSet)
throws EamDbException {
2402 if (eamGlobalSet == null) {
2403 throw new EamDbException(
"EamGlobalSet is null");
2407 throw new EamDbException(
"File known status on the EamGlobalSet is null");
2410 if (eamGlobalSet.
getType() == null) {
2411 throw new EamDbException(
"Type on the EamGlobalSet is null");
2414 Connection conn = connect();
2416 PreparedStatement preparedStatement1 = null;
2417 PreparedStatement preparedStatement2 = null;
2418 ResultSet resultSet = null;
2419 String sql1 =
"INSERT INTO reference_sets(org_id, set_name, version, known_status, read_only, type, import_date) VALUES (?, ?, ?, ?, ?, ?, ?) "
2420 + getConflictClause();
2421 String sql2 =
"SELECT id FROM reference_sets WHERE org_id=? AND set_name=? AND version=? AND import_date=? LIMIT 1";
2424 preparedStatement1 = conn.prepareStatement(sql1);
2425 preparedStatement1.setInt(1, eamGlobalSet.
getOrgID());
2426 preparedStatement1.setString(2, eamGlobalSet.
getSetName());
2427 preparedStatement1.setString(3, eamGlobalSet.
getVersion());
2429 preparedStatement1.setBoolean(5, eamGlobalSet.
isReadOnly());
2430 preparedStatement1.setInt(6, eamGlobalSet.
getType().getId());
2431 preparedStatement1.setString(7, eamGlobalSet.
getImportDate().toString());
2433 preparedStatement1.executeUpdate();
2435 preparedStatement2 = conn.prepareStatement(sql2);
2436 preparedStatement2.setInt(1, eamGlobalSet.
getOrgID());
2437 preparedStatement2.setString(2, eamGlobalSet.
getSetName());
2438 preparedStatement2.setString(3, eamGlobalSet.
getVersion());
2439 preparedStatement2.setString(4, eamGlobalSet.
getImportDate().toString());
2441 resultSet = preparedStatement2.executeQuery();
2443 return resultSet.getInt(
"id");
2445 }
catch (SQLException ex) {
2446 throw new EamDbException(
"Error inserting new global set.", ex);
2465 public EamGlobalSet getReferenceSetByID(
int referenceSetID)
throws EamDbException {
2466 Connection conn = connect();
2468 PreparedStatement preparedStatement1 = null;
2469 ResultSet resultSet = null;
2470 String sql1 =
"SELECT * FROM reference_sets WHERE id=?";
2473 preparedStatement1 = conn.prepareStatement(sql1);
2474 preparedStatement1.setInt(1, referenceSetID);
2475 resultSet = preparedStatement1.executeQuery();
2476 if (resultSet.next()) {
2477 return getEamGlobalSetFromResultSet(resultSet);
2482 }
catch (SQLException ex) {
2483 throw new EamDbException(
"Error getting reference set by id.", ex);
2503 if (correlationType == null) {
2504 throw new EamDbException(
"Correlation type is null");
2507 List<EamGlobalSet> results =
new ArrayList<>();
2508 Connection conn = connect();
2510 PreparedStatement preparedStatement1 = null;
2511 ResultSet resultSet = null;
2512 String sql1 =
"SELECT * FROM reference_sets WHERE type=" + correlationType.getId();
2515 preparedStatement1 = conn.prepareStatement(sql1);
2516 resultSet = preparedStatement1.executeQuery();
2517 while (resultSet.next()) {
2518 results.add(getEamGlobalSetFromResultSet(resultSet));
2521 }
catch (SQLException ex) {
2522 throw new EamDbException(
"Error getting reference sets.", ex);
2543 throw new EamDbException(
"Known status of EamGlobalFileInstance is null");
2545 if (correlationType == null) {
2546 throw new EamDbException(
"Correlation type is null");
2549 Connection conn = connect();
2551 PreparedStatement preparedStatement = null;
2553 String sql =
"INSERT INTO %s(reference_set_id, value, known_status, comment) VALUES (?, ?, ?, ?) "
2554 + getConflictClause();
2558 preparedStatement.setInt(1, eamGlobalFileInstance.
getGlobalSetID());
2559 preparedStatement.setString(2, eamGlobalFileInstance.
getMD5Hash());
2560 preparedStatement.setByte(3, eamGlobalFileInstance.
getKnownStatus().getFileKnownValue());
2561 preparedStatement.setString(4, eamGlobalFileInstance.
getComment());
2562 preparedStatement.executeUpdate();
2563 }
catch (SQLException ex) {
2564 throw new EamDbException(
"Error inserting new reference instance into reference_ table.", ex);
2584 public boolean referenceSetExists(String referenceSetName, String version)
throws EamDbException {
2585 Connection conn = connect();
2587 PreparedStatement preparedStatement1 = null;
2588 ResultSet resultSet = null;
2589 String sql1 =
"SELECT * FROM reference_sets WHERE set_name=? AND version=?";
2592 preparedStatement1 = conn.prepareStatement(sql1);
2593 preparedStatement1.setString(1, referenceSetName);
2594 preparedStatement1.setString(2, version);
2595 resultSet = preparedStatement1.executeQuery();
2596 return (resultSet.next());
2598 }
catch (SQLException ex) {
2599 throw new EamDbException(
"Error testing whether reference set exists (name: " + referenceSetName
2600 +
" version: " + version, ex);
2614 public void bulkInsertReferenceTypeEntries(Set<EamGlobalFileInstance> globalInstances,
CorrelationAttributeInstance.
Type contentType)
throws EamDbException {
2615 if (contentType == null) {
2616 throw new EamDbException(
"Correlation type is null");
2618 if (globalInstances == null) {
2619 throw new EamDbException(
"Null set of EamGlobalFileInstance");
2622 Connection conn = connect();
2624 PreparedStatement bulkPs = null;
2626 conn.setAutoCommit(
false);
2629 String sql =
"INSERT INTO %s(reference_set_id, value, known_status, comment) VALUES (?, ?, ?, ?) "
2630 + getConflictClause();
2635 if (globalInstance.getKnownStatus() == null) {
2636 throw new EamDbException(
"EamGlobalFileInstance with value " + globalInstance.getMD5Hash() +
" has null known status");
2639 bulkPs.setInt(1, globalInstance.getGlobalSetID());
2640 bulkPs.setString(2, globalInstance.getMD5Hash());
2641 bulkPs.setByte(3, globalInstance.getKnownStatus().getFileKnownValue());
2642 bulkPs.setString(4, globalInstance.getComment());
2646 bulkPs.executeBatch();
2648 }
catch (SQLException | EamDbException ex) {
2651 }
catch (SQLException ex2) {
2654 throw new EamDbException(
"Error inserting bulk artifacts.", ex);
2675 Connection conn = connect();
2677 List<EamGlobalFileInstance> globalFileInstances =
new ArrayList<>();
2678 PreparedStatement preparedStatement1 = null;
2679 ResultSet resultSet = null;
2680 String sql1 =
"SELECT * FROM %s WHERE value=?";
2684 preparedStatement1.setString(1, normalizeValued);
2685 resultSet = preparedStatement1.executeQuery();
2686 while (resultSet.next()) {
2687 globalFileInstances.add(getEamGlobalFileInstanceFromResultSet(resultSet));
2690 }
catch (SQLException ex) {
2691 throw new EamDbException(
"Error getting reference instances by type and value.", ex);
2698 return globalFileInstances;
2712 if (newType == null) {
2713 throw new EamDbException(
"Correlation type is null");
2716 if (-1 == newType.getId()) {
2717 typeId = newCorrelationTypeNotKnownId(newType);
2719 typeId = newCorrelationTypeKnownId(newType);
2736 Connection conn = connect();
2738 PreparedStatement preparedStatement = null;
2739 PreparedStatement preparedStatementQuery = null;
2740 ResultSet resultSet = null;
2745 insertSql =
"INSERT INTO correlation_types(display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?) " + getConflictClause();
2747 querySql =
"SELECT * FROM correlation_types WHERE display_name=? AND db_table_name=?";
2750 preparedStatement = conn.prepareStatement(insertSql);
2752 preparedStatement.setString(1, newType.getDisplayName());
2753 preparedStatement.setString(2, newType.getDbTableName());
2754 preparedStatement.setInt(3, newType.isSupported() ? 1 : 0);
2755 preparedStatement.setInt(4, newType.isEnabled() ? 1 : 0);
2757 preparedStatement.executeUpdate();
2759 preparedStatementQuery = conn.prepareStatement(querySql);
2760 preparedStatementQuery.setString(1, newType.getDisplayName());
2761 preparedStatementQuery.setString(2, newType.getDbTableName());
2763 resultSet = preparedStatementQuery.executeQuery();
2764 if (resultSet.next()) {
2766 typeId = correlationType.getId();
2768 }
catch (SQLException ex) {
2769 throw new EamDbException(
"Error inserting new correlation type.", ex);
2789 Connection conn = connect();
2791 PreparedStatement preparedStatement = null;
2792 PreparedStatement preparedStatementQuery = null;
2793 ResultSet resultSet = null;
2798 insertSql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?) " + getConflictClause();
2800 querySql =
"SELECT * FROM correlation_types WHERE display_name=? AND db_table_name=?";
2803 preparedStatement = conn.prepareStatement(insertSql);
2805 preparedStatement.setInt(1, newType.getId());
2806 preparedStatement.setString(2, newType.getDisplayName());
2807 preparedStatement.setString(3, newType.getDbTableName());
2808 preparedStatement.setInt(4, newType.isSupported() ? 1 : 0);
2809 preparedStatement.setInt(5, newType.isEnabled() ? 1 : 0);
2811 preparedStatement.executeUpdate();
2813 preparedStatementQuery = conn.prepareStatement(querySql);
2814 preparedStatementQuery.setString(1, newType.getDisplayName());
2815 preparedStatementQuery.setString(2, newType.getDbTableName());
2817 resultSet = preparedStatementQuery.executeQuery();
2818 if (resultSet.next()) {
2820 typeId = correlationType.getId();
2822 }
catch (SQLException ex) {
2823 throw new EamDbException(
"Error inserting new correlation type.", ex);
2835 Connection conn = connect();
2838 PreparedStatement preparedStatement = null;
2839 ResultSet resultSet = null;
2840 String sql =
"SELECT * FROM correlation_types";
2843 preparedStatement = conn.prepareStatement(sql);
2844 resultSet = preparedStatement.executeQuery();
2845 while (resultSet.next()) {
2846 aTypes.add(getCorrelationTypeFromResultSet(resultSet));
2850 }
catch (SQLException ex) {
2851 throw new EamDbException(
"Error getting all correlation types.", ex);
2870 Connection conn = connect();
2873 PreparedStatement preparedStatement = null;
2874 ResultSet resultSet = null;
2875 String sql =
"SELECT * FROM correlation_types WHERE enabled=1";
2878 preparedStatement = conn.prepareStatement(sql);
2879 resultSet = preparedStatement.executeQuery();
2880 while (resultSet.next()) {
2881 aTypes.add(getCorrelationTypeFromResultSet(resultSet));
2885 }
catch (SQLException ex) {
2886 throw new EamDbException(
"Error getting enabled correlation types.", ex);
2905 Connection conn = connect();
2908 PreparedStatement preparedStatement = null;
2909 ResultSet resultSet = null;
2910 String sql =
"SELECT * FROM correlation_types WHERE supported=1";
2913 preparedStatement = conn.prepareStatement(sql);
2914 resultSet = preparedStatement.executeQuery();
2915 while (resultSet.next()) {
2916 aTypes.add(getCorrelationTypeFromResultSet(resultSet));
2920 }
catch (SQLException ex) {
2921 throw new EamDbException(
"Error getting supported correlation types.", ex);
2938 Connection conn = connect();
2940 PreparedStatement preparedStatement = null;
2941 String sql =
"UPDATE correlation_types SET display_name=?, db_table_name=?, supported=?, enabled=? WHERE id=?";
2944 preparedStatement = conn.prepareStatement(sql);
2945 preparedStatement.setString(1, aType.getDisplayName());
2946 preparedStatement.setString(2, aType.getDbTableName());
2947 preparedStatement.setInt(3, aType.isSupported() ? 1 : 0);
2948 preparedStatement.setInt(4, aType.isEnabled() ? 1 : 0);
2949 preparedStatement.setInt(5, aType.getId());
2950 preparedStatement.executeUpdate();
2951 typeCache.put(aType.getId(), aType);
2952 }
catch (SQLException ex) {
2953 throw new EamDbException(
"Error updating correlation type.", ex);
2973 return typeCache.get(typeId, () -> getCorrelationTypeByIdFromCr(typeId));
2974 }
catch (CacheLoader.InvalidCacheLoadException ignored) {
2977 }
catch (ExecutionException ex) {
2978 throw new EamDbException(
"Error getting correlation type", ex);
2992 Connection conn = connect();
2995 PreparedStatement preparedStatement = null;
2996 ResultSet resultSet = null;
2997 String sql =
"SELECT * FROM correlation_types WHERE id=?";
3000 preparedStatement = conn.prepareStatement(sql);
3001 preparedStatement.setInt(1, typeId);
3002 resultSet = preparedStatement.executeQuery();
3003 if (resultSet.next()) {
3004 aType = getCorrelationTypeFromResultSet(resultSet);
3007 throw new EamDbException(
"Failed to find entry for correlation type ID = " + typeId);
3010 }
catch (SQLException ex) {
3011 throw new EamDbException(
"Error getting correlation type by id.", ex);
3029 private CorrelationCase getEamCaseFromResultSet(ResultSet resultSet)
throws SQLException {
3030 if (null == resultSet) {
3036 resultSet.getInt(
"org_id");
3037 if (!resultSet.wasNull()) {
3040 resultSet.getString(
"org_name"),
3041 resultSet.getString(
"poc_name"),
3042 resultSet.getString(
"poc_email"),
3043 resultSet.getString(
"poc_phone"));
3046 CorrelationCase eamCase =
new CorrelationCase(resultSet.getInt(
"case_id"), resultSet.getString(
"case_uid"), eamOrg, resultSet.getString(
"case_name"),
3047 resultSet.getString(
"creation_date"), resultSet.getString(
"case_number"), resultSet.getString(
"examiner_name"),
3048 resultSet.getString(
"examiner_email"), resultSet.getString(
"examiner_phone"), resultSet.getString(
"notes"));
3053 private CorrelationDataSource getEamDataSourceFromResultSet(ResultSet resultSet)
throws SQLException {
3054 if (null == resultSet) {
3059 resultSet.getInt(
"case_id"),
3060 resultSet.getInt(
"id"),
3061 resultSet.getString(
"device_id"),
3062 resultSet.getString(
"name"),
3063 resultSet.getLong(
"datasource_obj_id")
3066 return eamDataSource;
3070 if (null == resultSet) {
3075 resultSet.getInt(
"id"),
3076 resultSet.getString(
"display_name"),
3077 resultSet.getString(
"db_table_name"),
3078 resultSet.getBoolean(
"supported"),
3079 resultSet.getBoolean(
"enabled")
3082 return eamArtifactType;
3096 if (null == resultSet) {
3101 resultSet.getString(
"value"),
3102 resultSet.getInt(
"id"),
3103 new CorrelationCase(resultSet.getInt(
"case_id"), resultSet.getString(
"case_uid"), resultSet.getString(
"case_name")),
3104 new CorrelationDataSource(resultSet.getInt(
"case_id"), resultSet.getInt(
"data_source_id"), resultSet.getString(
"device_id"), resultSet.getString(
"name"), resultSet.getLong(
"datasource_obj_id")),
3105 resultSet.getString(
"file_path"),
3106 resultSet.getString(
"comment"),
3107 TskData.FileKnown.valueOf(resultSet.getByte(
"known_status")),
3108 resultSet.getLong(
"file_obj_id"));
3111 private EamOrganization getEamOrganizationFromResultSet(ResultSet resultSet)
throws SQLException {
3112 if (null == resultSet) {
3117 resultSet.getInt(
"id"),
3118 resultSet.getString(
"org_name"),
3119 resultSet.getString(
"poc_name"),
3120 resultSet.getString(
"poc_email"),
3121 resultSet.getString(
"poc_phone")
3125 private EamGlobalSet getEamGlobalSetFromResultSet(ResultSet resultSet)
throws SQLException, EamDbException {
3126 if (null == resultSet) {
3131 resultSet.getInt(
"id"),
3132 resultSet.getInt(
"org_id"),
3133 resultSet.getString(
"set_name"),
3134 resultSet.getString(
"version"),
3135 TskData.FileKnown.valueOf(resultSet.getByte(
"known_status")),
3136 resultSet.getBoolean(
"read_only"),
3138 LocalDate.parse(resultSet.getString(
"import_date"))
3143 if (null == resultSet) {
3148 resultSet.getInt(
"id"),
3149 resultSet.getInt(
"reference_set_id"),
3150 resultSet.getString(
"value"),
3151 TskData.FileKnown.valueOf(resultSet.getByte(
"known_status")),
3152 resultSet.getString(
"comment")
3166 abstract boolean doesColumnExist(Connection conn, String tableName, String columnName)
throws SQLException;
3174 public void upgradeSchema()
throws EamDbException, SQLException {
3176 ResultSet resultSet = null;
3177 Statement statement = null;
3178 PreparedStatement preparedStatement = null;
3179 Connection conn = null;
3183 conn.setAutoCommit(
false);
3184 statement = conn.createStatement();
3186 int minorVersion = 0;
3187 String minorVersionStr = null;
3188 resultSet = statement.executeQuery(
"SELECT value FROM db_info WHERE name='" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY +
"'");
3189 if (resultSet.next()) {
3190 minorVersionStr = resultSet.getString(
"value");
3192 minorVersion = Integer.parseInt(minorVersionStr);
3193 }
catch (NumberFormatException ex) {
3194 throw new EamDbException(
"Bad value for schema minor version (" + minorVersionStr +
") - database is corrupt", ex);
3197 throw new EamDbException(
"Failed to read schema minor version from db_info table");
3200 int majorVersion = 0;
3201 String majorVersionStr = null;
3202 resultSet = statement.executeQuery(
"SELECT value FROM db_info WHERE name='" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY +
"'");
3203 if (resultSet.next()) {
3204 majorVersionStr = resultSet.getString(
"value");
3206 majorVersion = Integer.parseInt(majorVersionStr);
3207 }
catch (NumberFormatException ex) {
3208 throw new EamDbException(
"Bad value for schema version (" + majorVersionStr +
") - database is corrupt", ex);
3211 throw new EamDbException(
"Failed to read schema major version from db_info table");
3222 CaseDbSchemaVersionNumber dbSchemaVersion =
new CaseDbSchemaVersionNumber(majorVersion, minorVersion);
3223 if (dbSchemaVersion.equals(CURRENT_DB_SCHEMA_VERSION)) {
3224 logger.log(Level.INFO,
"Central Repository is up to date");
3227 if (dbSchemaVersion.compareTo(CURRENT_DB_SCHEMA_VERSION) > 0) {
3228 logger.log(Level.INFO,
"Central Repository is of newer version than software creates");
3237 if (dbSchemaVersion.compareTo(
new CaseDbSchemaVersionNumber(1, 1)) < 0) {
3238 statement.execute(
"ALTER TABLE reference_sets ADD COLUMN known_status INTEGER;");
3239 statement.execute(
"ALTER TABLE reference_sets ADD COLUMN read_only BOOLEAN;");
3240 statement.execute(
"ALTER TABLE reference_sets ADD COLUMN type INTEGER;");
3245 EamDbUtil.insertDefaultOrganization(conn);
3251 if (dbSchemaVersion.compareTo(
new CaseDbSchemaVersionNumber(1, 2)) < 0) {
3252 final String addIntegerColumnTemplate =
"ALTER TABLE %s ADD COLUMN %s INTEGER;";
3253 final String addSsidTableTemplate;
3254 final String addCaseIdIndexTemplate;
3255 final String addDataSourceIdIndexTemplate;
3256 final String addValueIndexTemplate;
3257 final String addKnownStatusIndexTemplate;
3258 final String addObjectIdIndexTemplate;
3260 final String addAttributeSql;
3262 switch (selectedPlatform) {
3264 addAttributeSql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?) " + getConflictClause();
3274 addAttributeSql =
"INSERT OR IGNORE INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
3284 throw new EamDbException(
"Currently selected database platform \"" + selectedPlatform.name() +
"\" can not be upgraded.");
3286 final String dataSourcesTableName =
"data_sources";
3287 final String dataSourceObjectIdColumnName =
"datasource_obj_id";
3288 if (!doesColumnExist(conn, dataSourcesTableName, dataSourceObjectIdColumnName)) {
3289 statement.execute(String.format(addIntegerColumnTemplate, dataSourcesTableName, dataSourceObjectIdColumnName));
3291 final String dataSourceObjectIdIndexTemplate =
"CREATE INDEX IF NOT EXISTS datasource_object_id ON data_sources (%s)";
3292 statement.execute(String.format(dataSourceObjectIdIndexTemplate, dataSourceObjectIdColumnName));
3293 List<String> instaceTablesToAdd =
new ArrayList<>();
3295 final String wirelessNetworksDbTableName =
"wireless_networks";
3296 instaceTablesToAdd.add(wirelessNetworksDbTableName +
"_instances");
3297 final String macAddressDbTableName =
"mac_address";
3298 instaceTablesToAdd.add(macAddressDbTableName +
"_instances");
3299 final String imeiNumberDbTableName =
"imei_number";
3300 instaceTablesToAdd.add(imeiNumberDbTableName +
"_instances");
3301 final String iccidNumberDbTableName =
"iccid_number";
3302 instaceTablesToAdd.add(iccidNumberDbTableName +
"_instances");
3303 final String imsiNumberDbTableName =
"imsi_number";
3304 instaceTablesToAdd.add(imsiNumberDbTableName +
"_instances");
3307 preparedStatement = conn.prepareStatement(addAttributeSql);
3309 preparedStatement.setString(2, Bundle.CorrelationType_SSID_displayName());
3310 preparedStatement.setString(3, wirelessNetworksDbTableName);
3311 preparedStatement.setInt(4, 1);
3312 preparedStatement.setInt(5, 1);
3313 preparedStatement.execute();
3316 preparedStatement = conn.prepareStatement(addAttributeSql);
3318 preparedStatement.setString(2, Bundle.CorrelationType_MAC_displayName());
3319 preparedStatement.setString(3, macAddressDbTableName);
3320 preparedStatement.setInt(4, 1);
3321 preparedStatement.setInt(5, 1);
3322 preparedStatement.execute();
3325 preparedStatement = conn.prepareStatement(addAttributeSql);
3327 preparedStatement.setString(2, Bundle.CorrelationType_IMEI_displayName());
3328 preparedStatement.setString(3, imeiNumberDbTableName);
3329 preparedStatement.setInt(4, 1);
3330 preparedStatement.setInt(5, 1);
3331 preparedStatement.execute();
3334 preparedStatement = conn.prepareStatement(addAttributeSql);
3336 preparedStatement.setString(2, Bundle.CorrelationType_IMSI_displayName());
3337 preparedStatement.setString(3, imsiNumberDbTableName);
3338 preparedStatement.setInt(4, 1);
3339 preparedStatement.setInt(5, 1);
3340 preparedStatement.execute();
3343 preparedStatement = conn.prepareStatement(addAttributeSql);
3345 preparedStatement.setString(2, Bundle.CorrelationType_ICCID_displayName());
3346 preparedStatement.setString(3, iccidNumberDbTableName);
3347 preparedStatement.setInt(4, 1);
3348 preparedStatement.setInt(5, 1);
3349 preparedStatement.execute();
3352 for (String tableName : instaceTablesToAdd) {
3353 statement.execute(String.format(addSsidTableTemplate, tableName, tableName));
3354 statement.execute(String.format(addCaseIdIndexTemplate, tableName, tableName));
3355 statement.execute(String.format(addDataSourceIdIndexTemplate, tableName, tableName));
3356 statement.execute(String.format(addValueIndexTemplate, tableName, tableName));
3357 statement.execute(String.format(addKnownStatusIndexTemplate, tableName, tableName));
3361 String instance_type_dbname;
3362 final String objectIdColumnName =
"file_obj_id";
3365 if (!doesColumnExist(conn, instance_type_dbname, objectIdColumnName)) {
3366 statement.execute(String.format(addIntegerColumnTemplate, instance_type_dbname, objectIdColumnName));
3368 statement.execute(String.format(addObjectIdIndexTemplate, instance_type_dbname, instance_type_dbname));
3374 if (!doesColumnExist(conn, dataSourcesTableName,
"md5")) {
3375 statement.execute(
"ALTER TABLE data_sources ADD COLUMN md5 TEXT DEFAULT NULL");
3377 if (!doesColumnExist(conn, dataSourcesTableName,
"sha1")) {
3378 statement.execute(
"ALTER TABLE data_sources ADD COLUMN sha1 TEXT DEFAULT NULL");
3380 if (!doesColumnExist(conn, dataSourcesTableName,
"sha256")) {
3381 statement.execute(
"ALTER TABLE data_sources ADD COLUMN sha256 TEXT DEFAULT NULL");
3392 String creationMajorVer;
3393 resultSet = statement.executeQuery(
"SELECT value FROM db_info WHERE name = '" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY +
"'");
3394 if (resultSet.next()) {
3395 creationMajorVer = resultSet.getString(
"value");
3397 creationMajorVer =
"0";
3399 String creationMinorVer;
3400 resultSet = statement.executeQuery(
"SELECT value FROM db_info WHERE name = '" + AbstractSqlEamDb.CREATION_SCHEMA_MINOR_VERSION_KEY +
"'");
3401 if (resultSet.next()) {
3402 creationMinorVer = resultSet.getString(
"value");
3404 creationMinorVer =
"0";
3406 statement.execute(
"DROP TABLE db_info");
3408 statement.execute(
"CREATE TABLE db_info (id SERIAL, name TEXT UNIQUE NOT NULL, value TEXT NOT NULL)");
3410 statement.execute(
"CREATE TABLE db_info (id INTEGER PRIMARY KEY, name TEXT UNIQUE NOT NULL, value TEXT NOT NULL)");
3412 statement.execute(
"INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY +
"','" + majorVersionStr +
"')");
3413 statement.execute(
"INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY +
"','" + minorVersionStr +
"')");
3414 statement.execute(
"INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY +
"','" + creationMajorVer +
"')");
3415 statement.execute(
"INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MINOR_VERSION_KEY +
"','" + creationMinorVer +
"')");
3418 updateSchemaVersion(conn);
3420 logger.log(Level.INFO, String.format(
"Central Repository schema updated to version %s", CURRENT_DB_SCHEMA_VERSION));
3422 }
catch (SQLException | EamDbException ex) {
3427 }
catch (SQLException ex2) {
3428 logger.log(Level.SEVERE, String.format(
"Central Repository rollback of failed schema update to %s failed", CURRENT_DB_SCHEMA_VERSION), ex2);
TskData.FileKnown getKnownStatus()
String getExaminerPhone()
CorrelationAttributeInstance.Type getType()
static String correlationTypeToInstanceTableName(CorrelationAttributeInstance.Type type)
static final int ICCID_TYPE_ID
static void closeResultSet(ResultSet resultSet)
static void closeStatement(Statement statement)
static List< CorrelationAttributeInstance.Type > getDefaultCorrelationTypes()
String getCorrelationValue()
static final int IMEI_TYPE_ID
static TimingMetric getTimingMetric(String name)
TskData.FileKnown getKnownStatus()
void process(ResultSet resultSet)
Type getCorrelationType()
static String normalize(CorrelationAttributeInstance.Type attributeType, String data)
static EamDb getInstance()
static void closeConnection(Connection conn)
void setKnownStatus(TskData.FileKnown knownStatus)
CorrelationAttributeInstance.Type getCorrelationTypeById(int typeId)
TskData.FileKnown getFileKnownStatus()
CorrelationDataSource getCorrelationDataSource()
String getExaminerEmail()
LocalDate getImportDate()
String getExaminerPhone()
static final int MAC_TYPE_ID
Long getDataSourceObjectID()
static void submitTimingMetric(TimingMetric metric)
static final int IMSI_TYPE_ID
synchronized static Logger getLogger(String name)
CorrelationCase getCorrelationCase()
static String correlationTypeToReferenceTableName(CorrelationAttributeInstance.Type type)
static EamOrganization getDefault()
static final int SSID_TYPE_ID
static final int FILES_TYPE_ID
String getExaminerEmail()