org.rimudb
Class Table

java.lang.Object
  extended by org.rimudb.Table

public class Table
extends java.lang.Object

This class represents a table in the database.

Author:
Simon Ritchie

Constructor Summary
Table()
          Construct a Table.
 
Method Summary
 void add(Record record)
          Add a record to the table.
 void addRecordToBatch(Session session, Record record, boolean ignoreAutoCommitBatchErrors)
           
 int addUsingSession(Session session, Record record)
          Add a record using the Session.
protected  void checkWhereListIsPrimaryKey(WhereList whereList, int count)
          Check the primary WhereList contains the property names that match the primary key.
 DataObject createDataObject(Database database, LockResult lockResult)
          Create a DO instance for this table.
 DataObject createDataObject(Database database, Record record)
          Instantiate a Data Object.
 DataObject createDataObject(java.sql.ResultSet rs)
          Create DO instance and load with values from a result set.
protected  java.sql.PreparedStatement createPreparedStatement(java.sql.Connection con, java.lang.String sql, CrudType crudType)
          Return a prepared statement for the given SQL.
 Record createRecord(java.sql.ResultSet rs)
          Create Record instance and load with values from a result set.
 int deleteAll(WhereList whereList)
          Delete all the records that match the WhereList
 int deleteAllUsingSession(Session session, WhereList whereList)
          Delete records that match a WhereList within a Session.
 int deleteByPrimaryKey(WhereList primaryWhereList)
          Delete a record using the primary key
 void deleteByPrimaryKeyInBatch(Session session, WhereList primaryWhereList, boolean ignoreAutoCommitBatchErrors)
           
 Record get(WhereList primaryWhereList)
          Return the record for a primary KeyList.
 LockResult get(WhereList primaryWhereList, Lock lockType)
          Return the LockResult for a primary WhereList.
 java.util.List<? extends DataObject> getAllDataObjects(WhereList whereList, GroupByList groupBylist, OrderByList orderByList, int maxRecords)
          Return a List of DO instances.
 java.lang.String getCreateTableSQL(java.lang.String url, boolean ignoreIfExists, boolean prettyFormat)
          Return the SQL used to create the table in the database.
 Database getDatabase()
          Return the Database this table is connected to
 DataObject getDataObject(WhereList primaryWhereList, Lock lockType)
          Read the DataObject for a primaryWhereList and Lock from the database.
 java.lang.Class<? extends DataObject> getDataObjectClass()
          Return the Data Object class.
protected  java.sql.PreparedStatement getDeleteStatement(java.sql.Connection con, java.lang.String sql, WhereList whereList)
           
protected  int getMaximumBatchSize()
          Return the maximum batch size for this table
 OptimisticLocking getOptimisticLocking()
          Return the optimistic locking strategy.
 int getRecordCount()
           
 int getRecordCount(WhereList whereList)
          Return the number of records matching the WhereList.
 ISQLAdapter getSQLAdapter()
          Return the SQL Adapter.
 TableMetaData getTableMetaData()
          Return the TableMetaData.
 java.lang.String getTableName()
          Return the table name.
 void initialize()
          Initialize the table
 boolean isUsingLockingHints()
           
 void loadRecord(Record record, java.sql.ResultSet rs, boolean useCachedBinder)
           
protected  void populateGeneratedKeys(java.sql.PreparedStatement stmt, Record record)
          Populate the Record with the generated keys.
protected  void populateGeneratedKeys(java.sql.PreparedStatement stmt, Record[] records)
          Populate the Records with the generated keys.
protected  void populateQueriedKeys(java.sql.PreparedStatement stmt, Record record)
          Populate the Record with the keys generated from a query.
 boolean processesGeneratedKeys()
          Return true if this table has auto increment keys and the database supports them.
 void setDatabase(Database database)
          Set the Database for this table.
protected  void setMaximumBatchSize(int maximumBatchSize)
           
 void setOptimisticLocking(OptimisticLocking optimisticLocking)
          Set the optimistic locking strategy.
 void setRecordBinder(RecordBinder recordBinder)
          Set the RecordBinder for the table.
 void setSQLAdpater(ISQLAdapter sqlAdapter)
          Set the SQL Adapter.
protected  void setTableMetaData(TableMetaData tableMetaData)
          Set the TableMetaData.
 void setTableName(java.lang.String tableName)
          Set the table name.
 void setUsingLockingHints(boolean usingLockingHints)
           
protected  void update(java.sql.Connection con, Record oldRecord, Record newRecord)
          Update the database with the newRecord data.
protected  void update(Record oldRecord, Record newRecord)
          Change a record in the table.
 void updateRecordInBatch(Session session, Record oldRecord, Record newRecord)
           
 void updateUsingSession(Session session, Record oldRecord, Record newRecord)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Table

public Table()
Construct a Table.

Method Detail

getDataObjectClass

public java.lang.Class<? extends DataObject> getDataObjectClass()
Return the Data Object class.

