to.etc.dbutil
Class GenericDB

java.lang.Object
  extended by to.etc.dbutil.GenericDB

public class GenericDB
extends java.lang.Object

A generic database access class to hide differences between databases.

Version:
1.0
Author:
F. Jalvingh

Field Summary
static BaseDB dbtypeMYSQL
           
static BaseDB dbtypeORACLE
           
static BaseDB dbtypeORANXO
           
static BaseDB dbtypePOSTGRESQL
           
static BaseDB dbtypeUNKNOWN
           
 
Method Summary
static java.lang.String getCheckString(BaseDB dbtype)
           
static BaseDB getDbType(java.sql.Connection dbc)
          Tries to return a database type for the connection passed.
static BaseDB getDbTypeByDriverName(java.lang.String dn)
           
static int getFullSequenceID(java.sql.Connection dbc, java.lang.String tablename)
           
static java.io.Reader getLobReader(java.sql.Connection dbc, java.sql.ResultSet rs, int col)
          Returns a Reader from the blob (clob) column specified.
static java.io.Reader getLobReader(java.sql.Connection dbc, java.sql.ResultSet rs, java.lang.String col)
          Returns a Reader from the blob (clob) column specified.
static java.io.InputStream getLobStream(java.sql.Connection dbc, java.sql.ResultSet rs, int col)
          Returns an InputStream from the blob (clob) column specified.
static java.io.InputStream getLobStream(java.sql.Connection dbc, java.sql.ResultSet rs, java.lang.String col)
          Returns an InputStream from the blob (clob) column specified.
static int getSequenceID(java.sql.Connection dbc, java.lang.String tablename)
          Returns a sequence number that can be used to create a new PK for a record in the given table.
static boolean saveBlob(java.sql.ResultSet rs, int col, java.io.File f)
          Saves a BLOB from a resultset to a file using Oracle semantics.
static boolean saveBlob(java.sql.ResultSet rs, int col, java.io.OutputStream os)
           
static boolean saveBlob(java.sql.ResultSet rs, java.lang.String col, java.io.File f)
           
static void setBlob(java.sql.Connection dbc, java.lang.String table, java.lang.String column, java.lang.String[] pkfields, java.lang.Object[] key, java.io.File f)
           
static void setBlob(java.sql.Connection dbc, java.lang.String table, java.lang.String column, java.lang.String[] pkfields, java.lang.Object[] key, java.io.InputStream is)
           
static void setBlob(java.sql.Connection dbc, java.lang.String table, java.lang.String column, java.lang.String where, byte[][] data)
          Writes a blob to the requested record.
static void setBlob(java.sql.Connection dbc, java.lang.String table, java.lang.String column, java.lang.String where, java.io.File f)
          Writes a blob to the requested record.
static void setBlob(java.sql.Connection dbc, java.lang.String table, java.lang.String column, java.lang.String where, java.io.InputStream is)
          Writes a blob to the requested record.
static void setBlob(java.sql.Connection dbc, java.lang.String table, java.lang.String column, java.lang.String where, java.lang.String str)
           
static void setClob(java.sql.Connection dbc, java.lang.String table, java.lang.String column, java.lang.String where, java.io.Reader r)
           
static void setClob(java.sql.Connection dbc, java.lang.String table, java.lang.String column, java.lang.String where, java.lang.String content)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dbtypeUNKNOWN

public static final BaseDB dbtypeUNKNOWN

dbtypeORACLE

public static final BaseDB dbtypeORACLE

dbtypeMYSQL

public static final BaseDB dbtypeMYSQL

dbtypePOSTGRESQL

public static final BaseDB dbtypePOSTGRESQL

dbtypeORANXO

public static final BaseDB dbtypeORANXO
Method Detail

getDbType

public static BaseDB getDbType(java.sql.Connection dbc)
Tries to return a database type for the connection passed. TODO: Need to be replaced with generic accept() in base specific class

Parameters:
dbc - the connection to check
Returns:
a dbtype for the connection.

getDbTypeByDriverName

public static BaseDB getDbTypeByDriverName(java.lang.String dn)

getSequenceID

public static int getSequenceID(java.sql.Connection dbc,
                                java.lang.String tablename)
                         throws java.sql.SQLException
Returns a sequence number that can be used to create a new PK for a record in the given table. Sequences are emulated on databases that do not support 'm.

Parameters:
dbc -
tablename -
Returns:
Throws:
java.sql.SQLException

