org.rimudb
Class Session

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

public class Session
extends java.lang.Object

This class represents a transaction session. For batch operations, an internal queue is maintained. The queue contains batch statements in the order they are submitted. One batch statement is used for each table. This is necessary in order to ensure that batch statements get executed in the correct order. This means that if 10 batch inserts are executed for table_a, then another 10 batch inserts are executed for table_b, and then another 10 batch inserts are executed for table_a, then the queue will contain three prepared statements in order of inserts. When commit() is called the three prepared statements will be executed one after another, preserving the order of inserts. Obviously, if your application was coded differently, it would be more efficient to perform all 20 batch inserts for table_a first, and then the 10 batch inserts for table_b. This would only result in two prepared statements in the queue. In order to get the best batch performance, applications should attempt to perform all the operations to one table and then all the operations to the next table. The worst performance would occur if the application alternately executed one batch insert to table_a and then one batch insert to table_b. This would result in no gain in performance over regular inserts.

Author:
Simon Ritchie

Field Summary
static int BATCH_DELETE
           
static int BATCH_INSERT
           
static int BATCH_NONE
           
static int BATCH_UPDATE
           
 
Constructor Summary
Session(java.sql.Connection databaseConnection)
           
 
Method Summary
 void batchDelete(DataObject dataObject)
           
 void batchInsert(DataObject dataObject)
          Insert the data object within a batch.
 void batchUpdate(DataObject dataObject)
           
 void close()
          Close the session.
 void commit()
           
 void commit(boolean ignoreErrors)
           
protected  java.sql.PreparedStatement getBatchStatement(Table table, int batchType)
          Return any previously created prepared statement that we used for the table and type of batch.
 BatchStatistic[] getBatchStatistics()
          Return statistics on the batches in the queue.
protected  java.sql.Connection getConnection()
           
 int getCurrentBatchSize()
          Return the current batch size.
 void rollback()
          Rollback the session.
protected  void setBatchStatement(Table table, java.sql.PreparedStatement batchStatement, int batchType)
          Save the prepared statement that we used for the table and batch type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BATCH_NONE

public static final int BATCH_NONE
See Also:
Constant Field Values

BATCH_INSERT

public static final int BATCH_INSERT
See Also:
Constant Field Values

BATCH_UPDATE

public static final int BATCH_UPDATE
See Also:
Constant Field Values

BATCH_DELETE

public static final int BATCH_DELETE
See Also:
Constant Field Values
Constructor Detail

Session

public Session(java.sql.Connection databaseConnection)
        throws RimuDBException
Throws:
RimuDBException
Method Detail

getConnection

protected java.sql.Connection getConnection()

commit

public void commit()
            throws RimuDBException
Throws:
RimuDBException

commit

public void commit(boolean ignoreErrors)
            throws RimuDBException
Throws:
RimuDBException

getCurrentBatchSize

public int getCurrentBatchSize()
Return the current batch size.

Returns:
int

rollback

public void rollback()
              throws RimuDBException
Rollback the session.

Throws:
RimuDBException

close

public void close()
           throws RimuDBException
Close the session.

Throws:
RimuDBException

getBatchStatement

protected java.sql.PreparedStatement getBatchStatement(Table table,
                                                       int batchType)
Return any previously created prepared statement that we used for the table and type of batch.

Parameters:
table - Table
batchType - int
Returns:
PreparedStatement

setBatchStatement

protected void setBatchStatement(Table table,
                                 java.sql.PreparedStatement batchStatement,
                                 int batchType)
Save the prepared statement that we used for the table and batch type.

Parameters:
table - Table
batchStatement - PreparedStatement
batchType - int

getBatchStatistics

public BatchStatistic[] getBatchStatistics()
Return statistics on the batches in the queue.

Returns:
BatchStatistic[]

batchInsert

public void batchInsert(DataObject dataObject)
                 throws RimuDBException
Insert the data object within a batch.

Parameters:
dataObject -
Throws:
RimuDBException

batchDelete

public void batchDelete(DataObject dataObject)
                 throws RimuDBException
Throws:
RimuDBException

batchUpdate

public void batchUpdate(DataObject dataObject)
                 throws RimuDBException
Throws:
RimuDBException


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