org.ephman.abra.database
Class GenericFactoryBase

java.lang.Object
  |
  +--org.ephman.abra.database.GenericFactoryBase
Direct Known Subclasses:
FactoryBase

public abstract class GenericFactoryBase
extends java.lang.Object

FactoryBase class - base for all the JDBC based db factories.

Version:
0.1
Author:
TPR

Nested Class Summary
(package private)  class GenericFactoryBase.QueryResult
           
 
Field Summary
protected  int DEEP
           
protected  boolean endDates
           
protected  int SHALLOW
           
static java.lang.String VERSION_NUMBER
           
 
Constructor Summary
GenericFactoryBase()
           
 
Method Summary
protected  void checkRefresh(DatabaseSession dbSess, Identified item)
           
protected  void checkRefresh(DatabaseSession dbSess, Identified item, java.sql.ResultSet rs)
          routine to check if an object is up to date..
 int countRows(DatabaseSession dbSess, QueryFilter filter)
          A routine to count the number of rows in a query which returns the count of hits
 DatabaseCursor cursorQuery(DatabaseSession dbSess, QueryFilter query)
          A routine to perform a search given a filter which returns the Vector of oid hits in a DatabaseCursor object this allows small range retrievals with any type of data abstraction
 DatabaseCursor cursorQuery(DatabaseSession dbSess, QueryFilter query, SortCriteria sortBy)
          A routine to perform a search given a filter and an ordering which returns the Vector of oid hits in a DatabaseCursor object this allows small range retrievals with any type of data abstraction
 DatabaseCursor cursorQuery(DatabaseSession dbSess, SortCriteria sortBy)
          A routine to perform a search given an ordering which returns the Vector of oid hits in a DatabaseCursor object this allows small range retrievals with any type of data abstraction
protected  DatabaseCursor cursorRawQuery(DatabaseSession dbSess, java.lang.String sql)
          Raw query returns DatabaseCursor - to be used in descendant classes
protected  DatabaseCursor cursorStoredProcCall(DatabaseSession dbSess, java.lang.String procCall, java.util.Vector args, SortCriteria sort)
           
abstract  boolean dbNeedsId()
           
protected  void deepRetrieval(DatabaseSession dbSess, Identified item)
           
protected  void deepStorage(DatabaseSession dbSess, Identified item)
           
protected  boolean defaultNeedsWhereLogic()
           
protected  void deleteObject(DatabaseSession dbSess, Identified item)
           
protected  int deleteObjects(DatabaseSession dbSess, QueryFilter filter)
          deleteObjects will delete all the rows which match the given filter
 void flushCache()
           
protected  java.lang.String getBooleanAsString(java.lang.Boolean b)
           
 java.util.Vector getCollection(DatabaseSession dbSess, java.sql.ResultSet rs)
           
protected  java.sql.Connection getConnection(DatabaseSession dbSess)
           
protected  java.lang.String getDeleteSql(QueryFilter filter)
           
protected abstract  int getLastId(DatabaseSession dbSess)
           
protected  int getLastId(DatabaseSession dbSess, java.sql.PreparedStatement stmt)
           
 Identified getObject(DatabaseSession dbSess, QueryFilter query)
          A routine to get a single object given a filter
protected  Identified getObject(DatabaseSession dbSess, java.lang.String columnName, int value)
           
protected  Identified getObject(DatabaseSession dbSess, java.lang.String columnName, java.lang.String value)
           
protected abstract  java.lang.String getPrimaryColumn()
           
protected  GenericFactoryBase.QueryResult getResults(DatabaseSession dbSess, java.lang.String sql, int key)
          get results and set key in first arg..
protected  GenericFactoryBase.QueryResult getResults(DatabaseSession dbSess, java.lang.String sql, QueryFilter filter, SortCriteria sc)
          a helper routine to build a query and execute
protected  GenericFactoryBase.QueryResult getResults(DatabaseSession dbSess, java.lang.String sql, QueryFilter filter, SortCriteria sc, boolean needsWhereLogic, java.lang.String tableName)
           
protected  java.lang.String getSelectCountSql()
           
protected  java.lang.String getSelectSql()
           
protected  java.lang.String getSelectSql(java.lang.String columnName)
           
