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.List;
25 import java.util.logging.Level;
26 import org.apache.commons.dbcp2.BasicDataSource;
54 if (instance == null) {
75 if(connectionPool != null){
76 connectionPool.close();
77 connectionPool = null;
80 }
catch (SQLException ex) {
81 throw new EamDbException(
"Failed to close existing database connections.", ex);
105 Statement dropContent = conn.createStatement();
106 dropContent.executeUpdate(
"TRUNCATE TABLE organizations RESTART IDENTITY CASCADE");
107 dropContent.executeUpdate(
"TRUNCATE TABLE cases RESTART IDENTITY CASCADE");
108 dropContent.executeUpdate(
"TRUNCATE TABLE data_sources RESTART IDENTITY CASCADE");
109 dropContent.executeUpdate(
"TRUNCATE TABLE reference_sets RESTART IDENTITY CASCADE");
110 dropContent.executeUpdate(
"TRUNCATE TABLE correlation_types RESTART IDENTITY CASCADE");
111 dropContent.executeUpdate(
"TRUNCATE TABLE db_info RESTART IDENTITY CASCADE");
113 String instancesTemplate =
"TRUNCATE TABLE %s_instances RESTART IDENTITY CASCADE";
114 String referencesTemplate =
"TRUNCATE TABLE reference_%s RESTART IDENTITY CASCADE";
116 dropContent.executeUpdate(String.format(instancesTemplate, type.getDbTableName()));
119 dropContent.executeUpdate(String.format(referencesTemplate, type.getDbTableName()));
122 }
catch (SQLException ex) {
123 LOGGER.log(Level.WARNING,
"Failed to reset database.", ex);
136 connectionPool =
new BasicDataSource();
137 connectionPool.setUsername(dbSettings.
getUserName());
138 connectionPool.setPassword(dbSettings.
getPassword());
139 connectionPool.setDriverClassName(dbSettings.
getDriver());
141 StringBuilder connectionURL =
new StringBuilder();
143 connectionURL.append(dbSettings.
getHost());
144 connectionURL.append(
":");
145 connectionURL.append(dbSettings.
getPort());
146 connectionURL.append(
"/");
147 connectionURL.append(dbSettings.
getDbName());
149 connectionPool.setUrl(connectionURL.toString());
150 connectionPool.setUsername(dbSettings.
getUserName());
151 connectionPool.setPassword(dbSettings.
getPassword());
154 connectionPool.setInitialSize(5);
155 connectionPool.setMaxIdle(CONN_POOL_SIZE);
168 synchronized (
this) {
170 throw new EamDbException(
"Central Repository module is not enabled");
173 if (connectionPool == null) {
179 return connectionPool.getConnection();
180 }
catch (SQLException ex) {
181 throw new EamDbException(
"Error getting connection from connection pool.", ex);
static final int CONN_POOL_SIZE
String getConflictClause()
final List< String > badTags
static PostgresEamDb instance
static synchronized PostgresEamDb getInstance()
static final int FILES_TYPE_ID
boolean insertDefaultDatabaseContent()
void setupConnectionPool()
int bulkArtifactsThreshold
static final Logger LOGGER
List< String > getBadTags()
final List< CorrelationAttribute.Type > DEFAULT_CORRELATION_TYPES
final PostgresEamDbSettings dbSettings
void shutdownConnections()
static void closeConnection(Connection conn)
void setBadTags(List< String > badTags)
List< String > getBadTags()
String getValidationQuery()
static boolean isEnabled()
BasicDataSource connectionPool
synchronized static Logger getLogger(String name)
static final String CONFLICT_CLAUSE
void setBadTags(List< String > badTags)