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;
 
   70         if (dbName == null || dbName.isEmpty()) {
 
   75         if (dbDirectory == null || dbDirectory.isEmpty()) {
 
   81             if (bulkThresholdString == null || bulkThresholdString.isEmpty()) {
 
   82                 this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   84                 this.bulkThreshold = Integer.parseInt(bulkThresholdString);
 
   85                 if (getBulkThreshold() <= 0) {
 
   86                     this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   89         } 
catch (NumberFormatException ex) {
 
   90             this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   95         return String.format(
"SqliteCentralRepoSettings: [db type: sqlite, directory: %s, name: %s]", 
getDbDirectory(), 
getDbName());
 
  123         Path relativePath = Paths.get(fullPath);
 
  125         if (Paths.get(fullPath).startsWith(userConfigDir)) {
 
  127             relativePath = userConfigDir.relativize(relativePath);
 
  147         if (curPath != null && !curPath.isEmpty()) {
 
  150             Path driveLetterOrNetwork = Paths.get(curPath).getRoot();            
 
  151             if (driveLetterOrNetwork != null) {
 
  157             Path absolutePath = userConfigDir.resolve(curPath);
 
  158             curPath = absolutePath.toString();
 
  159             if (
new File(curPath).canRead() == 
false) {
 
  161                 LOGGER.log(Level.INFO, 
"Path to SQLite Central Repository database is not valid: {0}", curPath); 
 
  176         if (!dbFile.exists()) {
 
  180         return (!dbFile.isDirectory());
 
  197         if (!dbDir.exists()) {
 
  199         } 
else if (!dbDir.isDirectory()) {
 
  226                 Files.createDirectories(dbDir.toPath());
 
  227                 LOGGER.log(Level.INFO, 
"sqlite directory did not exist, created it at {0}.", 
getDbDirectory()); 
 
  228             } 
catch (IOException | InvalidPathException | SecurityException ex) {
 
  229                 LOGGER.log(Level.SEVERE, 
"Failed to create sqlite database directory.", ex); 
 
  244         return dbFile.delete();
 
  252     String getConnectionURL() {
 
  253         StringBuilder url = 
new StringBuilder();
 
  254         url.append(getJDBCBaseURI());
 
  257         return url.toString();
 
  268     Connection getEphemeralConnection() {
 
  275             String url = getConnectionURL();
 
  276             Class.forName(getDriver());
 
  277             conn = DriverManager.getConnection(url);
 
  278         } 
catch (ClassNotFoundException | SQLException ex) {
 
  279             LOGGER.log(Level.SEVERE, 
"Failed to acquire ephemeral connection to sqlite.", ex); 
 
  292         Connection conn = getEphemeralConnection();
 
  309         Connection conn = getEphemeralConnection();
 
  319     boolean isChanged() {
 
  324         return !dbName.equals(dbNameString)
 
  325                 || !dbDirectory.equals(dbDirectoryString)
 
  326                 || !Integer.toString(bulkThreshold).equals(bulkThresholdString);
 
  342         if (dbName == null || dbName.isEmpty()) {
 
  344         } 
else if (!Pattern.matches(DB_NAMES_REGEX, dbName)) {
 
  345             throw new CentralRepoException(
"Invalid database file name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); 
 
  354     int getBulkThreshold() {
 
  362         if (bulkThreshold > 0) {
 
  365             throw new CentralRepoException(
"Invalid bulk threshold."); 
 
  384         if (dbDirectory != null && !dbDirectory.isEmpty()) {
 
  410     String getValidationQuery() {
 
  417     String getJDBCBaseURI() {
 
static final Logger LOGGER
 
static synchronized String getConfigSetting(String moduleName, String settingName)
 
boolean createDbDirectory()
 
static final String BULK_THRESHOLD
 
static final String JDBC_DRIVER
 
static final String PROFILE_NAME
 
static final String JDBC_BASE_URI
 
boolean verifyConnection()
 
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()
 
static final String VALIDATION_QUERY
 
String getFileNameWithPath()
 
void setDbDirectory(String dbDirectory)
 
static boolean executeValidationQuery(Connection conn, String validationQuery)
 
synchronized static Logger getLogger(String name)
 
SqliteCentralRepoSettings()
 
static final String DATABASE_NAME
 
static final String DEFAULT_DBNAME
 
static final String DATABASE_PATH