protected  java.lang.Boolean getStringAsBoolean(java.lang.String s)
           
protected abstract  java.lang.String getTableName()
           
protected abstract  boolean hasClobs()
          sub factory overrides returning true or false
 void lock(DatabaseSession dbSess, Identified item)
          A routine to lock an object and all of its sub parts in the database (thread locking) which is only released when this thread commits/rollsback
protected abstract  Identified makeFromResultSet(java.sql.ResultSet rs)
           
protected abstract  java.lang.String makeInsertCall()
          call to a stored proc for this object..
protected  java.sql.PreparedStatement makeInsertStmt(DatabaseSession dbSess)
          generic.
protected abstract  java.lang.String makeInsertString()
           
protected  Identified makeObject(DatabaseSession dbSess, java.sql.ResultSet rs)
           
protected abstract  java.lang.String makeUpdateCall()
          call to a stored proc for this object..
protected  java.sql.PreparedStatement makeUpdateStmt(DatabaseSession dbSess)
           
protected abstract  java.lang.String makeUpdateString()
           
protected  void marshalObjects(Identified item)
           
protected  boolean needsAndBeforeFilter()
           
protected  void preStorage(DatabaseSession dbSess, Identified item)
           
protected  void putNewObject(DatabaseSession dbSess, Identified item)
          routine to place a new object in the db
protected  void putNewObject(DatabaseSession dbSess, Identified item, int storageDepth)
          putNewObject stores an object for the first time using insert stmts
protected  java.util.Vector queryAll(DatabaseSession dbSess)
          A routine to get a all from the table
protected  java.util.Vector queryAllSorted(DatabaseSession dbSess, SortCriteria sortBy)
          A routine to get a all from the table - sorted
 java.util.Vector queryObjects(DatabaseSession dbSess, QueryFilter query)
          A routine to get a hits given the filter
 java.util.Vector queryObjects(DatabaseSession dbSess, java.lang.String column, int key)
           
 java.util.Vector queryObjects(DatabaseSession dbSess, ViewLookup lookup, QueryFilter filter)
          a routine to get objects with a given DatabaseLookup..
 java.util.Vector queryObjects(DatabaseSession dbSess, ViewLookup lookup, QueryFilter filter, SortCriteria sortCriteria)
           
 java.util.Vector querySorted(DatabaseSession dbSess, QueryFilter query, SortCriteria sortBy)
          A routine to get a objects from a table using the filter and sorted w/ the criteria
protected abstract  void refreshFromResultSet(Identified item, java.sql.ResultSet rs)
           
protected abstract  void setArguments(java.sql.PreparedStatement stmt, java.lang.Object item, boolean update)
           
protected abstract  void setClob(DatabaseSession dbSess, java.sql.ResultSet rs, java.lang.String columnName, java.lang.String value)
          need specific db type libraries to do see oracle/FactoryBase
protected  void setClobs(DatabaseSession dbSess, java.sql.ResultSet rs, Identified item)
           
protected  int storedProcCall(DatabaseSession dbSess, java.lang.String procCall, java.util.Vector args)
          Execute a stored proc with some arguments that returns an integer.
protected  void storeObject(DatabaseSession dbSess, Identified item)
          routine to store an object -- if new putNew is called else update is called
protected  void storeObject(DatabaseSession dbSess, Identified item, int storageDepth)
          routine to store an object -- if new putNew is called else update is called
(package private)  void trace(java.lang.String text)
           
protected  void updateObject(DatabaseSession dbSess, Identified item)
           
protected  void updateObject(DatabaseSession dbSess, Identified item, int storageDepth)
           
protected abstract  boolean useStoredProcs()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SHALLOW

protected int SHALLOW

DEEP

protected int DEEP

VERSION_NUMBER

public static final java.lang.String VERSION_NUMBER
See Also:
Constant Field Values

endDates

protected boolean endDates
Constructor Detail

GenericFactoryBase

public GenericFactoryBase()
Method Detail

flushCache

public void flushCache()

getConnection

protected java.sql.Connection getConnection(DatabaseSession dbSess)

getObject

protected Identified getObject(DatabaseSession dbSess,
                               java.lang.String columnName,
                               java.lang.String value)
                        throws java.sql.SQLException
java.sql.SQLException

