org.fcrepo.server.utilities
Class SQLUtility

java.lang.Object
  extended by org.fcrepo.server.utilities.SQLUtility

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.

Author:
Chris Wilper

Constructor Summary
SQLUtility()
           
 
Method Summary
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 String getLongString(ResultSet rs, int pos)
          Get a long string, which could be a TEXT or CLOB type.
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  List<TableSpec> i_getNonExistingTables(Connection conn, List<TableSpec> specs)
           
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 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLUtility

public SQLUtility()
Method Detail

getConnectionPool

public static ConnectionPool getConnectionPool(ServerConfiguration fcfg)
                                        throws SQLException
Throws:
SQLException

getConnectionPool

public static ConnectionPool getConnectionPool(DatastoreConfiguration cpDC)
                                        throws SQLException
Throws:
SQLException

replaceInto

public static void replaceInto(Connection conn,
                               String tableName,
                               String[] columns,
                               String[] values,
                               String uniqueColumn)
                        throws SQLException
Throws:
SQLException

replaceInto

public static void replaceInto(Connection conn,
                               String table,
                               String[] columns,
                               String[] values,
                               String uniqueColumn,
                               boolean[] numeric)
                        throws SQLException
Adds or replaces a row in the given table.

Parameters:
conn - the connection to use
table - the name of the table
columns - the names of the columns whose values we're setting.
values - associated values
uniqueColumn - 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.
Throws:
SQLException

updateRow

public static boolean updateRow(Connection conn,
                                String table,
                                String[] columns,
                                String[] values,
                                String uniqueColumn,
                                boolean[] numeric)
                         throws SQLException
Updates an existing row.

Returns:
false if the row did not previously exist and therefore was not updated.
Throws:
SQLException

addRow

public static void addRow(Connection conn,
                          String table,
                          String[] columns,
                          String[] values,
                          boolean[] numeric)
                   throws SQLException
Adds a new row.

Throws:
SQLException - if the row could not be added.

getLongString

public static String getLongString(ResultSet rs,
                                   int pos)
                            throws SQLException
Get a long string, which could be a TEXT or CLOB type. (CLOBs require special handling -- this method normalizes the reading of them)

Throws:
SQLException

createNonExistingTables

public static void createNonExistingTables(ConnectionPool cPool,
                                           InputStream dbSpec)
                                    throws IOException,
                                           InconsistentTableSpecException,
                                           SQLException
Throws:
IOException
InconsistentTableSpecException
SQLException

i_getConnectionPool

protected abstract ConnectionPool i_getConnectionPool(DatastoreConfiguration cpDC)
                                               throws SQLException
Throws:
SQLException

i_replaceInto

protected abstract void i_replaceInto(Connection conn,
                                      String table,
                                      String[] columns,
                                      String[] values,
                                      String uniqueColumn,
                                      boolean[] numeric)
                               throws SQLException
Throws:
SQLException

i_updateRow

protected abstract boolean i_updateRow(Connection conn,
                                       String table,
                                       String[] columns,
                                       String[] values,
                                       String uniqueColumn,
                                       boolean[] numeric)
                                throws SQLException
Throws:
SQLException

i_addRow

protected abstract void i_addRow(Connection conn,
                                 String table,
                                 String[] columns,
                                 String[] values,
                                 boolean[] numeric)
                          throws SQLException
Throws:
SQLException

i_createNonExistingTables

protected abstract void i_createNonExistingTables(ConnectionPool pool,
                                                  InputStream dbSpec)
                                           throws IOException,
                                                  InconsistentTableSpecException,
                                                  SQLException
Throws:
IOException
InconsistentTableSpecException
SQLException

i_getNonExistingTables

protected abstract List<TableSpec> i_getNonExistingTables(Connection conn,
                                                          List<TableSpec> specs)
                                                   throws SQLException
Throws:
SQLException

i_createTables

protected abstract void i_createTables(TableCreatingConnection tcConn,
                                       List<TableSpec> specs)
                                throws SQLException
Throws:
SQLException

i_getLongString

protected abstract String i_getLongString(ResultSet rs,
                                          int pos)
                                   throws SQLException
Throws:
SQLException


Copyright © 2011 DuraSpace. All Rights Reserved.