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."})
184 String messageForDialog =
"";
189 LOGGER.log(Level.SEVERE,
"Error updating central repository, unable to make connection", ex);
190 messageForDialog = Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message();
203 LOGGER.log(Level.SEVERE,
"Error updating central repository", ex);
204 messageForDialog = Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message();
206 messageForDialog = ex.getMessage() +
"\n\n" + messageForDialog;
208 messageForDialog = ex.getMessage() + Bundle.EamDbUtil_centralRepoDisabled_message();
215 LOGGER.log(Level.SEVERE,
"Error releasing database lock", ex);
220 LOGGER.log(Level.SEVERE,
"Error updating central repository, unable to acquire exclusive lock", ex);
221 messageForDialog = Bundle.EamDbUtil_exclusiveLockAquisitionFailure_message() + Bundle.EamDbUtil_centralRepoDisabled_message();
225 messageForDialog = Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message();
228 if (!messageForDialog.isEmpty()) {
234 LOGGER.log(Level.SEVERE,
"Error shutting down central repo connection pool", ex2);
260 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);
330 ResultSet resultSet = null;
332 Statement tester = conn.createStatement();
333 resultSet = tester.executeQuery(validationQuery);
334 if (resultSet.next()) {
337 }
catch (SQLException ex) {
354 return type.getDbTableName() +
"_instances";
365 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