getObject

protected Identified getObject(DatabaseSession dbSess,
                               java.lang.String columnName,
                               int value)
                        throws java.sql.SQLException
java.sql.SQLException

storeObject

protected void storeObject(DatabaseSession dbSess,
                           Identified item)
                    throws java.sql.SQLException
routine to store an object -- if new putNew is called else update is called

java.sql.SQLException

storeObject

protected void storeObject(DatabaseSession dbSess,
                           Identified item,
                           int storageDepth)
                    throws java.sql.SQLException
routine to store an object -- if new putNew is called else update is called

java.sql.SQLException

putNewObject

protected void putNewObject(DatabaseSession dbSess,
                            Identified item)
                     throws java.sql.SQLException
routine to place a new object in the db

java.sql.SQLException

putNewObject

protected void putNewObject(DatabaseSession dbSess,
                            Identified item,
                            int storageDepth)
                     throws java.sql.SQLException
putNewObject stores an object for the first time using insert stmts

java.sql.SQLException

dbNeedsId

public abstract boolean dbNeedsId()

makeInsertStmt

protected java.sql.PreparedStatement makeInsertStmt(DatabaseSession dbSess)
                                             throws java.sql.SQLException
generic. can override in descendant class if procs are supported

java.sql.SQLException

makeUpdateStmt

protected java.sql.PreparedStatement makeUpdateStmt(DatabaseSession dbSess)
                                             throws java.sql.SQLException
java.sql.SQLException

deleteObject

protected void deleteObject(DatabaseSession dbSess,
                            Identified item)
                     throws java.sql.SQLException
java.sql.SQLException

deleteObjects

protected int deleteObjects(DatabaseSession dbSess,
                            QueryFilter filter)
                     throws java.sql.SQLException
deleteObjects will delete all the rows which match the given filter

Parameters:
dbSess - the database connection
filter - the query filter to apply
Returns:
the number of rows affected
java.sql.SQLException

updateObject

protected void updateObject(DatabaseSession dbSess,
                            Identified item)
                     throws java.sql.SQLException
java.sql.SQLException

updateObject

protected void updateObject(DatabaseSession dbSess,
                            Identified item,
                            int storageDepth)
                     throws java.sql.SQLException
java.sql.SQLException

queryObjects

public java.util.Vector queryObjects(DatabaseSession dbSess,
                                     java.lang.String column,
                                     int key)
                              throws java.sql.SQLException
java.sql.SQLException

queryObjects

public java.util.Vector queryObjects(DatabaseSession dbSess,
                                     ViewLookup lookup,
                                     QueryFilter filter)
                              throws java.sql.SQLException
a routine to get objects with a given DatabaseLookup..

Parameters:
dbSess - is the in-transaction database session
lookup - a ViewLookup from the generated descendant of this class
filter - an option filter to restrict hits
java.sql.SQLException

queryObjects

public java.util.Vector queryObjects(DatabaseSession dbSess,
                                     ViewLookup lookup,
                                     QueryFilter filter,
                                     SortCriteria sortCriteria)
                              throws java.sql.SQLException
java.sql.SQLException

lock

public void lock(DatabaseSession dbSess,
                 Identified item)
          throws java.sql.SQLException
A routine to lock an object and all of its sub parts in the database (thread locking) which is only released when this thread commits/rollsback

Parameters:
dbSess - the current merlin session
item - the Identified item to be locked (and even refreshed)
Throws:
java.sql.SQLException - when db-error occurs

useStoredProcs

protected abstract boolean useStoredProcs()

makeFromResultSet

protected abstract Identified makeFromResultSet(java.sql.ResultSet rs)
                                         throws java.sql.SQLException
java.sql.SQLException

refreshFromResultSet

protected abstract void refreshFromResultSet(Identified item,
                                             java.sql.ResultSet rs)
                                      throws java.sql.SQLException
java.sql.SQLException

makeUpdateString

protected abstract java.lang.String makeUpdateString()

makeInsertString

protected abstract java.lang.String makeInsertString()

makeInsertCall

protected abstract java.lang.String makeInsertCall()
call to a stored proc for this object..


makeUpdateCall

protected abstract java.lang.String makeUpdateCall()
call to a stored proc for this object..


