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 != preparedStatement) {
54 preparedStatement.close();
55 }
catch (SQLException ex) {
56 LOGGER.log(Level.SEVERE,
"Error closing PreparedStatement.", 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);
138 static boolean updateSchemaVersion(Connection conn) {
142 String sql =
"INSERT INTO db_info (name, value) VALUES (?, ?)";
144 statement = conn.createStatement();
145 resultSet = statement.executeQuery(
"SELECT id FROM db_info WHERE name='SCHEMA_VERSION'");
146 if (resultSet.next()) {
147 int id = resultSet.getInt(
"id");
148 statement.execute(
"UPDATE db_info SET value=" + CURRENT_DB_SCHEMA_VERSION.getMajor() +
" WHERE id=" + id);
150 statement.execute(
"INSERT INTO db_info (name, value) VALUES ('SCHEMA_VERSION', '" + CURRENT_DB_SCHEMA_VERSION.getMajor() +
"')");
153 resultSet = statement.executeQuery(
"SELECT id FROM db_info WHERE name='SCHEMA_MINOR_VERSION'");
154 if (resultSet.next()) {
155 int id = resultSet.getInt(
"id");
156 statement.execute(
"UPDATE db_info SET value=" + CURRENT_DB_SCHEMA_VERSION.getMinor() +
" WHERE id=" + id);
158 statement.execute(
"INSERT INTO db_info (name, value) VALUES ('SCHEMA_MINOR_VERSION', '" + CURRENT_DB_SCHEMA_VERSION.getMinor() +
"')");
160 }
catch (SQLException ex) {
161 LOGGER.log(Level.SEVERE,
"Error adding schema version to db_info.", ex);
178 ResultSet resultSet = null;
180 Statement tester = conn.createStatement();
181 String sql =
"SELECT value FROM db_info WHERE name='SCHEMA_VERSION'";
182 resultSet = tester.executeQuery(sql);
183 if (resultSet.next()) {
184 String value = resultSet.getString(
"value");
186 }
catch (SQLException ex) {
218 LOGGER.log(Level.SEVERE,
"Error updating central repository", ex);
226 LOGGER.log(Level.SEVERE,
"Error shutting down central repo connection pool", ex);
238 LOGGER.log(Level.SEVERE,
"Error releasing database lock", ex);
261 return DEFAULT_ORG_NAME.equals(org.
getName());
270 static boolean insertDefaultOrganization(Connection conn) {
275 PreparedStatement preparedStatement = null;
276 String sql =
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
278 preparedStatement = conn.prepareStatement(sql);
279 preparedStatement.setString(1, DEFAULT_ORG_NAME);
280 preparedStatement.setString(2,
"");
281 preparedStatement.setString(3,
"");
282 preparedStatement.setString(4,
"");
283 preparedStatement.executeUpdate();
284 }
catch (SQLException ex) {
285 LOGGER.log(Level.SEVERE,
"Error adding default organization", ex);
288 EamDbUtil.closePreparedStatement(preparedStatement);
326 ResultSet resultSet = null;
328 Statement tester = conn.createStatement();
329 resultSet = tester.executeQuery(validationQuery);
330 if (resultSet.next()) {
333 }
catch (SQLException ex) {
350 return type.getDbTableName() +
"_instances";
361 return "reference_" + type.getDbTableName();
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 final String DEFAULT_ORG_NAME
static String correlationTypeToReferenceTableName(CorrelationAttribute.Type type)
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 correlationTypeToInstanceTableName(CorrelationAttribute.Type type)
static String getConfigSetting(String moduleName, String settingName)
static final CaseDbSchemaVersionNumber CURRENT_DB_SCHEMA_VERSION
synchronized static Logger getLogger(String name)
static List< CorrelationAttribute.Type > getDefaultCorrelationTypes()
static void closePreparedStatement(PreparedStatement preparedStatement)
static final String CENTRAL_REPO_NAME