19 package org.sleuthkit.autopsy.centralrepository.datamodel;
21 import java.beans.PropertyChangeListener;
22 import java.beans.PropertyChangeSupport;
24 import java.sql.SQLException;
25 import java.util.logging.Level;
26 import org.openide.util.NbBundle;
71 if (clearDisabledDueToError)
77 savedChoice = newChoice;
79 propertyChangeSupport.firePropertyChange(
"savedChoice", oldChoice, newChoice);
107 if (savedChoice == null) {
109 savedChoice =
fromKey(selectedPlatformString);
135 propertyChangeSupport.firePropertyChange(
"disabledDueToFailure", oldValue, disabledDueToFailure);
158 propertyChangeSupport.addPropertyChangeListener(listener);
166 propertyChangeSupport.removePropertyChangeListener(listener);
173 if (dbChoice.getSettingKey().equalsIgnoreCase(keyName)) {
193 }
catch (CentralRepoException ex) {
194 logger.log(Level.SEVERE,
"Error updating central repository, unable to make connection", ex);
195 onUpgradeError(
"Error updating central repository, unable to make connection",
196 Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
215 return db.getExclusiveMultiUserDbLock();
218 logger.log(Level.SEVERE,
"Error updating central repository, unable to acquire exclusive lock", ex);
219 onUpgradeError(
"Error updating central repository, unable to acquire exclusive lock",
220 Bundle.EamDbUtil_exclusiveLockAquisitionFailure_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
237 }
catch (CentralRepoException ex) {
238 logger.log(Level.SEVERE,
"Error updating central repository", ex);
240 }
catch (SQLException ex) {
241 logger.log(Level.SEVERE,
"Error updating central repository", ex);
243 Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
245 logger.log(Level.SEVERE,
"Error updating central repository", ex);
247 ex.getMessage() +
"\n\n" + Bundle.EamDbUtil_centralRepoUpgradeFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), ex);
253 logger.log(Level.SEVERE,
"Error releasing database lock", ex);
264 @NbBundle.Messages(value = {
"EamDbUtil.centralRepoDisabled.message= The Central Repository has been disabled.",
"EamDbUtil.centralRepoUpgradeFailed.message=Failed to upgrade Central Repository.",
"EamDbUtil.centralRepoConnectionFailed.message=Unable to connect to Central Repository.",
"EamDbUtil.exclusiveLockAquisitionFailure.message=Unable to acquire exclusive lock for Central Repository."})
278 Bundle.EamDbUtil_centralRepoConnectionFailed_message() + Bundle.EamDbUtil_centralRepoDisabled_message(), null);
289 logger.log(Level.SEVERE,
"Error shutting down central repo connection pool", ex2);
292 if (innerException == null) {
360 throw new CentralRepoException(
"Unable to successfully create sqlite database");
389 throw new CentralRepoException(
"Unknown database type: " + selectedDbChoice);
402 throw new CentralRepoException(
"Unknown database type: " + selectedDbChoice);
412 if (selectedDbSettings == null)
413 throw new CentralRepoException(
"Unable to derive connectivity manager from settings: " + selectedDbChoice);
415 boolean result =
false;
416 boolean dbCreated =
true;
427 }
catch (CentralRepoException ex) {
428 logger.log(Level.SEVERE,
"Unable to create database for central repository with settings " + selectedDbSettings, ex);
438 String schemaError =
"Unable to initialize database schema or insert contents into central repository.";
439 logger.severe(schemaError);
440 throw new CentralRepoException(schemaError);
450 @NbBundle.Messages({
"CentralRepoDbManager.connectionErrorMsg.text=Failed to connect to central repository database."})
462 if (null != previousDbManager) {
467 logger.log(Level.SEVERE,
"Failed to close database connections in previously selected platform.", ex);
485 logger.info(
"Saving central repo settings for db: " + selectedDbSettings);
487 configurationChanged =
true;
489 logger.log(Level.SEVERE, Bundle.CentralRepoDbManager_connectionErrorMsg_text(), ex);
525 selectedDbChoice = newSelected;
536 String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
throws CentralRepoException, NumberFormatException {
539 dbSettingsPostgres.
setHost(tbDbHostname);
540 dbSettingsPostgres.
setPort(Integer.parseInt(tbDbPort));
541 dbSettingsPostgres.
setDbName(CENTRAL_REPO_DB_NAME);
546 File databasePath =
new File(tfDatabasePath);
551 throw new IllegalStateException(
"Central Repo has an unknown selected platform: " + selectedDbChoice);
567 catch (CentralRepoException e) {
568 logger.log(Level.WARNING,
"unable to test status of db connection in central repo", e);
final SqliteCentralRepoSettings dbSettingsSqlite
static synchronized String getConfigSetting(String moduleName, String settingName)
DatabaseTestResult getStatus()
DatabaseTestResult testStatus()
void setupDefaultSqliteDb()
static void removePropertyChangeListener(PropertyChangeListener listener)
static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice, boolean clearDisabledDueToError)
static final Object disabledDueToFailureLock
boolean insertDefaultDatabaseContent()
CentralRepoDbConnectivityManager getSelectedSettings()
PostgresCentralRepoSettings getDbSettingsMultiUser()
static void onUpgradeError(String message, String desc, Exception innerException)
SqliteCentralRepoSettings getDbSettingsSqlite()
static volatile CentralRepoDbChoice savedChoice
void setUserName(String userName)
DatabaseTestResult testingStatus
static void setUseCentralRepo(boolean centralRepoCheckBoxIsSelected)
static final String CENTRAL_REPOSITORY_SETTINGS_KEY
static CentralRepoDbChoice fromKey(String keyName)
static void upgradeDatabase()
static CentralRepoDbChoice getSavedDbChoice()
static boolean getIsMultiUserModeEnabled()
static boolean isPostgresMultiuserAllowed()
static final String DISABLED_DUE_TO_FAILURE_KEY
PostgresSettingsLoader MULTIUSER_SETTINGS_LOADER
static CentralRepoDbChoice saveDbChoice(CentralRepoDbChoice choice)
PostgresSettingsLoader CUSTOM_SETTINGS_LOADER
void saveNewCentralRepo()
static void disableDueToFailure()
static final String DB_SELECTED_PLATFORM_KEY
static boolean isDisabledDueToFailure()
static final String CENTRAL_REPO_DB_NAME
static CoordinationService.Lock obtainCentralRepoLock(CentralRepository db)
void setDbName(String dbName)
boolean testDatabaseSettingsAreValid(String tbDbHostname, String tbDbPort, String tbDbUsername, String tfDatabasePath, String jpDbPassword)
DatabaseTestResult testStatus()
void setupDefaultSettings()
void setPassword(String password)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
void setHost(String host)
void shutdownConnections()
static CentralRepository obtainCentralRepository()
final PostgresCentralRepoSettings dbSettingsPostgres
CentralRepoDbChoice getSelectedDbChoice()
PostgresCentralRepoSettings getDbSettingsPostgres()
boolean wasConfigurationChanged()
static void addPropertyChangeListener(PropertyChangeListener listener)
void setDbDirectory(String dbDirectory)
static void updatedDbSchema(CentralRepository db, CoordinationService.Lock lock)
boolean verifyDatabaseExists()
final PostgresCentralRepoSettings dbSettingsMultiUser
DatabaseTestResult testStatus()
synchronized static Logger getLogger(String name)
void setDbName(String dbName)
CentralRepoDbChoice selectedDbChoice
static final Object dbChoiceLock
boolean initializeDatabaseSchema()
static void setDisabledDueToFailure(boolean disabledDueToFailure)
static final String DEFAULT_DBNAME
void setSelctedDbChoice(CentralRepoDbChoice newSelected)
static CentralRepository getInstance()
boolean configurationChanged
static final PropertyChangeSupport propertyChangeSupport
RdbmsCentralRepoFactory getDbFactory()
static final Logger logger
static boolean isEnabled()