19 package org.sleuthkit.autopsy.centralrepository.datamodel;
 
   22 import java.io.IOException;
 
   23 import java.nio.file.Files;
 
   24 import java.nio.file.InvalidPathException;
 
   25 import java.nio.file.Path;
 
   26 import java.nio.file.Paths;
 
   27 import java.sql.Connection;
 
   28 import java.sql.DriverManager;
 
   29 import java.sql.SQLException;
 
   30 import java.util.logging.Level;
 
   31 import java.util.regex.Pattern;
 
   71         if (dbName == null || dbName.isEmpty()) {
 
   76         if (dbDirectory == null || dbDirectory.isEmpty()) {
 
   82             if (bulkThresholdString == null || bulkThresholdString.isEmpty()) {
 
   83                 this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   85                 this.bulkThreshold = Integer.parseInt(bulkThresholdString);
 
   86                 if (getBulkThreshold() <= 0) {
 
   87                     this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   90         } 
catch (NumberFormatException ex) {
 
   91             this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   96         return String.format(
"SqliteCentralRepoSettings: [db type: sqlite, directory: %s, name: %s]", 
getDbDirectory(), 
getDbName());
 
  124         Path relativePath = Paths.get(fullPath);
 
  126         if (Paths.get(fullPath).startsWith(userConfigDir)) {
 
  128             relativePath = userConfigDir.relativize(relativePath);
 
  148         if (curPath != null && !curPath.isEmpty()) {
 
  151             Path driveLetterOrNetwork = Paths.get(curPath).getRoot();            
 
  152             if (driveLetterOrNetwork != null) {
 
  158             Path absolutePath = userConfigDir.resolve(curPath);
 
  159             curPath = absolutePath.toString();
 
  160             if (
new File(curPath).canRead() == 
false) {
 
  162                 LOGGER.log(Level.INFO, 
"Path to SQLite Central Repository database is not valid: {0}", curPath); 
 
  177         if (!dbFile.exists()) {
 
  181         return (!dbFile.isDirectory());
 
  198         if (!dbDir.exists()) {
 
  200         } 
else if (!dbDir.isDirectory()) {
 
  227                 Files.createDirectories(dbDir.toPath());
 
  228                 LOGGER.log(Level.INFO, 
"sqlite directory did not exist, created it at {0}.", 
getDbDirectory()); 
 
  229             } 
catch (IOException | InvalidPathException | SecurityException ex) {
 
  230                 LOGGER.log(Level.SEVERE, 
"Failed to create sqlite database directory.", ex); 
 
  245         return dbFile.delete();
 
  253     String getConnectionURL() {
 
  254         StringBuilder url = 
new StringBuilder();
 
  255         url.append(getJDBCBaseURI());
 
  258         return url.toString();
 
  269     Connection getEphemeralConnection() {
 
  276             String url = getConnectionURL();
 
  277             Class.forName(getDriver());
 
  278             conn = DriverManager.getConnection(url);
 
  279         } 
catch (ClassNotFoundException | SQLException ex) {
 
  280             LOGGER.log(Level.SEVERE, 
"Failed to acquire ephemeral connection to sqlite.", ex); 
 
  293         Connection conn = getEphemeralConnection();
 
  310         Connection conn = getEphemeralConnection();
 
  320     boolean isChanged() {
 
  325         return !dbName.equals(dbNameString)
 
  326                 || !dbDirectory.equals(dbDirectoryString)
 
  327                 || !Integer.toString(bulkThreshold).equals(bulkThresholdString);
 
  343         if (dbName == null || dbName.isEmpty()) {
 
  345         } 
else if (!Pattern.matches(DB_NAMES_REGEX, dbName)) {
 
  346             throw new CentralRepoException(
"Invalid database file name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); 
 
  355     int getBulkThreshold() {
 
  363         if (bulkThreshold > 0) {
 
  366             throw new CentralRepoException(
"Invalid bulk threshold."); 
 
  385         if (dbDirectory != null && !dbDirectory.isEmpty()) {
 
  411     String getValidationQuery() {
 
  418     String getJDBCBaseURI() {
 
static final Logger LOGGER
 
static synchronized String getConfigSetting(String moduleName, String settingName)
 
boolean createDbDirectory()
 
String getDatabaseNameKey()
 
static final String BULK_THRESHOLD
 
String getDefaultDbPath()
 
static final String JDBC_DRIVER
 
static final String PROFILE_NAME
 
static final String JDBC_BASE_URI
 
boolean verifyConnection()
 
String getDefaultDbName()
 
static void closeConnection(Connection conn)
 
void saveDbPath(String fullPath)
 
static final String DEFAULT_DBDIRECTORY
 
boolean verifyDatabaseSchema()
 
boolean verifyDatabaseExists()
 
void setDbName(String dbName)
 
static final String DB_NAMES_REGEX
 
void setupDefaultSettings()
 
static boolean schemaVersionIsSet(Connection conn)
 
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
 
boolean dbDirectoryExists()
 
DatabaseTestResult testStatus()
 
String getDatabasePathKey()
 
static final String VALIDATION_QUERY
 
String getModuleSettingsKey()
 
String getFileNameWithPath()
 
void setDbDirectory(String dbDirectory)
 
static boolean executeValidationQuery(Connection conn, String validationQuery)
 
synchronized static Logger getLogger(String name)
 
SqliteCentralRepoSettings()
 
static CentralRepoSettings getInstance()
 
static final String DATABASE_NAME
 
static final String DEFAULT_DBNAME
 
static final String DATABASE_PATH