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 javax.swing.SwingUtilities;
 
   29 import org.openide.windows.TopComponent;
 
   30 import org.openide.windows.WindowManager;
 
   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); 
 
  138         String sql = 
"INSERT INTO correlation_types(id, display_name, db_table_name, supported, enabled) VALUES (?, ?, ?, ?, ?)";
 
  139         try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
 
  141             preparedStatement.setInt(1, correlationType.getId());
 
  142             preparedStatement.setString(2, correlationType.getDisplayName());
 
  143             preparedStatement.setString(3, correlationType.getDbTableName());
 
  144             preparedStatement.setInt(4, correlationType.isSupported() ? 1 : 0);
 
  145             preparedStatement.setInt(5, correlationType.isEnabled() ? 1 : 0);
 
  147             preparedStatement.execute();
 
  158     static void updateSchemaVersion(Connection conn) 
throws SQLException {
 
  159         try (Statement statement = conn.createStatement()) {
 
  160             statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + 
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MAJOR_VERSION_KEY + 
"'");
 
  161             statement.execute(
"UPDATE db_info SET value = '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + 
"' WHERE name = '" + RdbmsCentralRepo.SCHEMA_MINOR_VERSION_KEY + 
"'");
 
  175         ResultSet resultSet = null;
 
  177             Statement tester = conn.createStatement();
 
  178             String sql = 
"SELECT value FROM db_info WHERE name='SCHEMA_VERSION'";
 
  179             resultSet = tester.executeQuery(sql);
 
  180             if (resultSet.next()) {
 
  181                 String value = resultSet.getString(
"value");
 
  183         } 
catch (SQLException ex) {
 
  209         return DEFAULT_ORG_NAME.equals(org.
getName());
 
  219     static boolean insertDefaultOrganization(Connection conn) {
 
  224         PreparedStatement preparedStatement = null;
 
  225         String sql = 
"INSERT INTO organizations(org_name, poc_name, poc_email, poc_phone) VALUES (?, ?, ?, ?)";
 
  227             preparedStatement = conn.prepareStatement(sql);
 
  228             preparedStatement.setString(1, DEFAULT_ORG_NAME);
 
  229             preparedStatement.setString(2, 
"");
 
  230             preparedStatement.setString(3, 
"");
 
  231             preparedStatement.setString(4, 
"");
 
  232             preparedStatement.executeUpdate();
 
  233         } 
catch (SQLException ex) {
 
  234             LOGGER.log(Level.SEVERE, 
"Error adding default organization", ex);
 
  237             CentralRepoDbUtil.closePreparedStatement(preparedStatement);
 
  273         SwingUtilities.invokeLater(() -> {
 
  274             TopComponent personasWindow = WindowManager.getDefault().findTopComponent(
"PersonasTopComponent");
 
  275             if (personasWindow != null && personasWindow.isOpened()) {
 
  276                 personasWindow.close();   
 
  292         ResultSet resultSet = null;
 
  294             Statement tester = conn.createStatement();
 
  295             resultSet = tester.executeQuery(validationQuery);
 
  296             if (resultSet.next()) {
 
  299         } 
catch (SQLException ex) {
 
  316         return type.getDbTableName() + 
"_instances";
 
  327         return "reference_" + type.getDbTableName();
 
static synchronized String getConfigSetting(String moduleName, String settingName)
static final int EMAIL_TYPE_ID
static String getDefaultOrgName()
static void closePersonasTopComponent()
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)