wt.pds
Class SQLDatabasePds

java.lang.Object
  extended bywt.pds.SQLDatabasePds
All Implemented Interfaces:
PDSIfc
Direct Known Subclasses:
OraclePds, SQLServerPds

public abstract class SQLDatabasePds
extends Object
implements PDSIfc

This abstract class provides standard SQL database persistent data services. A concrete subclass must be supplied for each SQL DBMS supported.

Supported API: false

Extendable: false


Field Summary
private  AttributeMapInfo attributeMapInfo
           
private static String CLASSNAME
           
protected static DMLGenerator DMLGENERATOR
           
private  LobHandler lobHandler
           
private static String LOCATOR_TYPE
           
private static Hashtable mapCacheLobOnly
           
private static int ORACLE_TYPES_8_0_BLOB
           
private static ThreadLocal REFRESH_QUERY_CACHE
           
private static String RESOURCE
           
 
Constructor Summary
SQLDatabasePds()
          Constructs an instance.
 
Method Summary
private  void assignPersistInfo(Persistable a_obj, ObjectIdentifier a_oid, Timestamp a_createStamp, Timestamp a_updateStamp, Timestamp a_modifyStamp)
           
protected  Map buildLobMap(ClassInfo aClassInfo)
           
private  UpdateBatchSpec buildNullForeignKeyBatchSpec(AbstractBatchSpec a_batchSpec, LinkInfo linkInfo)
           
private  int buildPartialUpdate(ClassInfo classInfo, String attrName, ClassInfo attrClassInfo, boolean isRequired, StringBuffer upstmt, Persistable anObj)
           
private  WTPreparedStatement buildPreparedStatement(PreparedStatement a_statement, Map a_map)
           
 void closeConnection(WTConnection a_connection)
          This method is used to clean up the specfied WTConnection prior to freeing the underlying JDBC connection.
 boolean containSequenceColumn(ClassInfo a_classInfo)
          

Supported API: false
 int execute(WTConnection a_connection, AbstractBatchSpec a_batchSpec)
          Executes the specified statements in the datastore.
private  int execute(WTConnection a_connection, String[] a_sqls, Object a_updateBindParameters, Object a_whereBindParameters, boolean a_isUpdate, boolean a_setCurrentTime, int a_chunkCount)
          Executes the specified multi-row statement in the datastore.
 Object executeCall(WTConnection a_connection, String a_procedureName, StatementParameter[] a_argumentValues, StatementParameter a_outputType)
          This method executes a call to a database stored procedure.
 QueryResult expand(WTConnection a_connection, Persistable a_obj, String a_otherSideRole, Class a_linkClass, boolean a_onlyOtherSide, AccessControllerProcessor a_accessControllerProcessor)
          Expand the association from the object using the specified role and link class.
 QueryResult expand(WTConnection a_connection, Persistable a_obj, String a_otherSideRole, QuerySpec a_querySpec, boolean a_onlyOtherSide, AccessControllerProcessor a_accessControllerProcessor)
          Expand the association from the object using the specified role and QuerySpec.
private  QueryResult expandLink(WTConnection a_connection, Persistable a_obj, String a_otherSideRole, boolean a_onlyOtherSide, QuerySpec a_querySpec, LinkInfo a_linkInfo, AccessControllerProcessor a_accessControllerProcessor)
          Performs the expand operation.
 AttributeMapInfo getAttributeMapInfo()
           
abstract  DataSource getDataSource()
          

Supported API: false
 int getDefaultTransactionIsolation()
          Returns the default Transaction Isolation.
 DMLGenerator getDMLGenerator()
          

Supported API: false
 InputStream getLob(WTConnection a_connection, LobLocator a_lobLocator)
          Gets the data from the specified LOB as an InputStream.
 byte[] getLobAsByteArray(WTConnection a_connection, Object a_blob)
          Gets the Lob as a byte array.
 Object getLobAsObject(WTConnection a_connection, Object a_blob)
          Gets the Lob as an object.
