Removed commented code.

This commit is contained in:
Raman Arora 2020-02-11 11:58:09 -05:00
parent b79b91f502
commit ac8256b102

View File

@ -34,9 +34,7 @@ public class RdbmsCentralRepoSchemaFactory {
private final static Logger LOGGER = Logger.getLogger(RdbmsCentralRepoSchemaFactory.class.getName()); private final static Logger LOGGER = Logger.getLogger(RdbmsCentralRepoSchemaFactory.class.getName());
private static RdbmsCentralRepoSchemaFactory instance;
private final RdbmsCentralRepo rdbmsCentralRepo; private final RdbmsCentralRepo rdbmsCentralRepo;
private final CentralRepoPlatforms selectedPlatform; private final CentralRepoPlatforms selectedPlatform;
// SQLite pragmas // SQLite pragmas
@ -252,194 +250,11 @@ public class RdbmsCentralRepoSchemaFactory {
return true; return true;
} }
// TBD RAMAN - temporary container to store all Pstgres methods, till we unify... /**
// public static class PostgresCRSchemaCreator { * Inserts default data in CR database.
// *
// /** * @return True if success, False otherwise.
// * Initialize the database schema. */
// *
// * Requires valid connectionPool.
// *
// * This method is called from within connect(), so we cannot call
// * connect() to get a connection. This method is called after
// * setupConnectionPool(), so it is safe to assume that a valid
// * connectionPool exists. The implementation of connect() is
// * synchronized, so we can safely use the connectionPool object
// * directly.
// */
// public static boolean initializeDatabaseSchema(RdbmsCentralRepo rdbmsCentralRepo, CentralRepoPlatforms selectedPlatform) {
// // The "id" column is an alias for the built-in 64-bit int "rowid" column.
// // It is autoincrementing by default and must be of type "integer primary key".
// // We've omitted the autoincrement argument because we are not currently
// // using the id value to search for specific rows, so we do not care
// // if a rowid is re-used after an existing rows was previously deleted.
// StringBuilder createOrganizationsTable = new StringBuilder();
// createOrganizationsTable.append("CREATE TABLE IF NOT EXISTS organizations (");
// //createOrganizationsTable.append("id SERIAL PRIMARY KEY,");
// createOrganizationsTable.append(getNumericPrimaryKeyClause("id", selectedPlatform ));
// createOrganizationsTable.append("org_name text NOT NULL,");
// createOrganizationsTable.append("poc_name text NOT NULL,");
// createOrganizationsTable.append("poc_email text NOT NULL,");
// createOrganizationsTable.append("poc_phone text NOT NULL,");
// createOrganizationsTable.append("CONSTRAINT org_name_unique UNIQUE (org_name)");
// createOrganizationsTable.append(")");
//
// // NOTE: The organizations will only have a small number of rows, so
// // an index is probably not worthwhile.
// StringBuilder createCasesTable = new StringBuilder();
// createCasesTable.append("CREATE TABLE IF NOT EXISTS cases (");
// createCasesTable.append(getNumericPrimaryKeyClause("id", selectedPlatform ));
// //createCasesTable.append("id SERIAL PRIMARY KEY,");
// createCasesTable.append("case_uid text NOT NULL,");
// createCasesTable.append("org_id integer,");
// createCasesTable.append("case_name text NOT NULL,");
// createCasesTable.append("creation_date text NOT NULL,");
// createCasesTable.append("case_number text,");
// createCasesTable.append("examiner_name text,");
// createCasesTable.append("examiner_email text,");
// createCasesTable.append("examiner_phone text,");
// createCasesTable.append("notes text,");
// createCasesTable.append("foreign key (org_id) references organizations(id) ON UPDATE SET NULL ON DELETE SET NULL,");
// //createCasesTable.append("CONSTRAINT case_uid_unique UNIQUE (case_uid)");
// createCasesTable.append("CONSTRAINT case_uid_unique UNIQUE (case_uid)" ).append(getOnConflictIgnoreClause(selectedPlatform));
// createCasesTable.append(")");
//
// // NOTE: when there are few cases in the cases table, these indices may not be worthwhile
// String casesIdx1 = "CREATE INDEX IF NOT EXISTS cases_org_id ON cases (org_id)";
// String casesIdx2 = "CREATE INDEX IF NOT EXISTS cases_case_uid ON cases (case_uid)";
//
// StringBuilder createReferenceSetsTable = new StringBuilder();
// createReferenceSetsTable.append("CREATE TABLE IF NOT EXISTS reference_sets (");
// createReferenceSetsTable.append(getNumericPrimaryKeyClause("id", selectedPlatform ));
// //createReferenceSetsTable.append("id SERIAL PRIMARY KEY,");
// createReferenceSetsTable.append("org_id integer NOT NULL,");
// createReferenceSetsTable.append("set_name text NOT NULL,");
// createReferenceSetsTable.append("version text NOT NULL,");
// createReferenceSetsTable.append("known_status integer NOT NULL,");
// createReferenceSetsTable.append("read_only boolean NOT NULL,");
// createReferenceSetsTable.append("type integer NOT NULL,");
// createReferenceSetsTable.append("import_date text NOT NULL,");
// createReferenceSetsTable.append("foreign key (org_id) references organizations(id) ON UPDATE SET NULL ON DELETE SET NULL,");
// createReferenceSetsTable.append("CONSTRAINT hash_set_unique UNIQUE (set_name, version)");
// createReferenceSetsTable.append(")");
//
// String referenceSetsIdx1 = "CREATE INDEX IF NOT EXISTS reference_sets_org_id ON reference_sets (org_id)";
//
// // Each "%s" will be replaced with the relevant reference_TYPE table name.
// StringBuilder createReferenceTypesTableTemplate = new StringBuilder();
// createReferenceTypesTableTemplate.append("CREATE TABLE IF NOT EXISTS %s (");
// createReferenceTypesTableTemplate.append(getNumericPrimaryKeyClause("id", selectedPlatform ));
// createReferenceTypesTableTemplate.append("reference_set_id integer,");
// createReferenceTypesTableTemplate.append("value text NOT NULL,");
// createReferenceTypesTableTemplate.append("known_status integer NOT NULL,");
// createReferenceTypesTableTemplate.append("comment text,");
// createReferenceTypesTableTemplate.append("CONSTRAINT %s_multi_unique UNIQUE(reference_set_id, value)").append(getOnConflictIgnoreClause(selectedPlatform)).append(",");
// createReferenceTypesTableTemplate.append("foreign key (reference_set_id) references reference_sets(id) ON UPDATE SET NULL ON DELETE SET NULL");
// createReferenceTypesTableTemplate.append(")");
//
// // Each "%s" will be replaced with the relevant reference_TYPE table name.
// String referenceTypesIdx1 = "CREATE INDEX IF NOT EXISTS %s_value ON %s (value)";
// String referenceTypesIdx2 = "CREATE INDEX IF NOT EXISTS %s_value_known_status ON %s (value, known_status)";
//
// StringBuilder createCorrelationTypesTable = new StringBuilder();
// createCorrelationTypesTable.append("CREATE TABLE IF NOT EXISTS correlation_types (");
// createCorrelationTypesTable.append(getNumericPrimaryKeyClause("id", selectedPlatform ));
// createCorrelationTypesTable.append("display_name text NOT NULL,");
// createCorrelationTypesTable.append("db_table_name text NOT NULL,");
// createCorrelationTypesTable.append("supported integer NOT NULL,");
// createCorrelationTypesTable.append("enabled integer NOT NULL,");
// createCorrelationTypesTable.append("CONSTRAINT correlation_types_names UNIQUE (display_name, db_table_name)");
// createCorrelationTypesTable.append(")");
//
// String createArtifactInstancesTableTemplate = getCreateArtifactInstancesTableTemplate(selectedPlatform);
//
// String instancesCaseIdIdx = getAddCaseIdIndexTemplate();
// String instancesDatasourceIdIdx = getAddDataSourceIdIndexTemplate();
// String instancesValueIdx = getAddValueIndexTemplate();
// String instancesKnownStatusIdx = getAddKnownStatusIndexTemplate();
// String instancesObjectIdIdx = getAddObjectIdIndexTemplate();
//
// // NOTE: the db_info table currenly only has 1 row, so having an index
// // provides no benefit.
// Connection conn = null;
// try {
// conn = rdbmsCentralRepo.getEphemeralConnection();
// if (null == conn) {
// return false;
// }
// Statement stmt = conn.createStatement();
//
// stmt.execute(createOrganizationsTable.toString());
//
// stmt.execute(createCasesTable.toString());
// stmt.execute(casesIdx1);
// stmt.execute(casesIdx2);
//
// stmt.execute(getCreateDataSourcesTableStatement(selectedPlatform));
// stmt.execute(getAddDataSourcesNameIndexStatement());
// stmt.execute(getAddDataSourcesObjectIdIndexStatement());
//
// stmt.execute(createReferenceSetsTable.toString());
// stmt.execute(referenceSetsIdx1);
//
// stmt.execute(createCorrelationTypesTable.toString());
//
// /*
// * Note that the essentially useless id column in the following
// * table is required for backwards compatibility. Otherwise, the
// * name column could be the primary key.
// */
// StringBuilder dbInfoTable = new StringBuilder();
// dbInfoTable.append("CREATE TABLE db_info (");
// dbInfoTable.append(getNumericPrimaryKeyClause("id", selectedPlatform));
// dbInfoTable.append("name TEXT UNIQUE NOT NULL,");
// dbInfoTable.append("value TEXT NOT NULL )");
//
// stmt.execute(dbInfoTable.toString());
// stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + RdbmsCentralRepo.SCHEMA_MAJOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "')");
// stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + RdbmsCentralRepo.SCHEMA_MINOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "')");
// stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + RdbmsCentralRepo.CREATION_SCHEMA_MAJOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMajor() + "')");
// stmt.execute("INSERT INTO db_info (name, value) VALUES ('" + RdbmsCentralRepo.CREATION_SCHEMA_MINOR_VERSION_KEY + "', '" + SOFTWARE_CR_DB_SCHEMA_VERSION.getMinor() + "')");
//
// // Create a separate instance and reference table for each correlation type
// List<CorrelationAttributeInstance.Type> DEFAULT_CORRELATION_TYPES = CorrelationAttributeInstance.getDefaultCorrelationTypes();
//
// String reference_type_dbname;
// String instance_type_dbname;
// for (CorrelationAttributeInstance.Type type : DEFAULT_CORRELATION_TYPES) {
// reference_type_dbname = CentralRepoDbUtil.correlationTypeToReferenceTableName(type);
// instance_type_dbname = CentralRepoDbUtil.correlationTypeToInstanceTableName(type);
//
// stmt.execute(String.format(createArtifactInstancesTableTemplate, instance_type_dbname, instance_type_dbname));
// stmt.execute(String.format(instancesCaseIdIdx, instance_type_dbname, instance_type_dbname));
// stmt.execute(String.format(instancesDatasourceIdIdx, instance_type_dbname, instance_type_dbname));
// stmt.execute(String.format(instancesValueIdx, instance_type_dbname, instance_type_dbname));
// stmt.execute(String.format(instancesKnownStatusIdx, instance_type_dbname, instance_type_dbname));
// stmt.execute(String.format(instancesObjectIdIdx, instance_type_dbname, instance_type_dbname));
//
// // FUTURE: allow more than the FILES type
// if (type.getId() == CorrelationAttributeInstance.FILES_TYPE_ID) {
// stmt.execute(String.format(createReferenceTypesTableTemplate.toString(), reference_type_dbname, reference_type_dbname));
// stmt.execute(String.format(referenceTypesIdx1, reference_type_dbname, reference_type_dbname));
// stmt.execute(String.format(referenceTypesIdx2, reference_type_dbname, reference_type_dbname));
// }
// }
//
// } catch (SQLException ex) {
// LOGGER.log(Level.SEVERE, "Error initializing db schema.", ex); // NON-NLS
// return false;
// } catch (CentralRepoException ex) {
// 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
// return false;
// } finally {
// CentralRepoDbUtil.closeConnection(conn);
// }
// return true;
// }
//
//
//
// }
public boolean insertDefaultDatabaseContent() { public boolean insertDefaultDatabaseContent() {
Connection conn = rdbmsCentralRepo.getEphemeralConnection(); Connection conn = rdbmsCentralRepo.getEphemeralConnection();
if (null == conn) { if (null == conn) {