public abstract class SQLUtility extends Object
SQL-related utility methods.
Implementation note: Many of these static methods use JDBC objects
which are difficult to mock out for unit tests. The methods now delegate to
an instance of SQLUtilityImpl instead. The instance is declared
private, but not final, so it can be
overridden for unit tests. For example, see
TestFieldSearchSQLImpl.java.
Some of the methods involve no JDBC objects, and so are not delegated to the instance.
| Constructor and Description |
|---|
SQLUtility() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addRow(Connection conn,
String table,
String[] columns,
String[] values,
boolean[] numeric)
Adds a new row.
|
static void |
createNonExistingTables(ConnectionPool cPool,
InputStream dbSpec) |
static ConnectionPool |
getConnectionPool(DatastoreConfiguration cpDC) |
static ConnectionPool |
getConnectionPool(ServerConfiguration fcfg) |
static Connection |
getDefaultConnection(ServerConfiguration serverConfig)
Gets a connection to the database specified in connection pool module's
"defaultPoolName" config value.
|
static String |
getLongString(ResultSet rs,
int pos)
Get a long string, which could be a TEXT or CLOB type.
|
static long |
getMostRecentRebuild(Connection conn) |
static boolean |
getRebuildStatus(Connection conn,
long rebuildDate) |
protected abstract void |
i_addRow(Connection conn,
String table,
String[] columns,
String[] values,
boolean[] numeric) |
protected abstract void |
i_createNonExistingTables(ConnectionPool pool,
InputStream dbSpec) |
protected abstract void |
i_createTables(TableCreatingConnection tcConn,
List<TableSpec> specs) |
protected abstract ConnectionPool |
i_getConnectionPool(DatastoreConfiguration cpDC) |
protected abstract String |
i_getLongString(ResultSet rs,
int pos) |
protected abstract long |
i_getMostRecentRebuild(Connection conn) |
protected abstract List<TableSpec> |
i_getNonExistingTables(Connection conn,
List<TableSpec> specs) |
protected abstract boolean |
i_getRebuildStatus(Connection conn,
long rebuildDate) |
protected abstract void |
i_recordSuccessfulRebuild(Connection conn,
long rebuildDate) |
protected abstract void |
i_replaceInto(Connection conn,
String table,
String[] columns,
String[] values,
String uniqueColumn,
boolean[] numeric) |
protected abstract boolean |
i_updateRow(Connection conn,
String table,
String[] columns,
String[] values,
String uniqueColumn,
boolean[] numeric) |
static void |
recordSuccessfulRebuild(Connection conn,
long rebuildDate) |
static void |
replaceInto(Connection conn,
String tableName,
String[] columns,
String[] values,
String uniqueColumn) |
static void |
replaceInto(Connection conn,
String table,
String[] columns,
String[] values,
String uniqueColumn,
boolean[] numeric)
Adds or replaces a row in the given table.
|
static boolean |
updateRow(Connection conn,
String table,
String[] columns,
String[] values,
String uniqueColumn,
boolean[] numeric)
Updates an existing row.
|
public static ConnectionPool getConnectionPool(ServerConfiguration fcfg) throws SQLException
SQLExceptionpublic static ConnectionPool getConnectionPool(DatastoreConfiguration cpDC) throws SQLException
SQLExceptionpublic static void replaceInto(Connection conn, String tableName, String[] columns, String[] values, String uniqueColumn) throws SQLException
SQLExceptionpublic static void replaceInto(Connection conn, String table, String[] columns, String[] values, String uniqueColumn, boolean[] numeric) throws SQLException
conn - the connection to usetable - the name of the tablecolumns - the names of the columns whose values we're setting.values - associated valuesuniqueColumn - which column name is unique? The value of this column will be used
in the where clause. It must be a column which is not numeric.numeric - for each associated column, is it numeric? if null, all columns
are assumed to be strings.SQLExceptionpublic static boolean updateRow(Connection conn, String table, String[] columns, String[] values, String uniqueColumn, boolean[] numeric) throws SQLException
SQLExceptionpublic static void addRow(Connection conn, String table, String[] columns, String[] values, boolean[] numeric) throws SQLException
SQLException - if the row could not be added.public static String getLongString(ResultSet rs, int pos) throws SQLException
SQLExceptionpublic static void createNonExistingTables(ConnectionPool cPool, InputStream dbSpec) throws IOException, InconsistentTableSpecException, SQLException
public static long getMostRecentRebuild(Connection conn) throws SQLException
SQLExceptionpublic static boolean getRebuildStatus(Connection conn, long rebuildDate) throws SQLException
SQLExceptionpublic static void recordSuccessfulRebuild(Connection conn, long rebuildDate) throws SQLException
SQLExceptionpublic static Connection getDefaultConnection(ServerConfiguration serverConfig)
protected abstract ConnectionPool i_getConnectionPool(DatastoreConfiguration cpDC) throws SQLException
SQLExceptionprotected abstract void i_replaceInto(Connection conn, String table, String[] columns, String[] values, String uniqueColumn, boolean[] numeric) throws SQLException
SQLExceptionprotected abstract boolean i_updateRow(Connection conn, String table, String[] columns, String[] values, String uniqueColumn, boolean[] numeric) throws SQLException
SQLExceptionprotected abstract void i_addRow(Connection conn, String table, String[] columns, String[] values, boolean[] numeric) throws SQLException
SQLExceptionprotected abstract void i_createNonExistingTables(ConnectionPool pool, InputStream dbSpec) throws IOException, InconsistentTableSpecException, SQLException
protected abstract List<TableSpec> i_getNonExistingTables(Connection conn, List<TableSpec> specs) throws SQLException
SQLExceptionprotected abstract void i_createTables(TableCreatingConnection tcConn, List<TableSpec> specs) throws SQLException
SQLExceptionprotected abstract String i_getLongString(ResultSet rs, int pos) throws SQLException
SQLExceptionprotected abstract long i_getMostRecentRebuild(Connection conn) throws SQLException
SQLExceptionprotected abstract boolean i_getRebuildStatus(Connection conn, long rebuildDate) throws SQLException
SQLExceptionprotected abstract void i_recordSuccessfulRebuild(Connection conn, long rebuildDate) throws SQLException
SQLExceptionCopyright © 2013 DuraSpace. All Rights Reserved.