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;
52 if (null != statement) {
55 }
catch (SQLException ex) {
56 LOGGER.log(Level.SEVERE,
"Error closing Statement.", ex);
69 if (null != resultSet) {
72 }
catch (SQLException ex) {
73 LOGGER.log(Level.SEVERE,
"Error closing ResultSet.", ex);
89 }
catch (SQLException ex) {
90 LOGGER.log(Level.SEVERE,
"Error closing Connection.", ex);
103 PreparedStatement preparedStatement = null;
104 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
108 preparedStatement = conn.prepareStatement(sql);
110 preparedStatement.setInt(1, newType.getId());
111 preparedStatement.setString(2, newType.getDisplayName());
112 preparedStatement.setString(3, newType.getDbTableName());
113 preparedStatement.setInt(4, newType.isSupported() ? 1 : 0);
114 preparedStatement.setInt(5, newType.isEnabled() ? 1 : 0);
116 preparedStatement.addBatch();
118 preparedStatement.executeBatch();
120 LOGGER.log(Level.SEVERE,
"Error inserting default correlation types.", ex);
135 static void updateSchemaVersion(Connection conn)
throws SQLException {
136 try (Statement statement = conn.createStatement()) {
137 statement.execute(
"UPDATE db_info SET value = '" + CURRENT_DB_SCHEMA_VERSION.getMajor() +
"' WHERE name = '" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY +
"'");
138 statement.execute(
"UPDATE db_info SET value = '" + CURRENT_DB_SCHEMA_VERSION.getMinor() +
"' WHERE name = '" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY +
"'");
152 ResultSet resultSet = null;
154 Statement tester = conn.createStatement();
155 String sql =
"SELECT value FROM db_info WHERE name='SCHEMA_VERSION'";
156 resultSet = tester.executeQuery(sql);
157 if (resultSet.next()) {
158 String value = resultSet.getString(
"value");
160 }
catch (SQLException ex) {
192 LOGGER.log(Level.SEVERE,
"Error updating central repository", ex);
200 LOGGER.log(Level.SEVERE,
"Error shutting down central repo connection pool", ex);
212 LOGGER.log(Level.SEVERE,
"Error releasing database lock", ex);
236 return DEFAULT_ORG_NAME.equals(org.
getName());
246 static boolean insertDefaultOrganization(Connection conn) {
251 PreparedStatement preparedStatement = null;
252 String sql =
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
254 preparedStatement = conn.prepareStatement(sql);
255 preparedStatement.setString(1, DEFAULT_ORG_NAME);
256 preparedStatement.setString(2,
"");
257 preparedStatement.setString(3,
"");
258 preparedStatement.setString(4,
"");
259 preparedStatement.executeUpdate();
260 }
catch (SQLException ex) {
261 LOGGER.log(Level.SEVERE,
"Error adding default organization", ex);
264 EamDbUtil.closePreparedStatement(preparedStatement);
302 ResultSet resultSet = null;
304 Statement tester = conn.createStatement();
305 resultSet = tester.executeQuery(validationQuery);
306 if (resultSet.next()) {
309 }
catch (SQLException ex) {
326 return type.getDbTableName() +
"_instances";
337 return "reference_" + type.getDbTableName();
static String correlationTypeToInstanceTableName(CorrelationAttributeInstance.Type type)
void shutdownConnections()
static boolean schemaVersionIsSet(Connection conn)
CoordinationService.Lock getExclusiveMultiUserDbLock()
static boolean executeValidationQuery(Connection conn, String validationQuery)
static boolean useCentralRepo()
static boolean isDefaultOrg(EamOrganization org)
static final String CENTRAL_REPO_USE_KEY
static void closeResultSet(ResultSet resultSet)
static boolean upgradeDatabase()
static final Logger LOGGER
static void closeStatement(Statement statement)
static List< CorrelationAttributeInstance.Type > getDefaultCorrelationTypes()
static final String DEFAULT_ORG_NAME
static EamDb getInstance()
static void closeConnection(Connection conn)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected)
static String getDefaultOrgName()
static boolean isEnabled()
static boolean insertDefaultCorrelationTypes(Connection conn)
static String getConfigSetting(String moduleName, String settingName)
synchronized static Logger getLogger(String name)
static String correlationTypeToReferenceTableName(CorrelationAttributeInstance.Type type)
static void closePreparedStatement(PreparedStatement preparedStatement)
static final String CENTRAL_REPO_NAME