Returns:
Class

getCreateTableSQL

public java.lang.String getCreateTableSQL(java.lang.String url,
                                          boolean ignoreIfExists,
                                          boolean prettyFormat)
                                   throws RimuDBException
Return the SQL used to create the table in the database. The url parameter is used to allow a different SQL string to be returned depending on the database.

Parameters:
url - String
ignoreIfExists -
Returns:
String
Throws:
RimuDBException

createDataObject

public DataObject createDataObject(Database database,
                                   Record record)
                            throws RimuDBException
Instantiate a Data Object.

Parameters:
database - Database
record -
Returns:
DataObject
Throws:
RimuDBException

createDataObject

public DataObject createDataObject(Database database,
                                   LockResult lockResult)
                            throws RimuDBException
Create a DO instance for this table.

Parameters:
database - Database
lockResult - LockResult
Returns:
DataObject
Throws:
RimuDBException

createDataObject

public DataObject createDataObject(java.sql.ResultSet rs)
                            throws RimuDBException
Create DO instance and load with values from a result set.

Parameters:
rs - ResultSet
Returns:
DataObject
Throws:
RimuDBException

createRecord

public Record createRecord(java.sql.ResultSet rs)
                    throws RimuDBException,
                           java.sql.SQLException
Create Record instance and load with values from a result set.

Throws:
RimuDBException
java.sql.SQLException

loadRecord

public void loadRecord(Record record,
                       java.sql.ResultSet rs,
                       boolean useCachedBinder)
                throws RimuDBException
Throws:
RimuDBException

add

public void add(Record record)
         throws RimuDBException
Add a record to the table.

Parameters:
record - Record
Throws:
RimuDBException

deleteByPrimaryKey

public int deleteByPrimaryKey(WhereList primaryWhereList)
                       throws RimuDBException
Delete a record using the primary key

Parameters:
primaryWhereList - WhereList
Throws:
RimuDBException

deleteAll

public int deleteAll(WhereList whereList)
              throws RimuDBException
Delete all the records that match the WhereList

Parameters:
whereList - WhereList
Returns:
int The number of records deleted
Throws:
RimuDBException

getDeleteStatement

protected java.sql.PreparedStatement getDeleteStatement(java.sql.Connection con,
                                                        java.lang.String sql,
                                                        WhereList whereList)
                                                 throws java.sql.SQLException,
                                                        RimuDBException
Throws:
java.sql.SQLException
RimuDBException

getAllDataObjects

public java.util.List<? extends DataObject> getAllDataObjects(WhereList whereList,
                                                              GroupByList groupBylist,
                                                              OrderByList orderByList,
                                                              int maxRecords)
                                                       throws RimuDBException
Return a List of DO instances.

Parameters:
whereList - WhereList
groupBylist - GroupByList
orderByList - OrderByList
maxRecords - int
Returns:
List
Throws:
RimuDBException

getRecordCount

public int getRecordCount()
                   throws RimuDBException
Throws:
RimuDBException

getRecordCount

public int getRecordCount(WhereList whereList)
                   throws RimuDBException
Return the number of records matching the WhereList.

Parameters:
whereList - WhereList
Returns:
int Number of records
Throws:
RimuDBException

getDataObject

public DataObject getDataObject(WhereList primaryWhereList,
                                Lock lockType)
                         throws RimuDBException
Read the DataObject for a primaryWhereList and Lock from the database.

Parameters:
primaryWhereList - WhereList
lockType - Lock
Returns:
DataObject
Throws:
RimuDBException

get

public Record get(WhereList primaryWhereList)
           throws RimuDBException
Return the record for a primary KeyList.

Parameters:
primaryWhereList - WhereList
Returns:
Record
Throws:
RimuDBException

get

public LockResult get(WhereList primaryWhereList,
                      Lock lockType)
               throws RimuDBException
Return the LockResult for a primary WhereList.

Parameters:
primaryWhereList - WhereList
lockType - Lock
Returns:
LockResult
Throws:
RimuDBException

createPreparedStatement

protected java.sql.PreparedStatement createPreparedStatement(java.sql.Connection con,
                                                             java.lang.String sql,
                                                             CrudType crudType)
                                                      throws java.sql.SQLException
Return a prepared statement for the given SQL.

Throws:
java.sql.SQLException

checkWhereListIsPrimaryKey

protected void checkWhereListIsPrimaryKey(WhereList whereList,
                                          int count)
                                   throws InvalidKeyListException
Check the primary WhereList contains the property names that match the primary key. Check that the value of each key is the correct data type.

Parameters:
whereList - WhereList
count - int
Throws:
InvalidKeyListException

getMaximumBatchSize

protected int getMaximumBatchSize()
Return the maximum batch size for this table


setMaximumBatchSize

protected void setMaximumBatchSize(int maximumBatchSize)

getDatabase

public Database getDatabase()
Return the Database this table is connected to

