Add a method to return 'DSpace internal' DBMS names from a controlled vocabulary

This commit is contained in:
Mark H. Wood
2014-09-25 11:09:42 -04:00
parent bd65b62d1b
commit 9b8be34b72
3 changed files with 36 additions and 3 deletions

View File

@@ -64,6 +64,9 @@ public class DatabaseManager
/** Name of the DBMS, as returned by its driver. */ /** Name of the DBMS, as returned by its driver. */
private static String dbms; private static String dbms;
/** Name of the DBMS, as used in DSpace: "postgres", "oracle", or "h2". */
private static String dbms_keyword;
/** Name to use for the pool */ /** Name to use for the pool */
private static String poolName = "dspacepool"; private static String poolName = "dspacepool";
@@ -1484,16 +1487,19 @@ public class DatabaseManager
if (dbms_lc.contains("postgresql")) if (dbms_lc.contains("postgresql"))
{ {
isPostgres = true; isPostgres = true;
dbms_keyword = "postgres";
log.info("DBMS is PostgreSQL"); log.info("DBMS is PostgreSQL");
} }
else if (dbms_lc.contains("oracle")) else if (dbms_lc.contains("oracle"))
{ {
isOracle = true; isOracle = true;
dbms_keyword = "oracle";
log.info("DBMS is Oracle Database"); log.info("DBMS is Oracle Database");
} }
else if (dbms_lc.contains("h2")) // Used in testing else if (dbms_lc.contains("h2")) // Used in testing
{ {
isOracle = true; isOracle = true;
dbms_keyword = "h2";
log.info("DBMS is H2"); log.info("DBMS is H2");
} }
else else
@@ -1534,6 +1540,20 @@ public class DatabaseManager
return dbms; return dbms;
} }
/**
* What is the string that we use to name the DBMS brand?
*
* @return a normalized "keyword" for the DBMS brand: postgres, oracle, h2.
*/
public static String getDbKeyword()
{
try {
initialize();
} catch (SQLException ex) {
log.error("Failed to initialize the database: ", ex);
}
return dbms_keyword;
}
/** /**
* Iterate over the given parameters and add them to the given prepared statement. * Iterate over the given parameters and add them to the given prepared statement.
* Only a select number of datatypes are supported by the JDBC driver. * Only a select number of datatypes are supported by the JDBC driver.

View File

@@ -67,7 +67,7 @@ public class InitializeDatabase
*/ */
private static FileReader getScript(String name) throws FileNotFoundException, IOException private static FileReader getScript(String name) throws FileNotFoundException, IOException
{ {
String dbName = DatabaseManager.getDbName().toLowerCase(Locale.ROOT); String dbName = DatabaseManager.getDbKeyword();
File myFile = null; File myFile = null;

View File

@@ -56,7 +56,7 @@ public class DatabaseManagerTest
System.out.println("isOracle"); System.out.println("isOracle");
boolean expResult = true; boolean expResult = true;
boolean result = DatabaseManager.isOracle(); boolean result = DatabaseManager.isOracle();
assertEquals(expResult, result); assertEquals("isOracle is true for Oracle-like DBMSs", expResult, result);
} }
/** /**
@@ -630,7 +630,20 @@ public class DatabaseManagerTest
System.out.println("getDbName"); System.out.println("getDbName");
String expResult = "H2"; String expResult = "H2";
String result = DatabaseManager.getDbName(); String result = DatabaseManager.getDbName();
assertEquals(expResult, result); assertEquals("Database name names the configured database driver",
expResult, result);
}
/**
* Test of getDbKeyword method, of class DatabaseManager.
*/
@Test
public void testGetDbKeyword()
{
System.out.println("getDbKeyword");
String expResult = "h2";
String result = DatabaseManager.getDbKeyword();
assertEquals("Database 'keyword' names the configured DBMS", expResult, result);
} }
/** /**