getPrimaryColumn

protected abstract java.lang.String getPrimaryColumn()

getTableName

protected abstract java.lang.String getTableName()

setArguments

protected abstract void setArguments(java.sql.PreparedStatement stmt,
                                     java.lang.Object item,
                                     boolean update)
                              throws java.sql.SQLException
java.sql.SQLException

deepRetrieval

protected void deepRetrieval(DatabaseSession dbSess,
                             Identified item)
                      throws java.sql.SQLException
java.sql.SQLException

deepStorage

protected void deepStorage(DatabaseSession dbSess,
                           Identified item)
                    throws java.sql.SQLException
java.sql.SQLException

marshalObjects

protected void marshalObjects(Identified item)
                       throws java.sql.SQLException
java.sql.SQLException

preStorage

protected void preStorage(DatabaseSession dbSess,
                          Identified item)
                   throws java.sql.SQLException
java.sql.SQLException

getCollection

public java.util.Vector getCollection(DatabaseSession dbSess,
                                      java.sql.ResultSet rs)
                               throws java.sql.SQLException
java.sql.SQLException

queryObjects

public java.util.Vector queryObjects(DatabaseSession dbSess,
                                     QueryFilter query)
                              throws java.sql.SQLException
A routine to get a hits given the filter

Parameters:
dbSess - the current merlin session
query - the filter to delimit hits..
Returns:
Vector of results
Throws:
java.sql.SQLException - if a db error occurs

queryAll

protected java.util.Vector queryAll(DatabaseSession dbSess)
                             throws java.sql.SQLException
A routine to get a all from the table

Parameters:
dbSess - the current merlin session
Returns:
Vector of results
Throws:
java.sql.SQLException - if a db error occurs

queryAllSorted

protected java.util.Vector queryAllSorted(DatabaseSession dbSess,
                                          SortCriteria sortBy)
                                   throws java.sql.SQLException
A routine to get a all from the table - sorted

Parameters:
dbSess - the current merlin session
sortBy - the sorting criteria
Returns:
Vector of results
Throws:
java.sql.SQLException - if a db error occurs

querySorted

public java.util.Vector querySorted(DatabaseSession dbSess,
                                    QueryFilter query,
                                    SortCriteria sortBy)
                             throws java.sql.SQLException
A routine to get a objects from a table using the filter and sorted w/ the criteria

Parameters:
dbSess - the current merlin session
sortBy - the sorting criteria
query - the filter to search with
Returns:
Vector of results
Throws:
java.sql.SQLException - if a db error occurs

getObject

public Identified getObject(DatabaseSession dbSess,
                            QueryFilter query)
                     throws java.sql.SQLException
A routine to get a single object given a filter

Parameters:
dbSess - the current merlin session
query - one which should find 0-1 objects
Returns:
Identified
Throws:
java.sql.SQLException - if a db error occurs or more than 1 object is found on this filter

makeObject

protected Identified makeObject(DatabaseSession dbSess,
                                java.sql.ResultSet rs)
                         throws java.sql.SQLException
java.sql.SQLException

defaultNeedsWhereLogic

protected boolean defaultNeedsWhereLogic()

needsAndBeforeFilter

protected boolean needsAndBeforeFilter()

getResults

protected GenericFactoryBase.QueryResult getResults(DatabaseSession dbSess,
                                                    java.lang.String sql,
                                                    int key)
                                             throws java.sql.SQLException
get results and set key in first arg..

java.sql.SQLException

getResults

protected GenericFactoryBase.QueryResult getResults(DatabaseSession dbSess,
                                                    java.lang.String sql,
                                                    QueryFilter filter,
                                                    SortCriteria sc)
                                             throws java.sql.SQLException
a helper routine to build a query and execute

java.sql.SQLException

getResults

protected GenericFactoryBase.QueryResult getResults(DatabaseSession dbSess,
                                                    java.lang.String sql,
                                                    QueryFilter filter,
                                                    SortCriteria sc,
                                                    boolean needsWhereLogic,
                                                    java.lang.String tableName)
                                             throws java.sql.SQLException
java.sql.SQLException

countRows

public int countRows(DatabaseSession dbSess,
                     QueryFilter filter)
              throws java.sql.SQLException