abstract  String getNextSequence(WTConnection a_connection, String a_sequenceName)
          Return the next value from the datastore sequence.
 PersistenceException handleException(Exception a_exception)
          Handles an exception specific to the PDS instance.
 PersistenceException handleSQLException(SQLException a_sqlException, Object a_obj, String a_messageKey)
          Handles an SQL exception specific to the Datastore instance.
 void initializeConnection(WTConnection a_connection)
          This method is used to initialize the specfied WTConnection prior to making it available to use.
 void insert(WTConnection a_connection, Object a_obj, boolean a_reInsert)
          Insert an object into the SQL database

Supported API: false
private  void insertList(WTConnection a_connection, PersistableList a_list, boolean a_reInsert)
           
 int insertPageResults(WTConnection a_connection, int a_offset, int a_toIndex, long a_sessionId, List a_oidList, int a_groupFromIndex)
          Inserts results into the paging table of the datastore.
 boolean isLob(ColumnDescriptor a_columnDescriptor)
          Indicates if this is a LOB column

Supported API: false
 boolean isLobLocator(ColumnDescriptor a_columnDescriptor)
          Indicates if this is a LobLocator column.
private  boolean isMappedLob(ColumnDescriptor aD)
           
protected  boolean isPersistent(Persistable obj)
           
abstract  void lock(WTConnection a_connection, Object a_class, boolean a_wait)
          Perform a datastore lock on an Class table.
abstract  Persistable lock(WTConnection a_connection, Persistable a_obj, boolean a_wait)
          Perform a datastore lock on an Object.
private  void nullForeignKey(BinaryLink anObj, LinkInfo linkInfo)
           
protected  PersistenceException processSQLException(SQLException a_sqlException, Object a_obj, String a_operation, String a_sqlStatement)
          Handles an SQL exception specific to the Datastore instance.
 void query(WTConnection a_connection, StatementSpec a_statementSpec, AccessControllerProcessor a_accessControllerProcessor, ResultProcessor a_resultProcessor)
          Query for objects in the SQL database.
 Persistable refresh(WTConnection a_connection, Persistable a_obj, boolean a_inPlace, AccessControllerProcessor a_accessControllerProcessor)
          Refresh the object from the SQL database.
 Persistable refresh(WTConnection a_connection, Persistable a_obj, boolean a_inPlace, AccessControllerProcessor a_accessControllerProcessor, boolean a_lock)
          Lock and Refresh the object from the datastore.
 void remove(WTConnection a_connection, Persistable a_obj)
          Remove an object from the SQL database.
private  void setForeignKey(BinaryLink anObj, LinkInfo linkInfo)
           
 long setLob(WTConnection a_connection, LobLocator a_lobLocator, InputStream a_inputStream, boolean a_updateChangeStamp)
          Set the data in the InputStream to the specified LOB.
 void setLob(WTConnection a_connection, LobLocator a_lobLocator, InputStream a_inputStream, long a_length, boolean a_updateChangeStamp)
          Set the data in the InputStream to the specified LOB.
 void setObjectAsLob(WTConnection a_connection, LobLocator a_lobLocator, Object a_object)
          Set the object as LOB.
 void update(WTConnection a_connection, Object a_obj, boolean a_changeModifyDate)
          Update an object in the SQL database.
 Persistable update(WTConnection a_connection, Persistable a_obj, String a_attributeName, ObjectMappable a_attribute)
          Update an attribute of an object in the SQL database (partial update).
private  void updateList(WTConnection a_connection, PersistableList a_list, boolean a_changeModifyDate)
           
protected  void validateExists(Persistable anObj)
           
protected  void validateInsert(Persistable anObj, boolean a_reInsert)
           
private  void writeToInsertStatement(WTPreparedStatement a_statement, Persistable a_obj, ClassInfo a_classInfo, Timestamp a_createStamp, Timestamp a_updateStamp, Timestamp a_modifyStamp, long a_objectId, int a_persistInfoOffset)
           
