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.sql.Connection;
 
   26 import java.sql.DriverManager;
 
   27 import java.sql.SQLException;
 
   28 import java.util.logging.Level;
 
   29 import java.util.regex.Pattern;
 
   60         if (dbName == null || dbName.isEmpty()) {
 
   65         if (dbDirectory == null || dbDirectory.isEmpty()) {
 
   71             if (bulkThresholdString == null || bulkThresholdString.isEmpty()) {
 
   72                 this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   74                 this.bulkThreshold = Integer.parseInt(bulkThresholdString);
 
   75                 if (getBulkThreshold() <= 0) {
 
   76                     this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   79         } 
catch (NumberFormatException ex) {
 
   80             this.bulkThreshold = RdbmsCentralRepo.DEFAULT_BULK_THRESHHOLD;
 
   85         return String.format(
"SqliteCentralRepoSettings: [db type: sqlite, directory: %s, name: %s]", 
getDbDirectory(), 
getDbName());
 
  111         if (!dbFile.exists()) {
 
  115         return (!dbFile.isDirectory());
 
  132         if (!dbDir.exists()) {
 
  134         } 
else if (!dbDir.isDirectory()) {
 
  161                 Files.createDirectories(dbDir.toPath());
 
  162                 LOGGER.log(Level.INFO, 
"sqlite directory did not exist, created it at {0}.", 
getDbDirectory()); 
 
  163             } 
catch (IOException | InvalidPathException | SecurityException ex) {
 
  164                 LOGGER.log(Level.SEVERE, 
"Failed to create sqlite database directory.", ex); 
 
  179         return dbFile.delete();
 
  187     String getConnectionURL() {
 
  188         StringBuilder url = 
new StringBuilder();
 
  189         url.append(getJDBCBaseURI());
 
  192         return url.toString();
 
  203     Connection getEphemeralConnection() {
 
  210             String url = getConnectionURL();
 
  211             Class.forName(getDriver());
 
  212             conn = DriverManager.getConnection(url);
 
  213         } 
catch (ClassNotFoundException | SQLException ex) {
 
  214             LOGGER.log(Level.SEVERE, 
"Failed to acquire ephemeral connection to sqlite.", ex); 
 
  227         Connection conn = getEphemeralConnection();
 
  244         Connection conn = getEphemeralConnection();
 
  254     boolean isChanged() {
 
  259         return !dbName.equals(dbNameString)
 
  260                 || !dbDirectory.equals(dbDirectoryString)
 
  261                 || !Integer.toString(bulkThreshold).equals(bulkThresholdString);
 
  277         if (dbName == null || dbName.isEmpty()) {
 
  279         } 
else if (!Pattern.matches(DB_NAMES_REGEX, dbName)) {
 
  280             throw new CentralRepoException(
"Invalid database file name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); 
 
  289     int getBulkThreshold() {
 
  297         if (bulkThreshold > 0) {
 
  300             throw new CentralRepoException(
"Invalid bulk threshold."); 
 
  319         if (dbDirectory != null && !dbDirectory.isEmpty()) {
 
  345     String getValidationQuery() {
 
  352     String getJDBCBaseURI() {
 
static final Logger LOGGER
 
static synchronized String getConfigSetting(String moduleName, String settingName)
 
boolean createDbDirectory()
 
static final String JDBC_DRIVER
 
static final String JDBC_BASE_URI
 
boolean verifyConnection()
 
static void closeConnection(Connection conn)
 
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 DEFAULT_DBNAME