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.List;
27 import java.util.logging.Level;
50 if (null != statement) {
53 }
catch (SQLException ex) {
54 LOGGER.log(Level.SEVERE,
"Error closing Statement.", ex);
67 if (null != resultSet) {
70 }
catch (SQLException ex) {
71 LOGGER.log(Level.SEVERE,
"Error closing ResultSet.", ex);
87 }
catch (SQLException ex) {
88 LOGGER.log(Level.SEVERE,
"Error closing Connection.", ex);
101 PreparedStatement preparedStatement = null;
102 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
106 preparedStatement = conn.prepareStatement(sql);
108 preparedStatement.setInt(1, newType.getId());
109 preparedStatement.setString(2, newType.getDisplayName());
110 preparedStatement.setString(3, newType.getDbTableName());
111 preparedStatement.setInt(4, newType.isSupported() ? 1 : 0);
112 preparedStatement.setInt(5, newType.isEnabled() ? 1 : 0);
114 preparedStatement.addBatch();
116 preparedStatement.executeBatch();
118 LOGGER.log(Level.SEVERE,
"Error inserting default correlation types.", ex);
135 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
136 try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
138 preparedStatement.setInt(1, correlationType.getId());
139 preparedStatement.setString(2, correlationType.getDisplayName());
140 preparedStatement.setString(3, correlationType.getDbTableName());
141 preparedStatement.setInt(4, correlationType.isSupported() ? 1 : 0);
142 preparedStatement.setInt(5, correlationType.isEnabled() ? 1 : 0);
144 preparedStatement.execute();
155 static void updateSchemaVersion(Connection conn)
throws SQLException {
156 try (Statement statement = conn.createStatement()) {
157 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() +
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MAJOR_VERSION_KEY +
"'");
158 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() +
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MINOR_VERSION_KEY +
"'");
172 ResultSet resultSet = null;
174 Statement tester = conn.createStatement();
175 String sql =
"SELECT value FROM db_info WHERE name='SCHEMA_VERSION'";
176 resultSet = tester.executeQuery(sql);
177 if (resultSet.next()) {
178 String value = resultSet.getString(
"value");
180 }
catch (SQLException ex) {
206 return DEFAULT_ORG_NAME.equals(org.
getName());
216 static boolean insertDefaultOrganization(Connection conn) {
221 PreparedStatement preparedStatement = null;
222 String sql =
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
224 preparedStatement = conn.prepareStatement(sql);
225 preparedStatement.setString(1, DEFAULT_ORG_NAME);
226 preparedStatement.setString(2,
"");
227 preparedStatement.setString(3,
"");
228 preparedStatement.setString(4,
"");
229 preparedStatement.executeUpdate();
230 }
catch (SQLException ex) {
231 LOGGER.log(Level.SEVERE,
"Error adding default organization", ex);
234 CentralRepoDbUtil.closePreparedStatement(preparedStatement);
276 ResultSet resultSet = null;
278 Statement tester = conn.createStatement();
279 resultSet = tester.executeQuery(validationQuery);
280 if (resultSet.next()) {
283 }
catch (SQLException ex) {
300 return type.getDbTableName() +
"_instances";
311 return "reference_" + type.getDbTableName();
static synchronized String getConfigSetting(String moduleName, String settingName)
static final int EMAIL_TYPE_ID
static String getDefaultOrgName()
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 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 void closeStatement(Statement statement)