private  void writeToUpdateStatement(WTPreparedStatement a_statement, Persistable a_obj, ClassInfo a_classInfo, Timestamp a_updateStamp, Timestamp a_modifyStamp, int a_updateCount, long a_objectId, int a_persistInfoOffset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

CLASSNAME

private static final String CLASSNAME

attributeMapInfo

private AttributeMapInfo attributeMapInfo

lobHandler

private LobHandler lobHandler

LOCATOR_TYPE

private static final String LOCATOR_TYPE
See Also:
Constant Field Values

mapCacheLobOnly

private static Hashtable mapCacheLobOnly

ORACLE_TYPES_8_0_BLOB

private static final int ORACLE_TYPES_8_0_BLOB
See Also:
Constant Field Values

REFRESH_QUERY_CACHE

private static final ThreadLocal REFRESH_QUERY_CACHE

DMLGENERATOR

protected static final DMLGenerator DMLGENERATOR
Constructor Detail

SQLDatabasePds

public SQLDatabasePds()
Constructs an instance.

Supported API: false

Method Detail

insert

public void insert(WTConnection a_connection,
                   Object a_obj,
                   boolean a_reInsert)
            throws PersistenceException
Insert an object into the SQL database

Supported API: false

Specified by:
insert in interface PDSIfc
Parameters:
a_connection -
a_obj - The object(s) to insert. The value can be either a Persisteable or Persistable[].
a_reInsert -
Throws:
PersistenceException

remove

public void remove(WTConnection a_connection,
                   Persistable a_obj)
            throws PersistenceException
Remove an object from the SQL database.

Supported API: false

Specified by:
remove in interface PDSIfc
Parameters:
a_connection -
a_obj -
Throws:
PersistenceException

update

public void update(WTConnection a_connection,
                   Object a_obj,
                   boolean a_changeModifyDate)
            throws PersistenceException
Update an object in the SQL database.

Supported API: false

Specified by:
update in interface PDSIfc
Parameters:
a_connection -
a_obj - The object(s) to insert. The value can be either a Persisteable or Persistable[].
a_changeModifyDate -
Throws:
PersistenceException

update

public Persistable update(WTConnection a_connection,
                          Persistable a_obj,
                          String a_attributeName,
                          ObjectMappable a_attribute)
                   throws PersistenceException
Update an attribute of an object in the SQL database (partial update).

Supported API: false

Specified by:
update in interface PDSIfc
Parameters:
a_connection -
a_obj -
a_attributeName -
a_attribute -
Returns:
Persistable
Throws:
PersistenceException

expand

public QueryResult expand(WTConnection a_connection,
                          Persistable a_obj,
                          String a_otherSideRole,
                          Class a_linkClass,
                          boolean a_onlyOtherSide,
                          AccessControllerProcessor a_accessControllerProcessor)
                   throws PersistenceException
Expand the association from the object using the specified role and link class.

Supported API: false

Specified by:
expand in interface PDSIfc
Parameters:
a_connection -
a_obj -
a_otherSideRole -
a_linkClass -
a_onlyOtherSide -
a_accessControllerProcessor -
Returns:
QueryResult
Throws:
PersistenceException

expand

public QueryResult expand(WTConnection a_connection,
                          Persistable a_obj,
                          String a_otherSideRole,
                          QuerySpec a_querySpec,
                          boolean a_onlyOtherSide,
                          AccessControllerProcessor a_accessControllerProcessor)
                   throws PersistenceException
Expand the association from the object using the specified role and QuerySpec.

Supported API: false

Specified by:
expand in interface PDSIfc
Parameters:
a_connection -
a_obj -
a_otherSideRole -
a_querySpec -
a_onlyOtherSide -
a_accessControllerProcessor -
Returns:
QueryResult
Throws:
PersistenceException

query

public void query(WTConnection a_connection,
                  StatementSpec a_statementSpec,
                  AccessControllerProcessor a_accessControllerProcessor,
                  ResultProcessor a_resultProcessor)
           throws PersistenceException
Query for objects in the SQL database.

Supported API: false

Specified by:
query in interface PDSIfc
Parameters:
a_connection -
a_statementSpec -
a_accessControllerProcessor -
a_resultProcessor -
Throws:
PersistenceException

refresh

public Persistable refresh(WTConnection a_connection,
                           Persistable a_obj,
                           boolean a_inPlace,
                           AccessControllerProcessor a_accessControllerProcessor)
                    throws PersistenceException
Refresh the object from the SQL database.

Supported API: false

Specified by:
refresh in interface PDSIfc
Parameters:
a_connection -
a_obj -
a_inPlace -
a_accessControllerProcessor -
Returns:
Persistable
Throws:
PersistenceException

isLob

public boolean isLob(ColumnDescriptor a_columnDescriptor)
Indicates if this is a LOB column

Supported API: false

Specified by:
isLob in interface PDSIfc
Parameters:
a_columnDescriptor -
Returns:
boolean

handleException

public PersistenceException handleException(Exception a_exception)
Handles an exception specific to the PDS instance.

Supported API: false

Specified by:
handleException in interface PDSIfc
Parameters:
a_exception -
Returns:
PersistenceException

handleSQLException

public PersistenceException handleSQLException(SQLException a_sqlException,
                                               Object a_obj,
                                               String a_messageKey)
Handles an SQL exception specific to the Datastore instance.

Supported API: false

Parameters:
a_sqlException -
a_obj -
a_messageKey -
Returns:
PersistenceException

lock

public abstract Persistable lock(WTConnection a_connection,
                                 Persistable a_obj,
                                 boolean a_wait)
                          throws PersistenceException
Perform a datastore lock on an Object.

Supported API: false

Specified by:
lock in interface PDSIfc
Parameters:
a_connection -
a_obj -
a_wait -
Returns:
Persistable
Throws:
PersistenceException

getNextSequence

public abstract String getNextSequence(WTConnection a_connection,
                                       String a_sequenceName)
                                throws PersistenceException
Return the next value from the datastore sequence.

Supported API: false

Specified by:
getNextSequence in interface PDSIfc
Parameters:
a_connection -
a_sequenceName -
Returns:
String
Throws:
PersistenceException

getDefaultTransactionIsolation

public int getDefaultTransactionIsolation()
Returns the default Transaction Isolation.

Supported API: false

Specified by:
getDefaultTransactionIsolation in interface PDSIfc
Returns:
int

setLob

public void setLob(WTConnection a_connection,
                   LobLocator a_lobLocator,
                   InputStream a_inputStream,
                   long a_length,
                   boolean a_updateChangeStamp)
            throws PersistenceException
Set the data in the InputStream to the specified LOB.

Supported API: false

Specified by:
setLob in interface PDSIfc
Parameters:
a_connection -
a_lobLocator -
a_inputStream -
a_length -
a_updateChangeStamp -
Throws:
PersistenceException

setLob

public long setLob(WTConnection a_connection,
                   LobLocator a_lobLocator,
                   InputStream a_inputStream,
                   boolean a_updateChangeStamp)
            throws PersistenceException
Set the data in the InputStream to the specified LOB.

Supported API: false

Specified by:
setLob in interface PDSIfc
Parameters:
a_connection -
a_lobLocator -
a_inputStream -
a_updateChangeStamp -
Returns:
long
Throws:
PersistenceException

setObjectAsLob

public void setObjectAsLob(WTConnection a_connection,
                           LobLocator a_lobLocator,
                           Object a_object)
                    throws PersistenceException
Set the object as LOB.

Supported API: false

Specified by:
setObjectAsLob in interface PDSIfc
Parameters:
a_connection -
a_lobLocator -
a_object -
Throws:
PersistenceException

getLob

public InputStream getLob(WTConnection a_connection,
                          LobLocator a_lobLocator)
                   throws PersistenceException
Gets the data from the specified LOB as an InputStream.

Supported API: false

Specified by:
getLob in interface PDSIfc
Parameters:
a_connection -
a_lobLocator -
Returns:
InputStream
Throws:
PersistenceException

getLobAsByteArray

public byte[] getLobAsByteArray(WTConnection a_connection,
                                Object a_blob)
                         throws PersistenceException
Gets the Lob as a byte array.

Supported API: false

Specified by:
getLobAsByteArray in interface PDSIfc
Parameters:
a_connection -
a_blob -
Returns:
byte[]
Throws:
PersistenceException

getLobAsObject

public Object getLobAsObject(WTConnection a_connection,
                             Object a_blob)
                      throws PersistenceException
Gets the Lob as an object.

Supported API: false

Specified by:
getLobAsObject in interface PDSIfc
Parameters:
a_connection -
a_blob -
Returns:
Object
Throws:
PersistenceException

getDataSource

public abstract DataSource getDataSource()


Supported API: false

Specified by:
getDataSource in interface PDSIfc
Returns:
DataSource

getDMLGenerator

public DMLGenerator getDMLGenerator()


Supported API: false

Specified by:
getDMLGenerator in interface PDSIfc
Returns:
DMLGenerator

insertPageResults

public int insertPageResults(WTConnection a_connection,
                             int a_offset,
                             int a_toIndex,
                             long a_sessionId,
                             List a_oidList,
                             int a_groupFromIndex)
                      throws PersistenceException
Inserts results into the paging table of the datastore. If a valid group FROM index is specified, then all OIDs specified by the index that are identical will be grouped together (i.e. the group ID value will be the same)

Supported API: false

Specified by:
insertPageResults in interface PDSIfc
Parameters:
a_connection - Connection to use to perform the operation
a_offset -
a_toIndex -
a_sessionId - Identification value to use to associate the results with a paging session
a_oidList - List of OID values. The elements are assumed to be an Object[]. For every OID, two array entries are assumed. The first is the object ID and the second is the classname.
a_groupFromIndex - Specifies an index into the OID list for grouping. The index is not absolute since each OID uses two array entries. For example, index 3 would specify the OIDarray entries 5 and 6.
Throws:
PersistenceException

executeCall

public Object executeCall(WTConnection a_connection,
                          String a_procedureName,
                          StatementParameter[] a_argumentValues,
                          StatementParameter a_outputType)
                   throws PersistenceException
This method executes a call to a database stored procedure. Input argument are passed as specified. The output value from the stored procedure is returned, if applicable.

Supported API: false

Specified by:
executeCall in interface PDSIfc
Parameters:
a_connection - Connection to use to perform the operation
a_procedureName - Specifies the database stored procedure to execute.
a_argumentValues - Array of input argument values
a_outputType - StatementParmeter object used to specify the return value. If null, then the stored procedure is assumed to be a procedure and a null value is returned.
Returns:
Object
Throws:
PersistenceException
See Also:
StatementParameter

initializeConnection

public void initializeConnection(WTConnection a_connection)
                          throws WTException
This method is used to initialize the specfied WTConnection prior to making it available to use.

Supported API: false

Specified by:
initializeConnection in interface PDSIfc
Parameters:
a_connection - Connection to initialize.
Throws:
WTException

isLobLocator

public boolean isLobLocator(ColumnDescriptor a_columnDescriptor)
Indicates if this is a LobLocator column.

Supported API: false

Specified by:
isLobLocator in interface PDSIfc
Parameters:
a_columnDescriptor -
Returns:
boolean

lock

public abstract void lock(WTConnection a_connection,
                          Object a_class,
                          boolean a_wait)
                   throws PersistenceException
Perform a datastore lock on an Class table.

Supported API: false

Specified by:
lock in interface PDSIfc
Parameters:
a_connection -
a_class -
a_wait -
Throws:
PersistenceException

containSequenceColumn

public boolean containSequenceColumn(ClassInfo a_classInfo)
                              throws PersistenceException


Supported API: false

Specified by:
containSequenceColumn in interface PDSIfc
Parameters:
a_classInfo -
Returns:
boolean
Throws:
PersistenceException

refresh

public Persistable refresh(WTConnection a_connection,
                           Persistable a_obj,
                           boolean a_inPlace,
                           AccessControllerProcessor a_accessControllerProcessor,
                           boolean a_lock)
                    throws PersistenceException
Lock and Refresh the object from the datastore.

Supported API: false

Specified by:
refresh in interface PDSIfc
Parameters:
a_connection -
a_obj -
a_inPlace -
a_accessControllerProcessor -
a_lock -
Returns:
Persistable
Throws:
PersistenceException

execute

public int execute(WTConnection a_connection,
                   AbstractBatchSpec a_batchSpec)
            throws WTException
Executes the specified statements in the datastore.

Supported API: false

Specified by:
execute in interface PDSIfc
Parameters:
a_connection - The connection to use for the operation.
a_batchSpec - Specifies the statements to execute.
Throws:
WTException

closeConnection

public void closeConnection(WTConnection a_connection)
                     throws WTException
This method is used to clean up the specfied WTConnection prior to freeing the underlying JDBC connection.

Supported API: false

Specified by:
closeConnection in interface PDSIfc
Parameters:
a_connection - Connection to initialize.
Throws:
WTException

execute

private int execute(WTConnection a_connection,
                    String[] a_sqls,
                    Object a_updateBindParameters,
                    Object a_whereBindParameters,
                    boolean a_isUpdate,
                    boolean a_setCurrentTime,
                    int a_chunkCount)
             throws WTException
Executes the specified multi-row statement in the datastore.

Parameters:
a_connection - The connection to use for the operation.
a_sqls - Array of SQL statements to execute
a_isUpdate - indicates if this is update (true) or delete (false)
Throws:
WTException

getAttributeMapInfo

public AttributeMapInfo getAttributeMapInfo()

insertList

private void insertList(WTConnection a_connection,
                        PersistableList a_list,
                        boolean a_reInsert)
                 throws WTException
Throws:
WTException

updateList

private void updateList(WTConnection a_connection,
                        PersistableList a_list,
                        boolean a_changeModifyDate)
                 throws WTException
Throws:
WTException

assignPersistInfo

private void assignPersistInfo(Persistable a_obj,
                               ObjectIdentifier a_oid,
                               Timestamp a_createStamp,
                               Timestamp a_updateStamp,
                               Timestamp a_modifyStamp)
                        throws WTException
Throws:
WTException

writeToInsertStatement

private void writeToInsertStatement(WTPreparedStatement a_statement,
                                    Persistable a_obj,
                                    ClassInfo a_classInfo,
                                    Timestamp a_createStamp,
                                    Timestamp a_updateStamp,
                                    Timestamp a_modifyStamp,
                                    long a_objectId,
                                    int a_persistInfoOffset)
                             throws SQLException,
                                    WTException
Throws:
SQLException
WTException

writeToUpdateStatement

private void writeToUpdateStatement(WTPreparedStatement a_statement,
                                    Persistable a_obj,
                                    ClassInfo a_classInfo,
                                    Timestamp a_updateStamp,
                                    Timestamp a_modifyStamp,
                                    int a_updateCount,
                                    long a_objectId,
                                    int a_persistInfoOffset)
                             throws SQLException,
                                    WTException
Throws:
SQLException
WTException

buildPreparedStatement

private WTPreparedStatement buildPreparedStatement(PreparedStatement a_statement,
                                                   Map a_map)

expandLink

private QueryResult expandLink(WTConnection a_connection,
                               Persistable a_obj,
                               String a_otherSideRole,
                               boolean a_onlyOtherSide,
                               QuerySpec a_querySpec,
                               LinkInfo a_linkInfo,
                               AccessControllerProcessor a_accessControllerProcessor)
                        throws PersistenceException
Performs the expand operation.

Throws:
PersistenceException

validateInsert

protected void validateInsert(Persistable anObj,
                              boolean a_reInsert)
                       throws PersistenceException
Throws:
PersistenceException

validateExists

protected void validateExists(Persistable anObj)
                       throws PersistenceException
Throws:
PersistenceException

buildPartialUpdate

private int buildPartialUpdate(ClassInfo classInfo,
                               String attrName,
                               ClassInfo attrClassInfo,
                               boolean isRequired,
                               StringBuffer upstmt,
                               Persistable anObj)
                        throws PersistenceException
Throws:
PersistenceException

isPersistent

protected boolean isPersistent(Persistable obj)

buildLobMap

protected Map buildLobMap(ClassInfo aClassInfo)
                   throws PersistenceException
Throws:
PersistenceException

setForeignKey

private void setForeignKey(BinaryLink anObj,
                           LinkInfo linkInfo)
                    throws PersistenceException
Throws:
PersistenceException

buildNullForeignKeyBatchSpec

private UpdateBatchSpec buildNullForeignKeyBatchSpec(AbstractBatchSpec a_batchSpec,
                                                     LinkInfo linkInfo)
                                              throws WTException
Throws:
WTException

nullForeignKey

private void nullForeignKey(BinaryLink anObj,
                            LinkInfo linkInfo)

isMappedLob

private boolean isMappedLob(ColumnDescriptor aD)

processSQLException

protected PersistenceException processSQLException(SQLException a_sqlException,
                                                   Object a_obj,
                                                   String a_operation,
                                                   String a_sqlStatement)
Handles an SQL exception specific to the Datastore instance.

Supported API: false

Parameters:
a_sqlException -
a_obj -
a_operation -
Returns:
PersistenceException