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;
54 if (null != statement) {
57 }
catch (SQLException ex) {
58 LOGGER.log(Level.SEVERE,
"Error closing Statement.", ex);
71 if (null != resultSet) {
74 }
catch (SQLException ex) {
75 LOGGER.log(Level.SEVERE,
"Error closing ResultSet.", ex);
91 }
catch (SQLException ex) {
92 LOGGER.log(Level.SEVERE,
"Error closing Connection.", ex);
105 PreparedStatement preparedStatement = null;
106 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
110 preparedStatement = conn.prepareStatement(sql);
112 preparedStatement.setInt(1, newType.getId());
113 preparedStatement.setString(2, newType.getDisplayName());
114 preparedStatement.setString(3, newType.getDbTableName());
115 preparedStatement.setInt(4, newType.isSupported() ? 1 : 0);
116 preparedStatement.setInt(5, newType.isEnabled() ? 1 : 0);
118 preparedStatement.addBatch();
120 preparedStatement.executeBatch();
122 LOGGER.log(Level.SEVERE,
"Error inserting default correlation types.", ex);
139 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
140 try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
142 preparedStatement.setInt(1, correlationType.getId());
143 preparedStatement.setString(2, correlationType.getDisplayName());
144 preparedStatement.setString(3, correlationType.getDbTableName());
145 preparedStatement.setInt(4, correlationType.isSupported() ? 1 : 0);
146 preparedStatement.setInt(5, correlationType.isEnabled() ? 1 : 0);
148 preparedStatement.execute();
159 static void updateSchemaVersion(Connection conn)
throws SQLException {
160 try (Statement statement = conn.createStatement()) {
161 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() +
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MAJOR_VERSION_KEY +
"'");
162 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() +
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MINOR_VERSION_KEY +
"'");
176 ResultSet resultSet = null;
178 Statement tester = conn.createStatement();
179 String sql =
"SELECT value FROM db_info WHERE name='SCHEMA_VERSION'";
180 resultSet = tester.executeQuery(sql);
181 if (resultSet.next()) {
182 String value = resultSet.getString(
"value");
184 }
catch (SQLException ex) {
209 return DEFAULT_ORG_NAME.equals(org.
getName());
219 static boolean insertDefaultOrganization(Connection conn) {
224 PreparedStatement preparedStatement = null;
225 String sql =
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
227 preparedStatement = conn.prepareStatement(sql);
228 preparedStatement.setString(1, DEFAULT_ORG_NAME);
229 preparedStatement.setString(2,
"");
230 preparedStatement.setString(3,
"");
231 preparedStatement.setString(4,
"");
232 preparedStatement.executeUpdate();
233 }
catch (SQLException ex) {
234 LOGGER.log(Level.SEVERE,
"Error adding default organization", ex);
237 CentralRepoDbUtil.closePreparedStatement(preparedStatement);
273 SwingUtilities.invokeLater(() -> {
274 TopComponent personasWindow = WindowManager.getDefault().findTopComponent(
"PersonasTopComponent");
275 if (personasWindow != null && personasWindow.isOpened()) {
276 personasWindow.close();
292 ResultSet resultSet = null;
294 Statement tester = conn.createStatement();
295 resultSet = tester.executeQuery(validationQuery);
296 if (resultSet.next()) {
299 }
catch (SQLException ex) {
316 return type.getDbTableName() +
"_instances";
327 return "reference_" + type.getDbTableName();
373 boolean commentExists =
false;
377 String sqlSelect =
"SELECT EXISTS "
380 String sqlWhere =
" WHERE value=? "
386 params =
new ArrayList<>();
387 params.add(instance.getCorrelationValue());
390 if (commentCallback.doesCommentExist()) {
392 commentExists =
true;
397 return commentExists;
412 commentExists = rs.getBoolean(1);
421 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
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 CentralRepository getInstance()
static void closeStatement(Statement statement)
static boolean isEnabled()