Returns:
Database

setDatabase

public void setDatabase(Database database)
Set the Database for this table.

Parameters:
database - Database

setSQLAdpater

public void setSQLAdpater(ISQLAdapter sqlAdapter)
Set the SQL Adapter.

Parameters:
sqlAdapter - ISQLAdapter

getSQLAdapter

public ISQLAdapter getSQLAdapter()
Return the SQL Adapter.

Returns:
ISQLAdapter

deleteByPrimaryKeyInBatch

public void deleteByPrimaryKeyInBatch(Session session,
                                      WhereList primaryWhereList,
                                      boolean ignoreAutoCommitBatchErrors)
                               throws RimuDBException
Throws:
RimuDBException

addRecordToBatch

public void addRecordToBatch(Session session,
                             Record record,
                             boolean ignoreAutoCommitBatchErrors)
                      throws RimuDBException
Throws:
RimuDBException

populateGeneratedKeys

protected void populateGeneratedKeys(java.sql.PreparedStatement stmt,
                                     Record record)
                              throws java.sql.SQLException,
                                     RimuDBException
Populate the Record with the generated keys.

Parameters:
stmt - PreparedStatement
record - Record
Throws:
java.sql.SQLException
RimuDBException

populateGeneratedKeys

protected void populateGeneratedKeys(java.sql.PreparedStatement stmt,
                                     Record[] records)
                              throws java.sql.SQLException,
                                     RimuDBException
Populate the Records with the generated keys.

Parameters:
stmt - PreparedStatement
records - Record[]
Throws:
java.sql.SQLException
RimuDBException

populateQueriedKeys

protected void populateQueriedKeys(java.sql.PreparedStatement stmt,
                                   Record record)
                            throws java.sql.SQLException,
                                   RimuDBException
Populate the Record with the keys generated from a query.

Parameters:
stmt - PreparedStatement
record - Record
Throws:
java.sql.SQLException
RimuDBException

getTableMetaData

public TableMetaData getTableMetaData()
Return the TableMetaData.

Returns:
TableMetaData

setTableMetaData

protected void setTableMetaData(TableMetaData tableMetaData)
Set the TableMetaData.

Parameters:
tableMetaData - TableMetaData

deleteAllUsingSession

public int deleteAllUsingSession(Session session,
                                 WhereList whereList)
                          throws RimuDBException
Delete records that match a WhereList within a Session. Returns the number of records deleted.

Parameters:
session - Session
whereList - WhereList
Returns:
int
Throws:
RimuDBException

addUsingSession

public int addUsingSession(Session session,
                           Record record)
                    throws RimuDBException
Add a record using the Session.

Parameters:
session - Session
record - Record
Returns:
int The number of records added
Throws:
RimuDBException

update

protected void update(Record oldRecord,
                      Record newRecord)
               throws RimuDBException
Change a record in the table.

Parameters:
oldRecord - Record
newRecord - Record
Throws:
RimuDBException

update

protected void update(java.sql.Connection con,
                      Record oldRecord,
                      Record newRecord)
               throws RimuDBException
Update the database with the newRecord data. Key values from the oldRecord are used. The update is run using the SQL connection con.

Throws:
RimuDBException

updateUsingSession

public void updateUsingSession(Session session,
                               Record oldRecord,
                               Record newRecord)
                        throws RimuDBException
Throws:
RimuDBException

updateRecordInBatch

public void updateRecordInBatch(Session session,
                                Record oldRecord,
                                Record newRecord)
                         throws RimuDBException
Parameters:
session - Session
oldRecord - Record
newRecord - Record
Throws:
RimuDBException

initialize

public void initialize()
                throws RimuDBException
Initialize the table

Throws:
java.lang.Exception
java.lang.SecurityException
RimuDBException

setUsingLockingHints

public void setUsingLockingHints(boolean usingLockingHints)
Parameters:
usingLockingHints - the usingLockingHints to set

isUsingLockingHints

public boolean isUsingLockingHints()
Returns:
the usingLockingHints

setOptimisticLocking

public void setOptimisticLocking(OptimisticLocking optimisticLocking)
Set the optimistic locking strategy.

Parameters:
optimisticLocking - OptimisticLocking

getOptimisticLocking

public OptimisticLocking getOptimisticLocking()
Return the optimistic locking strategy.

Returns:
OptimisticLocking

getTableName

public java.lang.String getTableName()
Return the table name.

Returns:
String

setTableName

public void setTableName(java.lang.String tableName)
Set the table name.

Parameters:
tableName - String

setRecordBinder

public void setRecordBinder(RecordBinder recordBinder)
Set the RecordBinder for the table.

Parameters:
recordBinder - RecordBinder

processesGeneratedKeys

public boolean processesGeneratedKeys()
Return true if this table has auto increment keys and the database supports them.

Returns:
boolean


Copyright © 2008-2011 Simon Ritchie. All Rights Reserved.