Autopsy  4.9.1
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-2017 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;
31 import static org.sleuthkit.autopsy.centralrepository.datamodel.AbstractSqlEamDb.CURRENT_DB_SCHEMA_VERSION;
36 
43 public final class PostgresEamDbSettings {
44 
45  private final static Logger LOGGER = Logger.getLogger(PostgresEamDbSettings.class.getName());
46  private final String DEFAULT_HOST = ""; // NON-NLS
47  private final int DEFAULT_PORT = 5432;
48  private final String DEFAULT_DBNAME = "central_repository"; // NON-NLS
49  private final String DEFAULT_USERNAME = "";
50  private final String DEFAULT_PASSWORD = "";
51  private final String VALIDATION_QUERY = "SELECT version()"; // NON-NLS
52  private final String JDBC_BASE_URI = "jdbc:postgresql://"; // NON-NLS
53  private final String JDBC_DRIVER = "org.postgresql.Driver"; // NON-NLS
54  private final String DB_NAMES_REGEX = "[a-z][a-z0-9_]*"; // only lower case
55  private final 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 createDataSourcesTable = new StringBuilder();
343  createDataSourcesTable.append("CREATE TABLE IF NOT EXISTS data_sources (");
344  createDataSourcesTable.append("id SERIAL PRIMARY KEY,");
345  createDataSourcesTable.append("case_id integer NOT NULL,");
346  createDataSourcesTable.append("device_id text NOT NULL,");
347  createDataSourcesTable.append("name text NOT NULL,");
348  createDataSourcesTable.append("datasource_obj_id integer,");
349  createDataSourcesTable.append("md5 text DEFAULT NULL,");
350  createDataSourcesTable.append("sha1 text DEFAULT NULL,");
351  createDataSourcesTable.append("sha256 text DEFAULT NULL,");
352  createDataSourcesTable.append("foreign key (case_id) references cases(id) ON UPDATE SET NULL ON DELETE SET NULL,");
353  createDataSourcesTable.append("CONSTRAINT datasource_unique UNIQUE (case_id, device_id, name)");
354  createDataSourcesTable.append(")");
355 
356  String dataSourceIdx1 = "CREATE INDEX IF NOT EXISTS data_sources_name ON data_sources (name)";
357  String dataSourceIdx2 = "CREATE INDEX IF NOT EXISTS data_sources_object_id ON data_sources (datasource_obj_id)";
358 
359  StringBuilder createReferenceSetsTable = new StringBuilder();
360  createReferenceSetsTable.append("CREATE TABLE IF NOT EXISTS reference_sets (");
361  createReferenceSetsTable.append("id SERIAL PRIMARY KEY,");
362  createReferenceSetsTable.append("org_id integer NOT NULL,");
363  createReferenceSetsTable.append("set_name text NOT NULL,");
364  createReferenceSetsTable.append("version text NOT NULL,");
365  createReferenceSetsTable.append("known_status integer NOT NULL,");
366  createReferenceSetsTable.append("read_only boolean NOT NULL,");
367  createReferenceSetsTable.append("type integer NOT NULL,");
368  createReferenceSetsTable.append("import_date text NOT NULL,");
369  createReferenceSetsTable.append("foreign key (org_id) references organizations(id) ON UPDATE SET NULL ON DELETE SET NULL,");
370  createReferenceSetsTable.append("CONSTRAINT hash_set_unique UNIQUE (set_name, version)");
371  createReferenceSetsTable.append(")");
372 
373  String referenceSetsIdx1 = "CREATE INDEX IF NOT EXISTS reference_sets_org_id ON reference_sets (org_id)";
374 
375  // Each "%s" will be replaced with the relevant reference_TYPE table name.
376  StringBuilder createReferenceTypesTableTemplate = new StringBuilder();
377  createReferenceTypesTableTemplate.append("CREATE TABLE IF NOT EXISTS %s (");
378  createReferenceTypesTableTemplate.append("id SERIAL PRIMARY KEY,");
379  createReferenceTypesTableTemplate.append("reference_set_id integer,");
380  createReferenceTypesTableTemplate.append("value text NOT NULL,");
381  createReferenceTypesTableTemplate.append("known_status integer NOT NULL,");
382  createReferenceTypesTableTemplate.append("comment text,");
383  createReferenceTypesTableTemplate.append("CONSTRAINT %s_multi_unique UNIQUE (reference_set_id, value),");
384  createReferenceTypesTableTemplate.append("foreign key (reference_set_id) references reference_sets(id) ON UPDATE SET NULL ON DELETE SET NULL");
385  createReferenceTypesTableTemplate.append(")");
386 
387  // Each "%s" will be replaced with the relevant reference_TYPE table name.
388  String referenceTypesIdx1 = "CREATE INDEX IF NOT EXISTS %s_value ON %s (value)";
389  String referenceTypesIdx2 = "CREATE INDEX IF NOT EXISTS %s_value_known_status ON %s (value, known_status)";
390 
391  StringBuilder createCorrelationTypesTable = new StringBuilder();
392  createCorrelationTypesTable.append("CREATE TABLE IF NOT EXISTS correlation_types (");
393  createCorrelationTypesTable.append("id SERIAL PRIMARY KEY,");
394  createCorrelationTypesTable.append("display_name text NOT NULL,");
395  createCorrelationTypesTable.append("db_table_name text NOT NULL,");
396  createCorrelationTypesTable.append("supported integer NOT NULL,");
397  createCorrelationTypesTable.append("enabled integer NOT NULL,");
398  createCorrelationTypesTable.append("CONSTRAINT correlation_types_names UNIQUE (display_name, db_table_name)");
399  createCorrelationTypesTable.append(")");
400 
401  String createArtifactInstancesTableTemplate = getCreateArtifactInstancesTableTemplate();
402 
403  String instancesCaseIdIdx = getAddCaseIdIndexTemplate();
404  String instancesDatasourceIdIdx = getAddDataSourceIdIndexTemplate();
405  String instancesValueIdx = getAddValueIndexTemplate();
406  String instancesKnownStatusIdx = getAddKnownStatusIndexTemplate();
407  String instancesObjectIdIdx = getAddObjectIdIndexTemplate();
408 
409  // NOTE: the db_info table currenly only has 1 row, so having an index
410  // provides no benefit.
411  Connection conn = null;
412  try {
413  conn = getEphemeralConnection(false);
414  if (null == conn) {
415  return false;
416  }
417  Statement stmt = conn.createStatement();
418 
419  stmt.execute(createOrganizationsTable.toString());
420 
421  stmt.execute(createCasesTable.toString());
422  stmt.execute(casesIdx1);
423  stmt.execute(casesIdx2);
424 
425  stmt.execute(createDataSourcesTable.toString());
426  stmt.execute(dataSourceIdx1);
427  stmt.execute(dataSourceIdx2);
428 
429  stmt.execute(createReferenceSetsTable.toString());
430  stmt.execute(referenceSetsIdx1);
431 
432  stmt.execute(createCorrelationTypesTable.toString());
433 
434  /*
435  * Note that the essentially useless id column in the following
436  * table is required for backwards compatibility. Otherwise, the
437  * name column could be the primary key.
438  */
439  stmt.execute("CREATE TABLE db_info (id SERIAL, name TEXT UNIQUE NOT NULL, value TEXT NOT NULL)");
440  stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MAJOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMajor() + "')");
441  stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.SCHEMA_MINOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMinor() + "')");
442  stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MAJOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMajor() + "')");
443  stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + AbstractSqlEamDb.CREATION_SCHEMA_MINOR_VERSION_KEY + "', '" + CURRENT_DB_SCHEMA_VERSION.getMinor() + "')");
444 
445  // Create a separate instance and reference table for each correlation type
447 
448  String reference_type_dbname;
449  String instance_type_dbname;
450  for (CorrelationAttributeInstance.Type type : DEFAULT_CORRELATION_TYPES) {
451  reference_type_dbname = EamDbUtil.correlationTypeToReferenceTableName(type);
452  instance_type_dbname = EamDbUtil.correlationTypeToInstanceTableName(type);
453 
454  stmt.execute(String.format(createArtifactInstancesTableTemplate, instance_type_dbname, instance_type_dbname));
455  stmt.execute(String.format(instancesCaseIdIdx, instance_type_dbname, instance_type_dbname));
456  stmt.execute(String.format(instancesDatasourceIdIdx, instance_type_dbname, instance_type_dbname));
457  stmt.execute(String.format(instancesValueIdx, instance_type_dbname, instance_type_dbname));
458  stmt.execute(String.format(instancesKnownStatusIdx, instance_type_dbname, instance_type_dbname));
459  stmt.execute(String.format(instancesObjectIdIdx, instance_type_dbname, instance_type_dbname));
460 
461  // FUTURE: allow more than the FILES type
462  if (type.getId() == CorrelationAttributeInstance.FILES_TYPE_ID) {
463  stmt.execute(String.format(createReferenceTypesTableTemplate.toString(), reference_type_dbname, reference_type_dbname));
464  stmt.execute(String.format(referenceTypesIdx1, reference_type_dbname, reference_type_dbname));
465  stmt.execute(String.format(referenceTypesIdx2, reference_type_dbname, reference_type_dbname));
466  }
467  }
468 
469  } catch (SQLException ex) {
470  LOGGER.log(Level.SEVERE, "Error initializing db schema.", ex); // NON-NLS
471  return false;
472  } catch (EamDbException ex) {
473  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
474  return false;
475  } finally {
477  }
478  return true;
479  }
480 
488  static String getCreateArtifactInstancesTableTemplate() {
489  // Each "%s" will be replaced with the relevant TYPE_instances table name.
490  StringBuilder createArtifactInstancesTableTemplate = new StringBuilder();
491  createArtifactInstancesTableTemplate.append("CREATE TABLE IF NOT EXISTS %s (");
492  createArtifactInstancesTableTemplate.append("id SERIAL PRIMARY KEY,");
493  createArtifactInstancesTableTemplate.append("case_id integer NOT NULL,");
494  createArtifactInstancesTableTemplate.append("data_source_id integer NOT NULL,");
495  createArtifactInstancesTableTemplate.append("value text NOT NULL,");
496  createArtifactInstancesTableTemplate.append("file_path text NOT NULL,");
497  createArtifactInstancesTableTemplate.append("known_status integer NOT NULL,");
498  createArtifactInstancesTableTemplate.append("comment text,");
499  createArtifactInstancesTableTemplate.append("file_obj_id integer,");
500  createArtifactInstancesTableTemplate.append("CONSTRAINT %s_multi_unique_ UNIQUE (data_source_id, value, file_path),");
501  createArtifactInstancesTableTemplate.append("foreign key (case_id) references cases(id) ON UPDATE SET NULL ON DELETE SET NULL,");
502  createArtifactInstancesTableTemplate.append("foreign key (data_source_id) references data_sources(id) ON UPDATE SET NULL ON DELETE SET NULL");
503  createArtifactInstancesTableTemplate.append(")");
504  return createArtifactInstancesTableTemplate.toString();
505  }
506 
515  static String getAddCaseIdIndexTemplate() {
516  // Each "%s" will be replaced with the relevant TYPE_instances table name.
517  return "CREATE INDEX IF NOT EXISTS %s_case_id ON %s (case_id)";
518  }
519 
528  static String getAddDataSourceIdIndexTemplate() {
529  // Each "%s" will be replaced with the relevant TYPE_instances table name.
530  return "CREATE INDEX IF NOT EXISTS %s_data_source_id ON %s (data_source_id)";
531  }
532 
541  static String getAddValueIndexTemplate() {
542  // Each "%s" will be replaced with the relevant TYPE_instances table name.
543  return "CREATE INDEX IF NOT EXISTS %s_value ON %s (value)";
544  }
545 
554  static String getAddKnownStatusIndexTemplate() {
555  // Each "%s" will be replaced with the relevant TYPE_instances table name.
556  return "CREATE INDEX IF NOT EXISTS %s_value_known_status ON %s (value, known_status)";
557  }
558 
567  static String getAddObjectIdIndexTemplate() {
568  // Each "%s" will be replaced with the relevant TYPE_instances table name.
569  return "CREATE INDEX IF NOT EXISTS %s_file_obj_id ON %s (file_obj_id)";
570  }
571 
572  public boolean insertDefaultDatabaseContent() {
573  Connection conn = getEphemeralConnection(false);
574  if (null == conn) {
575  return false;
576  }
577 
578  boolean result = EamDbUtil.insertDefaultCorrelationTypes(conn) && EamDbUtil.insertDefaultOrganization(conn);
580 
581  return result;
582  }
583 
584  boolean isChanged() {
585  String hostString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.host"); // NON-NLS
586  String portString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.port"); // NON-NLS
587  String dbNameString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.dbName"); // NON-NLS
588  String bulkThresholdString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.bulkThreshold"); // NON-NLS
589  String userNameString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.user"); // NON-NLS
590  String userPasswordString = ModuleSettings.getConfigSetting("CentralRepository", "db.postgresql.password"); // NON-NLS
591 
592  return !host.equals(hostString) || !Integer.toString(port).equals(portString)
593  || !dbName.equals(dbNameString) || !Integer.toString(bulkThreshold).equals(bulkThresholdString)
594  || !userName.equals(userNameString) || !password.equals(userPasswordString);
595  }
596 
600  public String getHost() {
601  return host;
602  }
603 
607  public void setHost(String host) throws EamDbException {
608  if (null != host && !host.isEmpty()) {
609  this.host = host;
610  } else {
611  throw new EamDbException("Invalid host name. Cannot be empty."); // NON-NLS
612  }
613  }
614 
618  public int getPort() {
619  return port;
620  }
621 
625  public void setPort(int port) throws EamDbException {
626  if (port > 0 && port < 65535) {
627  this.port = port;
628  } else {
629  throw new EamDbException("Invalid port. Must be a number greater than 0."); // NON-NLS
630  }
631  }
632 
639  public String getDbName() {
640  return dbName.toLowerCase();
641  }
642 
646  public void setDbName(String dbName) throws EamDbException {
647  if (dbName == null || dbName.isEmpty()) {
648  throw new EamDbException("Invalid database name. Cannot be empty."); // NON-NLS
649  } else if (!Pattern.matches(DB_NAMES_REGEX, dbName)) {
650  throw new EamDbException("Invalid database name. Name must start with a lowercase letter and can only contain lowercase letters, numbers, and '_'."); // NON-NLS
651  }
652 
653  this.dbName = dbName.toLowerCase();
654  }
655 
659  int getBulkThreshold() {
660  return bulkThreshold;
661  }
662 
666  public void setBulkThreshold(int bulkThreshold) throws EamDbException {
667  if (bulkThreshold > 0) {
668  this.bulkThreshold = bulkThreshold;
669  } else {
670  throw new EamDbException("Invalid bulk threshold."); // NON-NLS
671  }
672  }
673 
677  public String getUserName() {
678  return userName;
679  }
680 
684  public void setUserName(String userName) throws EamDbException {
685  if (userName == null || userName.isEmpty()) {
686  throw new EamDbException("Invalid user name. Cannot be empty."); // NON-NLS
687  } else if (!Pattern.matches(DB_USER_NAMES_REGEX, userName)) {
688  throw new EamDbException("Invalid user name. Name must start with a letter and can only contain letters, numbers, and '_'."); // NON-NLS
689  }
690  this.userName = userName;
691  }
692 
696  public String getPassword() {
697  return password;
698  }
699 
703  public void setPassword(String password) throws EamDbException {
704  if (password == null || password.isEmpty()) {
705  throw new EamDbException("Invalid user password. Cannot be empty."); // NON-NLS
706  }
707  this.password = password;
708  }
709 
713  String getValidationQuery() {
714  return VALIDATION_QUERY;
715  }
716 
720  String getDriver() {
721  return JDBC_DRIVER;
722  }
723 
727  String getJDBCBaseURI() {
728  return JDBC_BASE_URI;
729  }
730 
731 }
static String correlationTypeToInstanceTableName(CorrelationAttributeInstance.Type type)
Definition: EamDbUtil.java:325
static boolean executeValidationQuery(Connection conn, String validationQuery)
Definition: EamDbUtil.java:297
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static boolean insertDefaultCorrelationTypes(Connection conn)
Definition: EamDbUtil.java:102
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:336
static String convertTextToHexText(String property)
static String convertHexTextToText(String property)

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