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;
28 import org.openide.util.NbBundle.Messages;
53 if (null != statement) {
56 }
catch (SQLException ex) {
57 LOGGER.log(Level.SEVERE,
"Error closing Statement.", ex);
70 if (null != resultSet) {
73 }
catch (SQLException ex) {
74 LOGGER.log(Level.SEVERE,
"Error closing ResultSet.", ex);
90 }
catch (SQLException ex) {
91 LOGGER.log(Level.SEVERE,
"Error closing Connection.", ex);
104 PreparedStatement preparedStatement = null;
105 String sql =
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
109 preparedStatement = conn.prepareStatement(sql);
111 preparedStatement.setInt(1, newType.getId());
112 preparedStatement.setString(2, newType.getDisplayName());
113 preparedStatement.setString(3, newType.getDbTableName());
114 preparedStatement.setInt(4, newType.isSupported() ? 1 : 0);
115 preparedStatement.setInt(5, newType.isEnabled() ? 1 : 0);
117 preparedStatement.addBatch();
119 preparedStatement.executeBatch();
121 LOGGER.log(Level.SEVERE,
"Error inserting default correlation types.", ex);
136 static void updateSchemaVersion(Connection conn)
throws SQLException {
137 try (Statement statement = conn.createStatement()) {
138 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() +
"' WHERE name = '" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY +
"'");
139 statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() +
"' WHERE name = '" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY +
"'");
153 ResultSet resultSet = null;
155 Statement tester = conn.createStatement();
156 String sql =
"SELECT value FROM db_info WHERE name='SCHEMA_VERSION'";
157 resultSet = tester.executeQuery(sql);
158 if (resultSet.next()) {
159 String value = resultSet.getString(
"value");
161 }
catch (SQLException ex) {
174 @Messages({
"EamDbUtil.centralRepoDisabled.message= The Central Repository has been disabled.",
175 "EamDbUtil.centralRepoUpgradeFailed.message=Failed to upgrade Central Repository.",
176 "EamDbUtil.centralRepoConnectionFailed.message=Unable to connect to Central Repository.",
177 "EamDbUtil.exclusiveLockAquisitionFailure.message=Unable to acquire exclusive lock for Central Repository."})
190 LOGGER.log(Level.SEVERE,
"Error updating central repository, unable to make connection", ex);
191 throw new EamDbException(
"Error updating central repository, unable to make connection", Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
202 LOGGER.log(Level.SEVERE,
"Error updating central repository, unable to acquire exclusive lock", ex);
203 throw new EamDbException(
"Error updating central repository, unable to acquire exclusive lock", Bundle.EamDbUtil_exclusiveLockAquisitionFailure_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
209 LOGGER.log(Level.SEVERE,
"Error updating central repository", ex);
210 throw new EamDbException(
"Error updating central repository", ex.
getUserMessage() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
211 }
catch (SQLException ex) {
212 LOGGER.log(Level.SEVERE,
"Error updating central repository", ex);
213 throw new EamDbException(
"Error updating central repository", Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
215 LOGGER.log(Level.SEVERE,
"Error updating central repository", ex);
216 throw new EamDbException(
"Error updating central repository", ex.getMessage() +
"\n\n" + Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
222 LOGGER.log(Level.SEVERE,
"Error releasing database lock", ex);
227 throw new EamDbException(
"Unable to connect to database", Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message());
236 LOGGER.log(Level.SEVERE,
"Error shutting down central repo connection pool", ex2);
261 return DEFAULT_ORG_NAME.equals(org.
getName());
271 static boolean insertDefaultOrganization(Connection conn) {
276 PreparedStatement preparedStatement = null;
277 String sql =
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
279 preparedStatement = conn.prepareStatement(sql);
280 preparedStatement.setString(1, DEFAULT_ORG_NAME);
281 preparedStatement.setString(2,
"");
282 preparedStatement.setString(3,
"");
283 preparedStatement.setString(4,
"");
284 preparedStatement.executeUpdate();
285 }
catch (SQLException ex) {
286 LOGGER.log(Level.SEVERE,
"Error adding default organization", ex);
289 EamDbUtil.closePreparedStatement(preparedStatement);
331 ResultSet resultSet = null;
333 Statement tester = conn.createStatement();
334 resultSet = tester.executeQuery(validationQuery);
335 if (resultSet.next()) {
338 }
catch (SQLException ex) {
355 return type.getDbTableName() +
"_instances";
366 return "reference_" + type.getDbTableName();
static void upgradeDatabase()
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 isDefaultOrg(EamOrganization org)
static final String CENTRAL_REPO_USE_KEY
static void closeResultSet(ResultSet resultSet)
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 boolean allowUseOfCentralRepository()
static final String CENTRAL_REPO_NAME