19 package org.sleuthkit.autopsy.centralrepository.datamodel;
21 import java.sql.Connection;
22 import java.sql.SQLException;
23 import java.sql.Statement;
24 import java.util.concurrent.TimeUnit;
25 import java.util.logging.Level;
26 import org.apache.commons.dbcp2.BasicDataSource;
58 if (instance == null) {
79 if(connectionPool != null){
80 connectionPool.close();
81 connectionPool = null;
84 }
catch (SQLException ex) {
85 throw new EamDbException(
"Failed to close existing database connections.", ex);
109 Statement dropContent = conn.createStatement();
110 dropContent.executeUpdate(
"TRUNCATE TABLE organizations RESTART IDENTITY CASCADE");
111 dropContent.executeUpdate(
"TRUNCATE TABLE cases RESTART IDENTITY CASCADE");
112 dropContent.executeUpdate(
"TRUNCATE TABLE data_sources RESTART IDENTITY CASCADE");
113 dropContent.executeUpdate(
"TRUNCATE TABLE reference_sets RESTART IDENTITY CASCADE");
114 dropContent.executeUpdate(
"TRUNCATE TABLE correlation_types RESTART IDENTITY CASCADE");
115 dropContent.executeUpdate(
"TRUNCATE TABLE db_info RESTART IDENTITY CASCADE");
117 String instancesTemplate =
"TRUNCATE TABLE %s_instances RESTART IDENTITY CASCADE";
118 String referencesTemplate =
"TRUNCATE TABLE reference_%s RESTART IDENTITY CASCADE";
120 dropContent.executeUpdate(String.format(instancesTemplate, type.getDbTableName()));
123 dropContent.executeUpdate(String.format(referencesTemplate, type.getDbTableName()));
126 }
catch (SQLException ex) {
127 LOGGER.log(Level.WARNING,
"Failed to reset database.", ex);
140 connectionPool =
new BasicDataSource();
141 connectionPool.setUsername(dbSettings.
getUserName());
142 connectionPool.setPassword(dbSettings.
getPassword());
143 connectionPool.setDriverClassName(dbSettings.
getDriver());
145 StringBuilder connectionURL =
new StringBuilder();
147 connectionURL.append(dbSettings.
getHost());
148 connectionURL.append(
":");
149 connectionURL.append(dbSettings.
getPort());
150 connectionURL.append(
"/");
151 connectionURL.append(dbSettings.
getDbName());
153 connectionPool.setUrl(connectionURL.toString());
154 connectionPool.setUsername(dbSettings.
getUserName());
155 connectionPool.setPassword(dbSettings.
getPassword());
158 connectionPool.setInitialSize(5);
159 connectionPool.setMaxIdle(CONN_POOL_SIZE);
172 synchronized (
this) {
174 throw new EamDbException(
"Central Repository module is not enabled");
177 if (connectionPool == null) {
183 return connectionPool.getConnection();
184 }
catch (SQLException ex) {
185 throw new EamDbException(
"Error getting connection from connection pool.", ex);
210 String databaseNodeName = dbSettings.
getHost() +
"_" + dbSettings.
getDbName();
216 throw new EamDbException(
"Error acquiring database lock");
217 }
catch (InterruptedException ex){
218 throw new EamDbException(
"Error acquiring database lock");
static final int CONN_POOL_SIZE
String getConflictClause()
static PostgresEamDb instance
static synchronized PostgresEamDb getInstance()
static final int FILES_TYPE_ID
boolean insertDefaultDatabaseContent()
CoordinationService.Lock getExclusiveMultiUserDbLock()
static boolean getIsMultiUserModeEnabled()
void setupConnectionPool()
int bulkArtifactsThreshold
static final Logger LOGGER
final List< CorrelationAttribute.Type > DEFAULT_CORRELATION_TYPES
final PostgresEamDbSettings dbSettings
void shutdownConnections()
static void closeConnection(Connection conn)
Lock tryGetExclusiveLock(CategoryNode category, String nodePath, int timeOut, TimeUnit timeUnit)
String getValidationQuery()
static boolean isEnabled()
BasicDataSource connectionPool
synchronized static Logger getLogger(String name)
static synchronized CoordinationService getInstance()
static final String CONFLICT_CLAUSE