19 package org.sleuthkit.autopsy.centralrepository.datamodel;
21 import java.sql.Connection;
22 import java.sql.PreparedStatement;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
25 import java.sql.Statement;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.logging.Level;
29 import javax.swing.SwingUtilities;
30 import org.openide.windows.TopComponent;
31 import org.openide.windows.WindowManager;
55 if (null != statement) {
58 }
catch (SQLException ex) {
59 LOGGER.log(Level.SEVERE,
"Error closing Statement.", ex);
72 if (null != resultSet) {
75 }
catch (SQLException ex) {
76 LOGGER.log(Level.SEVERE,
"Error closing ResultSet.", ex);
92 }
catch (SQLException ex) {
93 LOGGER.log(Level.SEVERE,
"Error closing Connection.", ex);
106 PreparedStatement preparedStatement = null;
107 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
111 preparedStatement = conn.prepareStatement(sql);
113 preparedStatement.setInt(1, newType.getId());
114 preparedStatement.setString(2, newType.getDisplayName());
115 preparedStatement.setString(3, newType.getDbTableName());
116 preparedStatement.setInt(4, newType.isSupported() ? 1 : 0);
117 preparedStatement.setInt(5, newType.isEnabled() ? 1 : 0);
119 preparedStatement.addBatch();
121 preparedStatement.executeBatch();
123 LOGGER.log(Level.SEVERE,
"Error inserting default correlation types.", ex);
140 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
141 try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
143 preparedStatement.setInt(1, correlationType.getId());
144 preparedStatement.setString(2, correlationType.getDisplayName());
145 preparedStatement.setString(3, correlationType.getDbTableName());
146 preparedStatement.setInt(4, correlationType.isSupported() ? 1 : 0);
147 preparedStatement.setInt(5, correlationType.isEnabled() ? 1 : 0);
149 preparedStatement.execute();
160 static void updateSchemaVersion(Connection conn)
throws SQLException {
161 try (Statement statement = conn.createStatement()) {
162 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() +
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MAJOR_VERSION_KEY +
"'");
163 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() +
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MINOR_VERSION_KEY +
"'");
177 ResultSet resultSet = null;
179 Statement tester = conn.createStatement();
180 String sql =
"SELECT value FROM db_info WHERE name='SCHEMA_VERSION'";
181 resultSet = tester.executeQuery(sql);
182 if (resultSet.next()) {
183 String value = resultSet.getString(
"value");
185 }
catch (SQLException ex) {
210 return DEFAULT_ORG_NAME.equals(org.
getName());
220 static boolean insertDefaultOrganization(Connection conn) {
225 PreparedStatement preparedStatement = null;
226 String sql =
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
228 preparedStatement = conn.prepareStatement(sql);
229 preparedStatement.setString(1, DEFAULT_ORG_NAME);
230 preparedStatement.setString(2,
"");
231 preparedStatement.setString(3,
"");
232 preparedStatement.setString(4,
"");
233 preparedStatement.executeUpdate();
234 }
catch (SQLException ex) {
235 LOGGER.log(Level.SEVERE,
"Error adding default organization", ex);
238 CentralRepoDbUtil.closePreparedStatement(preparedStatement);
274 SwingUtilities.invokeLater(() -> {
275 TopComponent personasWindow = WindowManager.getDefault().findTopComponent(
"PersonasTopComponent");
276 if (personasWindow != null && personasWindow.isOpened()) {
277 personasWindow.close();
293 ResultSet resultSet = null;
295 Statement tester = conn.createStatement();
296 resultSet = tester.executeQuery(validationQuery);
297 if (resultSet.next()) {
300 }
catch (SQLException ex) {
317 return type.getDbTableName() +
"_instances";
328 return "reference_" + type.getDbTableName();
374 boolean commentExists =
false;
378 String sqlSelect =
"SELECT EXISTS "
381 String sqlWhere =
" WHERE value=? "
387 params =
new ArrayList<>();
388 params.add(instance.getCorrelationValue());
391 if (commentCallback.doesCommentExist()) {
393 commentExists =
true;
398 return commentExists;
413 commentExists = rs.getBoolean(1);
422 boolean doesCommentExist() {
static synchronized String getConfigSetting(String moduleName, String settingName)
static final int EMAIL_TYPE_ID
static String getDefaultOrgName()
static void closePersonasTopComponent()
void executeQuery(String sql, List< Object > params, CentralRepositoryDbQueryCallback queryCallback)
static void insertCorrelationType(Connection conn, CorrelationAttributeInstance.Type correlationType)
static void closeResultSet(ResultSet resultSet)
static String correlationTypeToReferenceTableName(CorrelationAttributeInstance.Type type)
static final String DEFAULT_ORG_NAME
static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected)
static final int ADDITIONAL_TYPES_BASE_ID
static List< CorrelationAttributeInstance.Type > getDefaultCorrelationTypes()
static void closeConnection(Connection conn)
static String correlationTypeToInstanceTableName(CorrelationAttributeInstance.Type type)
static boolean commentExistsOnAttributes(List< CorrelationAttributeInstance > attributes)
static boolean schemaVersionIsSet(Connection conn)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static void closePreparedStatement(PreparedStatement preparedStatement)
static final int PHONE_TYPE_ID
static final String CENTRAL_REPO_USE_KEY
String getModuleSettingsKey()
static final String CENTRAL_REPO_NAME
static boolean executeValidationQuery(Connection conn, String validationQuery)
static final Logger LOGGER
static boolean allowUseOfCentralRepository()
synchronized static Logger getLogger(String name)
static boolean insertDefaultCorrelationTypes(Connection conn)
static boolean isDefaultOrg(CentralRepoOrganization org)
static CentralRepoSettings getInstance()
static CentralRepository getInstance()
static void closeStatement(Statement statement)
static boolean isEnabled()