fedora.server.utilities
Class SQLUtility

java.lang.Object
  extended by fedora.server.utilities.SQLUtility

public abstract class SQLUtility
extends java.lang.Object

SQL-related utility methods.

Version:
$Id: SQLUtility.java 5999 2007-04-05 17:23:10Z cwilper $
Author:
cwilper@cs.cornell.edu

Constructor Summary
SQLUtility()
           
 
Method Summary
static void addRow(java.sql.Connection conn, java.lang.String table, java.lang.String[] columns, java.lang.String[] values, boolean[] numeric)
          Adds a new row.
static java.lang.String aposEscape(java.lang.String in)
           
static java.lang.String backslashEscape(java.lang.String in)
           
static void closeStatement(java.sql.Statement stmt)
           
static void createNonExistingTables(ConnectionPool cPool, java.io.InputStream dbSpec)
           
static void createTables(TableCreatingConnection tcConn, java.util.List tSpecs)
           
static ConnectionPool getConnectionPool(DatastoreConfiguration cpDC)
           
static ConnectionPool getConnectionPool(ServerConfiguration fcfg)
           
static java.lang.String getLongString(java.sql.ResultSet rs, int pos)
          Get a long string, which could be a TEXT or CLOB type.
static java.util.List getNonExistingTables(java.sql.Connection conn, java.util.List tSpecs)
           
static void replaceInto(java.sql.Connection conn, java.lang.String tableName, java.lang.String[] columns, java.lang.String[] values, java.lang.String uniqueColumn)
           
static void replaceInto(java.sql.Connection conn, java.lang.String table, java.lang.String[] columns, java.lang.String[] values, java.lang.String uniqueColumn, boolean[] numeric)
          Adds or replaces a row in the given table.
static java.lang.String slashEscaped(java.lang.String in)
           
static boolean updateRow(java.sql.Connection conn, java.lang.String table, java.lang.String[] columns, java.lang.String[] values, java.lang.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 java.sql.SQLException
Throws:
java.sql.SQLException

getConnectionPool

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

replaceInto

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

replaceInto

public static void replaceInto(java.sql.Connection conn,
                               java.lang.String table,
                               java.lang.String[] columns,
                               java.lang.String[] values,
                               java.lang.String uniqueColumn,
                               boolean[] numeric)
                        throws java.sql.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:
java.sql.SQLException

updateRow

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

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

addRow

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

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

slashEscaped

public static java.lang.String slashEscaped(java.lang.String in)

getLongString

public static java.lang.String getLongString(java.sql.ResultSet rs,
                                             int pos)
                                      throws java.sql.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:
java.sql.SQLException

createNonExistingTables

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

getNonExistingTables

public static java.util.List getNonExistingTables(java.sql.Connection conn,
                                                  java.util.List tSpecs)
                                           throws java.sql.SQLException
Throws:
java.sql.SQLException

createTables

public static void createTables(TableCreatingConnection tcConn,
                                java.util.List tSpecs)
                         throws java.sql.SQLException
Throws:
java.sql.SQLException

backslashEscape

public static java.lang.String backslashEscape(java.lang.String in)

aposEscape

public static java.lang.String aposEscape(java.lang.String in)

closeStatement

public static void closeStatement(java.sql.Statement stmt)