goldengate.common.database.data
Class AbstractDbData

java.lang.Object
  extended by goldengate.common.database.data.AbstractDbData
Direct Known Subclasses:
AbstractDbDataWithCommit, DbDataModel

public abstract class AbstractDbData
extends Object

Abstract database table implementation without explicit COMMIT.

If the connection is in autocommit, this is the right abstract to extend.
If the connection is not in autocommit, one could use this implementation to explicitly commit when needed.

Author:
Frederic Bregier

Nested Class Summary
static class AbstractDbData.UpdatedInfo
          UpdatedInfo status
 
Field Summary
protected  DbValue[] allFields
           
protected  DbSession dbSession
          The DbSession to use
protected  boolean isSaved
           
protected  DbValue[] otherFields
           
protected  DbValue[] primaryKey
          To be implemented
 
Constructor Summary
AbstractDbData(DbSession dbSession)
          Abstract constructor to set the DbSession to use
 
Method Summary
abstract  void changeUpdatedInfo(AbstractDbData.UpdatedInfo info)
          Change UpdatedInfo status
 void delete()
          Delete object from table
 boolean exist()
          Test the existence of the current object
 boolean get(DbPreparedStatement preparedStatement)
          Get Values from PreparedStatement
protected abstract  String getInsertAllValues()
           
protected abstract  String getSelectAllFields()
           
protected abstract  String getTable()
           
static void getTrueValue(ResultSet rs, DbValue value)
          Get one value into DbValue from ResultSet
protected abstract  String getUpdateAllFields()
           
protected  void getValue(DbPreparedStatement preparedStatement, DbValue value)
          Get one value into DbValue from DbPreparedStatement
protected  void getValues(DbPreparedStatement preparedStatement, DbValue[] values)
          Get several values into DbValue from DbPreparedStatement
protected abstract  String getWherePrimaryKey()
           
protected abstract  void initObject()
          To setup primaryKey, otherFields, allFields.
 void insert()
          Insert object into table
 void select()
          Select object from table
protected abstract  void setFromArray()
          Internal function to retrieve data from Array to pull data from database
protected abstract  void setPrimaryKey()
          Set the primary Key as current value
protected abstract  void setToArray()
          Internal function to set to Array used to push data to database
static void setTrueValue(PreparedStatement ps, DbValue value, int rank)
          Set Value into PreparedStatement
protected  void setValue(DbPreparedStatement preparedStatement, DbValue value)
          Set one value to a DbPreparedStatement
protected  void setValues(DbPreparedStatement preparedStatement, DbValue[] values)
          Set several values to a DbPreparedStatement
 void update()
          Update object to table
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

primaryKey

protected DbValue[] primaryKey
To be implemented


otherFields

protected DbValue[] otherFields

allFields

protected DbValue[] allFields

isSaved

protected boolean isSaved

dbSession

protected final DbSession dbSession
The DbSession to use

Constructor Detail

AbstractDbData

public AbstractDbData(DbSession dbSession)
Abstract constructor to set the DbSession to use

Parameters:
dbSession -
Method Detail

initObject

protected abstract void initObject()
To setup primaryKey, otherFields, allFields. Note this initObject is called within constructor of AbstractDbData. Be careful that no data is actually initialized at this stage.


getWherePrimaryKey

protected abstract String getWherePrimaryKey()
Returns:
The Where condition on Primary Key

setPrimaryKey

protected abstract void setPrimaryKey()
Set the primary Key as current value


getSelectAllFields

protected abstract String getSelectAllFields()

getTable

protected abstract String getTable()

getInsertAllValues

protected abstract String getInsertAllValues()

getUpdateAllFields

protected abstract String getUpdateAllFields()

exist

public boolean exist()
              throws GoldenGateDatabaseException
Test the existence of the current object

Returns:
True if the object exists
Throws:
GoldenGateDatabaseException

select

public void select()
            throws GoldenGateDatabaseException
Select object from table

Throws:
GoldenGateDatabaseException

insert

public void insert()
            throws GoldenGateDatabaseException
Insert object into table

Throws:
GoldenGateDatabaseException

update

public void update()
            throws GoldenGateDatabaseException
Update object to table

Throws:
GoldenGateDatabaseException

delete

public void delete()
            throws GoldenGateDatabaseException
Delete object from table

Throws:
GoldenGateDatabaseException

changeUpdatedInfo

public abstract void changeUpdatedInfo(AbstractDbData.UpdatedInfo info)
Change UpdatedInfo status

Parameters:
info -

setToArray

protected abstract void setToArray()
Internal function to set to Array used to push data to database


setFromArray

protected abstract void setFromArray()
                              throws GoldenGateDatabaseSqlException
Internal function to retrieve data from Array to pull data from database

Throws:
GoldenGateDatabaseSqlException

setTrueValue

public static void setTrueValue(PreparedStatement ps,
                                DbValue value,
                                int rank)
                         throws GoldenGateDatabaseSqlException
Set Value into PreparedStatement

Parameters:
ps -
value -
rank - >= 1
Throws:
GoldenGateDatabaseSqlException

setValue

protected void setValue(DbPreparedStatement preparedStatement,
                        DbValue value)
                 throws GoldenGateDatabaseNoConnectionException,
                        GoldenGateDatabaseSqlException
Set one value to a DbPreparedStatement

Parameters:
preparedStatement -
value -
Throws:
GoldenGateDatabaseNoConnectionException
GoldenGateDatabaseSqlException

setValues

protected void setValues(DbPreparedStatement preparedStatement,
                         DbValue[] values)
                  throws GoldenGateDatabaseNoConnectionException,
                         GoldenGateDatabaseSqlException
Set several values to a DbPreparedStatement

Parameters:
preparedStatement -
values -
Throws:
GoldenGateDatabaseNoConnectionException
GoldenGateDatabaseSqlException

getTrueValue

public static void getTrueValue(ResultSet rs,
                                DbValue value)
                         throws GoldenGateDatabaseSqlException
Get one value into DbValue from ResultSet

Parameters:
rs -
value -
Throws:
GoldenGateDatabaseSqlException

getValue

protected void getValue(DbPreparedStatement preparedStatement,
                        DbValue value)
                 throws GoldenGateDatabaseNoConnectionException,
                        GoldenGateDatabaseSqlException
Get one value into DbValue from DbPreparedStatement

Parameters:
preparedStatement -
value -
Throws:
GoldenGateDatabaseNoConnectionException
GoldenGateDatabaseSqlException

getValues

protected void getValues(DbPreparedStatement preparedStatement,
                         DbValue[] values)
                  throws GoldenGateDatabaseNoConnectionException,
                         GoldenGateDatabaseSqlException
Get several values into DbValue from DbPreparedStatement

Parameters:
preparedStatement -
values -
Throws:
GoldenGateDatabaseNoConnectionException
GoldenGateDatabaseSqlException

get

public boolean get(DbPreparedStatement preparedStatement)
Get Values from PreparedStatement

Parameters:
preparedStatement -
Returns:
True if OK, else False


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.