Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
PostgresEamDbSettings.java
Go to the documentation of this file.
1 /*
2  * Central Repository
3  *
4  * Copyright 2015-2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.centralrepository.datamodel;
20 
21 import java.sql.Connection;
22 import java.sql.DriverManager;
23 import java.sql.PreparedStatement;
24 import java.sql.ResultSet;
25 import java.sql.SQLException;
26 import java.sql.Statement;
27 import java.util.List;
28 import java.util.Properties;
29 import java.util.logging.Level;
30 import java.util.regex.Pattern;
35 import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.SOFTWARE_CR_DB_SCHEMA_VERSION;
36 
43 public final class PostgresEamDbSettings {
44 
45  private final static Logger LOGGER = Logger.getLogger(PostgresEamDbSettings.class.getName());
46  private final static String DEFAULT_HOST = ""; // NON-NLS
47  private final static int DEFAULT_PORT = 5432;
48  private final static String DEFAULT_DBNAME = "central_repository"; // NON-NLS
49  private final static String DEFAULT_USERNAME = "";
50  private final static String DEFAULT_PASSWORD = "";
51  private final static String VALIDATION_QUERY = "SELECT version()"; // NON-NLS
52  private final static String JDBC_BASE_URI = "jdbc:postgresql://"; // NON-NLS
53  private final static String JDBC_DRIVER = "org.postgresql.Driver"; // NON-NLS
54  private final static String DB_NAMES_REGEX = "[a-z][a-z0-9_]*"; // only lower case
55  private final static String DB_USER_NAMES_REGEX = "[a-zA-Z]\\w*";
56  private String host;
57  private int port;
58  private String dbName;
59  private int bulkThreshold;
60  private String userName;
61  private String password;
62 
64  loadSettings();
65  }
66 
67  public void loadSettings() {
68  host = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.host"); // NON-NLS
69  if (host == null || host.isEmpty()) {
70  host = DEFAULT_HOST;
71  }
72 
73  try {
74  String portString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.port"); // NON-NLS
75  if (portString == null || portString.isEmpty()) {
76  port = DEFAULT_PORT;
77  } else {
78  port = Integer.parseInt(portString);
79  if (port < 0 || port > 65535) {
80  port = DEFAULT_PORT;
81  }
82  }
83  } catch (NumberFormatException ex) {
84  port = DEFAULT_PORT;
85  }
86 
87  dbName = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.dbName"); // NON-NLS
88  if (dbName == null || dbName.isEmpty()) {
89  dbName = DEFAULT_DBNAME;
90  }
91 
92  try {
93  String bulkThresholdString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.bulkThreshold"); // NON-NLS
94  if (bulkThresholdString == null || bulkThresholdString.isEmpty()) {
95  this.bulkThreshold = AbstractSqlEamDb.DEFAULT_BULK_THRESHHOLD;
96  } else {
97  this.bulkThreshold = Integer.parseInt(bulkThresholdString);
98  if (getBulkThreshold() <= 0) {
99  this.bulkThreshold = AbstractSqlEamDb.DEFAULT_BULK_THRESHHOLD;
100  }
101  }
102  } catch (NumberFormatException ex) {
103  this.bulkThreshold = AbstractSqlEamDb.DEFAULT_BULK_THRESHHOLD;
104  }
105 
106  userName = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.user"); // NON-NLS
107  if (userName == null || userName.isEmpty()) {
108  userName = DEFAULT_USERNAME;
109  }
110 
111  password = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.password"); // NON-NLS
112  if (password == null || password.isEmpty()) {
113  password = DEFAULT_PASSWORD;
114  } else {
115  try {
116  password = TextConverter.convertHexTextToText(password);
117  } catch (TextConverterException ex) {
118  LOGGER.log(Level.WARNING, "Failed to convert password from hex text to text.", ex);
119  password = DEFAULT_PASSWORD;
120  }
121  }
122  }
123 
124  public void saveSettings() {
125  ModuleSettings.setConfigSetting("CentralRepository", "db.postgresql.host", getHost()); // NON-NLS
126  ModuleSettings.setConfigSetting("CentralRepository", "db.postgresql.port", Integer.toString(port)); // NON-NLS
127  ModuleSettings.setConfigSetting("CentralRepository", "db.postgresql.dbName", getDbName()); // NON-NLS
128  ModuleSettings.setConfigSetting("CentralRepository", "db.postgresql.bulkThreshold", Integer.toString(getBulkThreshold())); // NON-NLS
129  ModuleSettings.setConfigSetting("CentralRepository", "db.postgresql.user", getUserName()); // NON-NLS
130  try {
131  ModuleSettings.setConfigSetting("CentralRepository", "db.postgresql.password", TextConverter.convertTextToHexText(getPassword())); // NON-NLS
132  } catch (TextConverterException ex) {
133  LOGGER.log(Level.SEVERE, "Failed to convert password from text to hex text.", ex);
134  }
135  }
136 
145  String getConnectionURL(boolean usePostgresDb) {
146  StringBuilder url = new StringBuilder();
147  url.append(getJDBCBaseURI());
148  url.append(getHost());
149  url.append("/"); // NON-NLS
150  if (usePostgresDb) {
151  url.append("postgres"); // NON-NLS
152  } else {
153  url.append(getDbName());
154  }
155 
156  return url.toString();
157  }
158 
165  private Connection getEphemeralConnection(boolean usePostgresDb) {
166  Connection conn;
167  try {
168  String url = getConnectionURL(usePostgresDb);
169  Properties props = new Properties();
170  props.setProperty("user", getUserName());
171  props.setProperty("password", getPassword());
172 
173  Class.forName(getDriver());
174  conn = DriverManager.getConnection(url, props);
175  } catch (ClassNotFoundException | SQLException ex) {
176  // TODO: Determine why a connection failure (ConnectionException) re-throws
177  // the SQLException and does not print this log message?
178  LOGGER.log(Level.SEVERE, "Failed to acquire ephemeral connection to postgresql."); // NON-NLS
179  conn = null;
180  }
181  return conn;
182  }
183 
190  public boolean verifyConnection() {
191  Connection conn = getEphemeralConnection(true);
192  if (null == conn) {
193  return false;
194  }
195 
196  boolean result = EamDbUtil.executeValidationQuery(conn, VALIDATION_QUERY);
198  return result;
199  }
200 
206  public boolean verifyDatabaseExists() {
207  Connection conn = getEphemeralConnection(true);
208  if (null == conn) {
209  return false;
210  }
211 
212  String sql = "SELECT datname FROM pg_catalog.pg_database WHERE lower(datname) = lower(?) LIMIT 1"; // NON-NLS
213  PreparedStatement ps = null;
214  ResultSet rs = null;
215  try {
216  ps = conn.prepareStatement(sql);
217  ps.setString(1, getDbName());
218  rs = ps.executeQuery();
219  if (rs.next()) {
220  return true;
221  }
222  } catch (SQLException ex) {
223  LOGGER.log(Level.SEVERE, "Failed to execute database existance query.", ex); // NON-NLS
224  return false;
225  } finally {
229  }
230  return false;
231  }
232 
239  public boolean verifyDatabaseSchema() {
240  Connection conn = getEphemeralConnection(false);
241  if (null == conn) {
242  return false;
243  }
244 
245  boolean result = EamDbUtil.schemaVersionIsSet(conn);
246 
248  return result;
249  }
250 
251  public boolean createDatabase() {
252  Connection conn = getEphemeralConnection(true);
253  if (null == conn) {
254  return false;
255  }
256 
257  String sql = "CREATE DATABASE %s OWNER %s"; // NON-NLS
258  try {
259  Statement stmt;
260  stmt = conn.createStatement();
261  stmt.execute(String.format(sql, getDbName(), getUserName()));
262  } catch (SQLException ex) {
263  LOGGER.log(Level.SEVERE, "Failed to execute create database statement.", ex); // NON-NLS
264  return false;
265  } finally {
267  }
268  return true;
269 
270  }
271 
272  public boolean deleteDatabase() {
273  Connection conn = getEphemeralConnection(true);
274  if (null == conn) {
275  return false;
276  }
277 
278  String sql = "DROP DATABASE %s"; // NON-NLS
279  try {
280  Statement stmt;
281  stmt = conn.createStatement();
282  stmt.execute(String.format(sql, getDbName()));
283  } catch (SQLException ex) {
284  LOGGER.log(Level.SEVERE, "Failed to execute drop database statement.", ex); // NON-NLS
285  return false;
286  } finally {
288  }
289  return true;
290 
291  }
292 
304  public boolean initializeDatabaseSchema() {
305  // The "id" column is an alias for the built-in 64-bit int "rowid" column.
306  // It is autoincrementing by default and must be of type "integer primary key".
307  // We've omitted the autoincrement argument because we are not currently
308  // using the id value to search for specific rows, so we do not care
309  // if a rowid is re-used after an existing rows was previously deleted.
310  StringBuilder createOrganizationsTable = new StringBuilder();
311  createOrganizationsTable.append("CREATE TABLE IF NOT EXISTS organizations (");
312  createOrganizationsTable.append("id SERIAL PRIMARY KEY,");
313  createOrganizationsTable.append("org_name text NOT NULL,");
314  createOrganizationsTable.append("poc_name text NOT NULL,");
315  createOrganizationsTable.append("poc_email text NOT NULL,");
316  createOrganizationsTable.append("poc_phone text NOT NULL,");
317  createOrganizationsTable.append("CONSTRAINT org_name_unique UNIQUE (org_name)");
318  createOrganizationsTable.append(")");
319 
320  // NOTE: The organizations will only have a small number of rows, so
321  // an index is probably not worthwhile.
322  StringBuilder createCasesTable = new StringBuilder();
323  createCasesTable.append("CREATE TABLE IF NOT EXISTS cases (");
324  createCasesTable.append("id SERIAL PRIMARY KEY,");
325  createCasesTable.append("case_uid text NOT NULL,");
326  createCasesTable.append("org_id integer,");
327  createCasesTable.append("case_name text NOT NULL,");
328  createCasesTable.append("creation_date text NOT NULL,");
329  createCasesTable.append("case_number text,");
330  createCasesTable.append("examiner_name text,");
331  createCasesTable.append("examiner_email text,");
332  createCasesTable.append("examiner_phone text,");
333  createCasesTable.append("notes text,");
334  createCasesTable.append("foreign key (org_id) references organizations(id) ON UPDATE SET NULL ON DELETE SET NULL,");
335  createCasesTable.append("CONSTRAINT case_uid_unique UNIQUE (case_uid)");
336  createCasesTable.append(")");
337 
338  // NOTE: when there are few cases in the cases table, these indices may not be worthwhile
339  String casesIdx1 = "CREATE INDEX IF NOT EXISTS cases_org_id ON cases (org_id)";
340  String casesIdx2 = "CREATE INDEX IF NOT EXISTS cases_case_uid ON cases (case_uid)";
341 
342  StringBuilder createReferenceSetsTable = new StringBuilder();
343  createReferenceSetsTable.append("CREATE TABLE IF NOT EXISTS reference_sets (");
344  createReferenceSetsTable.append("id SERIAL PRIMARY KEY,");
345  createReferenceSetsTable.append("org_id integer NOT NULL,");
346  createReferenceSetsTable.append("set_name text NOT NULL,");
347  createReferenceSetsTable.append("version text NOT NULL,");
348  createReferenceSetsTable.append("known_status integer NOT NULL,");
349  createReferenceSetsTable.append("read_only boolean NOT NULL,");
350  createReferenceSetsTable.append("type integer NOT NULL,");
351  createReferenceSetsTable.append("import_date text NOT NULL,");
352  createReferenceSetsTable.append("foreign key (org_id) references organizations(id) ON UPDATE SET NULL ON DELETE SET NULL,");
353  createReferenceSetsTable.append("CONSTRAINT hash_set_unique UNIQUE (set_name, version)");
354  createReferenceSetsTable.append(")");
355 
356  String referenceSetsIdx1 = "CREATE INDEX IF NOT EXISTS reference_sets_org_id ON reference_sets (org_id)";
357 
358  // Each "%s" will be replaced with the relevant reference_TYPE table name.
359  StringBuilder createReferenceTypesTableTemplate = new StringBuilder();
360  createReferenceTypesTableTemplate.append("CREATE TABLE IF NOT EXISTS %s (");
361  createReferenceTypesTableTemplate.append("id SERIAL PRIMARY KEY,");
362  createReferenceTypesTableTemplate.append("reference_set_id integer,");
363  createReferenceTypesTableTemplate.append("value text NOT NULL,");
364  createReferenceTypesTableTemplate.append("known_status integer NOT NULL,");
365  createReferenceTypesTableTemplate.append("comment text,");
366  createReferenceTypesTableTemplate.append("CONSTRAINT %s_multi_unique UNIQUE (reference_set_id, value),");
367  createReferenceTypesTableTemplate.append("foreign key (reference_set_id) references reference_sets(id) ON UPDATE SET NULL ON DELETE SET NULL");
368  createReferenceTypesTableTemplate.append(")");
369 
370  // Each "%s" will be replaced with the relevant reference_TYPE table name.
371  String referenceTypesIdx1 = "CREATE INDEX IF NOT EXISTS %s_value ON %s (value)";
372  String referenceTypesIdx2 = "CREATE INDEX IF NOT EXISTS %s_value_known_status ON %s (value, known_status)";
373 
374  StringBuilder createCorrelationTypesTable = new StringBuilder();
375  createCorrelationTypesTable.append("CREATE TABLE IF NOT EXISTS correlation_types (");
376  createCorrelationTypesTable.append("id SERIAL PRIMARY KEY,");
377  createCorrelationTypesTable.append("display_name text NOT NULL,");
378  createCorrelationTypesTable.append("db_table_name text NOT NULL,");
379  createCorrelationTypesTable.append("supported integer NOT NULL,");
380  createCorrelationTypesTable.append("enabled integer NOT NULL,");
381  createCorrelationTypesTable.append("CONSTRAINT correlation_types_names UNIQUE (display_name, db_table_name)");
382  createCorrelationTypesTable.append(")");
383 
384  String createArtifactInstancesTableTemplate = getCreateArtifactInstancesTableTemplate();
385 
386  String instancesCaseIdIdx = getAddCaseIdIndexTemplate();
387  String instancesDatasourceIdIdx = getAddDataSourceIdIndexTemplate();
388  String instancesValueIdx = getAddValueIndexTemplate();
389  String instancesKnownStatusIdx = getAddKnownStatusIndexTemplate();
390  String instancesObjectIdIdx = getAddObjectIdIndexTemplate();
391 
392  // NOTE: the db_info table currenly only has 1 row, so having an index
393  // provides no benefit.
394  Connection conn = null;
395  try {
396  conn = getEphemeralConnection(false);
397  if (null == conn) {
398  return false;
399  }
400  Statement stmt = conn.createStatement();
401 
402  stmt.execute(createOrganizationsTable.toString());
403 
404  stmt.execute(createCasesTable.toString());
405  stmt.execute(casesIdx1);
406  stmt.execute(casesIdx2);
407 
408  stmt.execute(getCreateDataSourcesTableStatement());
409  stmt.execute(getAddDataSourcesNameIndexStatement());
410  stmt.execute(getAddDataSourcesObjectIdIndexStatement());
411 
412  stmt.execute(createReferenceSetsTable.toString());
413  stmt.execute(referenceSetsIdx1);
414 
415  stmt.execute(createCorrelationTypesTable.toString());
416 
417  /*
418  * Note that the essentially useless id column in the following
419  * table is required for backwards compatibility. Otherwise, the
420  * name column could be the primary key.
421  */
422  stmt.execute("CREATE TABLE db_info (id SERIAL, name TEXT UNIQUE NOT NULL, value TEXT NOT NULL)");
423  stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "')");
424  stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "')");
425  stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "')");
426  stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MINOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "')");
427 
428  // Create a separate instance and reference table for each correlation type
430 
431  String reference_type_dbname;
432  String instance_type_dbname;
433  for (CorrelationAttributeInstance.Type type : DEFAULT_CORRELATION_TYPES) {
434  reference_type_dbname = EamDbUtil.correlationTypeToReferenceTableName(type);
435  instance_type_dbname = EamDbUtil.correlationTypeToInstanceTableName(type);
436 
437  stmt.execute(String.format(createArtifactInstancesTableTemplate, instance_type_dbname, instance_type_dbname));
438  stmt.execute(String.format(instancesCaseIdIdx, instance_type_dbname, instance_type_dbname));
439  stmt.execute(String.format(instancesDatasourceIdIdx, instance_type_dbname, instance_type_dbname));
440  stmt.execute(String.format(instancesValueIdx, instance_type_dbname, instance_type_dbname));
441  stmt.execute(String.format(instancesKnownStatusIdx, instance_type_dbname, instance_type_dbname));
442  stmt.execute(String.format(instancesObjectIdIdx, instance_type_dbname, instance_type_dbname));
443 
444  // FUTURE: allow more than the FILES type
445  if (type.getId() == CorrelationAttributeInstance.FILES_TYPE_ID) {
446  stmt.execute(String.format(createReferenceTypesTableTemplate.toString(), reference_type_dbname, reference_type_dbname));
447  stmt.execute(String.format(referenceTypesIdx1, reference_type_dbname, reference_type_dbname));
448  stmt.execute(String.format(referenceTypesIdx2, reference_type_dbname, reference_type_dbname));
449  }
450  }
451 
452  } catch (SQLException ex) {
453  LOGGER.log(Level.SEVERE, "Error initializing db schema.", ex); // NON-NLS
454  return false;
455  } catch (EamDbException ex) {
456  LOGGER.log(Level.SEVERE, "Error getting default correlation types. Likely due to one or more Type's with an invalid db table name."); // NON-NLS
457  return false;
458  } finally {
460  }
461  return true;
462  }
463 
471  static String getCreateArtifactInstancesTableTemplate() {
472  // Each "%s" will be replaced with the relevant TYPE_instances table name.
473  return ("CREATE TABLE IF NOT EXISTS %s (id SERIAL PRIMARY KEY,case_id integer NOT NULL,"
474  + "data_source_id integer NOT NULL,value text NOT NULL,file_path text NOT NULL,"
475  + "known_status integer NOT NULL,comment text,file_obj_id BIGINT,"
476  + "CONSTRAINT %s_multi_unique_ UNIQUE (data_source_id, value, file_path),"
477  + "foreign key (case_id) references cases(id) ON UPDATE SET NULL ON DELETE SET NULL,"
478  + "foreign key (data_source_id) references data_sources(id) ON UPDATE SET NULL ON DELETE SET NULL)");
479  }
480 
488  static String getCreateDataSourcesTableStatement() {
489  return "CREATE TABLE IF NOT EXISTS data_sources "
490  + "(id SERIAL PRIMARY KEY,case_id integer NOT NULL,device_id text NOT NULL,"
491  + "name text NOT NULL,datasource_obj_id BIGINT,md5 text DEFAULT NULL,"
492  + "sha1 text DEFAULT NULL,sha256 text DEFAULT NULL,"
493  + "foreign key (case_id) references cases(id) ON UPDATE SET NULL ON DELETE SET NULL,"
494  + "CONSTRAINT datasource_unique UNIQUE (case_id, datasource_obj_id))";
495  }
496 
504  static String getAddDataSourcesNameIndexStatement() {
505  return "CREATE INDEX IF NOT EXISTS data_sources_name ON data_sources (name)";
506  }
507 
515  static String getAddDataSourcesObjectIdIndexStatement() {
516  return "CREATE INDEX IF NOT EXISTS data_sources_object_id ON data_sources (datasource_obj_id)";
517  }
518 
527  static String getAddCaseIdIndexTemplate() {
528  // Each "%s" will be replaced with the relevant TYPE_instances table name.
529  return "CREATE INDEX IF NOT EXISTS %s_case_id ON %s (case_id)";
530  }
531 
540  static String getAddDataSourceIdIndexTemplate() {
541  // Each "%s" will be replaced with the relevant TYPE_instances table name.
542  return "CREATE INDEX IF NOT EXISTS %s_data_source_id ON %s (data_source_id)";
543  }
544 
553  static String getAddValueIndexTemplate() {
554  // Each "%s" will be replaced with the relevant TYPE_instances table name.
555  return "CREATE INDEX IF NOT EXISTS %s_value ON %s (value)";
556  }
557 
566  static String getAddKnownStatusIndexTemplate() {
567  // Each "%s" will be replaced with the relevant TYPE_instances table name.
568  return "CREATE INDEX IF NOT EXISTS %s_value_known_status ON %s (value, known_status)";
569  }
570 
579  static String getAddObjectIdIndexTemplate() {
580  // Each "%s" will be replaced with the relevant TYPE_instances table name.
581  return "CREATE INDEX IF NOT EXISTS %s_file_obj_id ON %s (file_obj_id)";
582  }
583 
584  public boolean insertDefaultDatabaseContent() {
585  Connection conn = getEphemeralConnection(false);
586  if (null == conn) {
587  return false;
588  }
589 
590  boolean result = EamDbUtil.insertDefaultCorrelationTypes(conn) && EamDbUtil.insertDefaultOrganization(conn);
592 
593  return result;
594  }
595 
596  boolean isChanged() {
597  String hostString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.host"); // NON-NLS
598  String portString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.port"); // NON-NLS
599  String dbNameString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.dbName"); // NON-NLS
600  String bulkThresholdString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.bulkThreshold"); // NON-NLS
601  String userNameString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.user"); // NON-NLS
602  String userPasswordString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.password"); // NON-NLS
603 
604  return !host.equals(hostString) || !Integer.toString(port).equals(portString)
605  || !dbName.equals(dbNameString) || !Integer.toString(bulkThreshold).equals(bulkThresholdString)
606  || !userName.equals(userNameString) || !password.equals(userPasswordString);
607  }
608 
612  public String getHost() {
613  return host;
614  }
615 
619  public void setHost(String host) throws EamDbException {
620  if (null != host && !host.isEmpty()) {
621  this.host = host;
622  } else {
623  throw new EamDbException("Invalid host name. Cannot be empty."); // NON-NLS
624  }
625  }
626 
630  public int getPort() {
631  return port;
632  }
633 
637  public void setPort(int port) throws EamDbException {
638  if (port > 0 && port < 65535) {
639  this.port = port;
640  } else {
641  throw new EamDbException("Invalid port. Must be a number greater than 0."); // NON-NLS
642  }
643  }
644 
651  public String getDbName() {
652  return dbName.toLowerCase();
653  }
654 
658  public void setDbName(String dbName) throws EamDbException {
659  if (dbName == null || dbName.isEmpty()) {
660  throw new EamDbException("Invalid database name. Cannot be empty."); // NON-NLS
661  } else if (!Pattern.matches(DB_NAMES_REGEX, dbName)) {
662  throw new EamDbException("Invalid database name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
663  }
664 
665  this.dbName = dbName.toLowerCase();
666  }
667 
671  int getBulkThreshold() {
672  return bulkThreshold;
673  }
674 
678  public void setBulkThreshold(int bulkThreshold) throws EamDbException {
679  if (bulkThreshold > 0) {
680  this.bulkThreshold = bulkThreshold;
681  } else {
682  throw new EamDbException("Invalid bulk threshold."); // NON-NLS
683  }
684  }
685 
689  public String getUserName() {
690  return userName;
691  }
692 
696  public void setUserName(String userName) throws EamDbException {
697  if (userName == null || userName.isEmpty()) {
698  throw new EamDbException("Invalid user name. Cannot be empty."); // NON-NLS
699  } else if (!Pattern.matches(DB_USER_NAMES_REGEX, userName)) {
700  throw new EamDbException("Invalid user name. Name must start with a letter and can only contain letters, numbers, and '_'."); // NON-NLS
701  }
702  this.userName = userName;
703  }
704 
708  public String getPassword() {
709  return password;
710  }
711 
715  public void setPassword(String password) throws EamDbException {
716  if (password == null || password.isEmpty()) {
717  throw new EamDbException("Invalid user password. Cannot be empty."); // NON-NLS
718  }
719  this.password = password;
720  }
721 
725  String getValidationQuery() {
726  return VALIDATION_QUERY;
727  }
728 
732  String getDriver() {
733  return JDBC_DRIVER;
734  }
735 
739  String getJDBCBaseURI() {
740  return JDBC_BASE_URI;
741  }
742 
743 }
static String correlationTypeToInstanceTableName(CorrelationAttributeInstance.Type type)
Definition: EamDbUtil.java:353
static boolean executeValidationQuery(Connection conn, String validationQuery)
Definition: EamDbUtil.java:325
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static boolean insertDefaultCorrelationTypes(Connection conn)
Definition: EamDbUtil.java:103
static String getConfigSetting(String moduleName, String settingName)
synchronized static Logger getLogger(String name)
Definition: Logger.java:124
static String correlationTypeToReferenceTableName(CorrelationAttributeInstance.Type type)
Definition: EamDbUtil.java:364
static String convertTextToHexText(String property)
static String convertHexTextToText(String property)

Copyright © 2012-2018 Basis Technology. Generated on: Wed Sep 18 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.