getFullSequenceID

public static int getFullSequenceID(java.sql.Connection dbc,
                                    java.lang.String tablename)
                             throws java.sql.SQLException
Throws:
java.sql.SQLException

getCheckString

public static java.lang.String getCheckString(BaseDB dbtype)

setBlob

public static void setBlob(java.sql.Connection dbc,
                           java.lang.String table,
                           java.lang.String column,
                           java.lang.String where,
                           java.io.File f)
                    throws java.lang.Exception
Writes a blob to the requested record. Works for Oral and MYSQL.

Throws:
java.lang.Exception

setBlob

public static void setBlob(java.sql.Connection dbc,
                           java.lang.String table,
                           java.lang.String column,
                           java.lang.String where,
                           java.lang.String str)
                    throws java.lang.Exception
Throws:
java.lang.Exception

setBlob

public static void setBlob(java.sql.Connection dbc,
                           java.lang.String table,
                           java.lang.String column,
                           java.lang.String where,
                           java.io.InputStream is)
                    throws java.lang.Exception
Writes a blob to the requested record.

Throws:
java.lang.Exception

setBlob

public static void setBlob(java.sql.Connection dbc,
                           java.lang.String table,
                           java.lang.String column,
                           java.lang.String where,
                           byte[][] data)
                    throws java.lang.Exception
Writes a blob to the requested record.

Throws:
java.lang.Exception

setBlob

public static void setBlob(java.sql.Connection dbc,
                           java.lang.String table,
                           java.lang.String column,
                           java.lang.String[] pkfields,
                           java.lang.Object[] key,
                           java.io.InputStream is)
                    throws java.sql.SQLException
Throws:
java.sql.SQLException

setBlob

public static void setBlob(java.sql.Connection dbc,
                           java.lang.String table,
                           java.lang.String column,
                           java.lang.String[] pkfields,
                           java.lang.Object[] key,
                           java.io.File f)
                    throws java.sql.SQLException
Throws:
java.sql.SQLException

getLobReader

public static java.io.Reader getLobReader(java.sql.Connection dbc,
                                          java.sql.ResultSet rs,
                                          int col)
                                   throws java.lang.Exception
Returns a Reader from the blob (clob) column specified.

Parameters:
rs -
col -
Returns:
Throws:
java.lang.Exception

getLobReader

public static java.io.Reader getLobReader(java.sql.Connection dbc,
                                          java.sql.ResultSet rs,
                                          java.lang.String col)
                                   throws java.lang.Exception
Returns a Reader from the blob (clob) column specified.

Parameters:
rs -
col -
Returns:
Throws:
java.lang.Exception

getLobStream

public static java.io.InputStream getLobStream(java.sql.Connection dbc,
                                               java.sql.ResultSet rs,
                                               int col)
                                        throws java.lang.Exception
Returns an InputStream from the blob (clob) column specified.

Parameters:
rs -
col -
Returns:
Throws:
java.lang.Exception

getLobStream

public static java.io.InputStream getLobStream(java.sql.Connection dbc,
                                               java.sql.ResultSet rs,
                                               java.lang.String col)
                                        throws java.lang.Exception
Returns an InputStream from the blob (clob) column specified.

Parameters:
rs -
col -
Returns:
Throws:
java.lang.Exception

setClob

public static void setClob(java.sql.Connection dbc,
                           java.lang.String table,
                           java.lang.String column,
                           java.lang.String where,
                           java.io.Reader r)
                    throws java.lang.Exception
Throws:
java.lang.Exception

setClob

public static void setClob(java.sql.Connection dbc,
                           java.lang.String table,
                           java.lang.String column,
                           java.lang.String where,
                           java.lang.String content)
                    throws java.lang.Exception
Throws:
java.lang.Exception

saveBlob

public static boolean saveBlob(java.sql.ResultSet rs,
                               int col,
                               java.io.File f)
                        throws java.lang.Exception
Saves a BLOB from a resultset to a file using Oracle semantics.

Throws:
java.lang.Exception

saveBlob

public static boolean saveBlob(java.sql.ResultSet rs,
                               java.lang.String col,
                               java.io.File f)
                        throws java.lang.Exception
Throws:
java.lang.Exception

saveBlob

public static boolean saveBlob(java.sql.ResultSet rs,
                               int col,
                               java.io.OutputStream os)
                        throws java.lang.Exception
Throws:
java.lang.Exception