A routine to count the number of rows in a query which returns the count of hits

Parameters:
dbSess - the current merlin session
filter - a QueryFilter
java.sql.SQLException

cursorQuery

public DatabaseCursor cursorQuery(DatabaseSession dbSess,
                                  SortCriteria sortBy)
                           throws java.sql.SQLException
A routine to perform a search given an ordering which returns the Vector of oid hits in a DatabaseCursor object this allows small range retrievals with any type of data abstraction

Parameters:
dbSess - the current merlin session
sortBy - a list of columns on which to sort the data
java.sql.SQLException

cursorQuery

public DatabaseCursor cursorQuery(DatabaseSession dbSess,
                                  QueryFilter query)
                           throws java.sql.SQLException
A routine to perform a search given a filter which returns the Vector of oid hits in a DatabaseCursor object this allows small range retrievals with any type of data abstraction

Parameters:
dbSess - the current merlin session
query - a query filter with any lookup specific criteria
java.sql.SQLException

cursorQuery

public DatabaseCursor cursorQuery(DatabaseSession dbSess,
                                  QueryFilter query,
                                  SortCriteria sortBy)
                           throws java.sql.SQLException
A routine to perform a search given a filter and an ordering which returns the Vector of oid hits in a DatabaseCursor object this allows small range retrievals with any type of data abstraction

Parameters:
dbSess - the current merlin session
query - a query filter with any lookup specific criteria
sortBy - a list of columns on which to sort the data
java.sql.SQLException

cursorRawQuery

protected DatabaseCursor cursorRawQuery(DatabaseSession dbSess,
                                        java.lang.String sql)
                                 throws java.sql.SQLException
Raw query returns DatabaseCursor - to be used in descendant classes

Parameters:
dbSess -
sql -
Returns:
Throws:
java.sql.SQLException

storedProcCall

protected int storedProcCall(DatabaseSession dbSess,
                             java.lang.String procCall,
                             java.util.Vector args)
                      throws java.sql.SQLException
Execute a stored proc with some arguments that returns an integer.

java.sql.SQLException

cursorStoredProcCall

protected DatabaseCursor cursorStoredProcCall(DatabaseSession dbSess,
                                              java.lang.String procCall,
                                              java.util.Vector args,
                                              SortCriteria sort)
                                       throws java.sql.SQLException
java.sql.SQLException

checkRefresh

protected void checkRefresh(DatabaseSession dbSess,
                            Identified item)
                     throws java.sql.SQLException
java.sql.SQLException

checkRefresh

protected void checkRefresh(DatabaseSession dbSess,
                            Identified item,
                            java.sql.ResultSet rs)
                     throws java.sql.SQLException
routine to check if an object is up to date..

Parameters:
dbSess - this threads connection
item - the dbObject in question
rs - an open ResultSet represneting this object in the db
Throws:
java.sql.SQLException - on error.

getLastId

protected int getLastId(DatabaseSession dbSess,
                        java.sql.PreparedStatement stmt)
                 throws java.sql.SQLException
java.sql.SQLException

setClobs

protected void setClobs(DatabaseSession dbSess,
                        java.sql.ResultSet rs,
                        Identified item)
                 throws java.sql.SQLException
java.sql.SQLException

hasClobs

protected abstract boolean hasClobs()
sub factory overrides returning true or false


setClob

protected abstract void setClob(DatabaseSession dbSess,
                                java.sql.ResultSet rs,
                                java.lang.String columnName,
                                java.lang.String value)
                         throws java.sql.SQLException
need specific db type libraries to do see oracle/FactoryBase

java.sql.SQLException

getLastId

protected abstract int getLastId(DatabaseSession dbSess)
                          throws java.sql.SQLException
java.sql.SQLException

getSelectSql

protected java.lang.String getSelectSql(java.lang.String columnName)

getSelectSql

protected java.lang.String getSelectSql()

getSelectCountSql

protected java.lang.String getSelectCountSql()

getDeleteSql

protected java.lang.String getDeleteSql(QueryFilter filter)

getBooleanAsString

protected java.lang.String getBooleanAsString(java.lang.Boolean b)

getStringAsBoolean

protected java.lang.Boolean getStringAsBoolean(java.lang.String s)

trace

void trace(java.lang.String text)