org.bsf.remoteIterator.server
Class RemoteIteratorBean

java.lang.Object
  extended byorg.bsf.commons.ejb.GenericAdapterBean
      extended byorg.bsf.commons.ejb.SessionAdapterBean
          extended byorg.bsf.remoteIterator.server.RemoteIteratorBean
All Implemented Interfaces:
javax.ejb.EnterpriseBean, java.io.Serializable, javax.ejb.SessionBean

public class RemoteIteratorBean
extends org.bsf.commons.ejb.SessionAdapterBean

Executes and provides an iterator on a SQL statement using the Bean container to handle passivation and so on... Usually used to populate a Table on the client without transfering all the rows at once.

See Also:
Serialized Form

Field Summary
private  java.util.List _columnMetadatas
           
private  java.sql.Connection _connection
           
private  int _defaultBlockSize
           
private  int _lastReadBlockSize
          Keeps the size of the last read block.
private  int _position
          The curent position into the resultset (needed when passivated or activated).
private  java.sql.ResultSet _resultSet
           
private  java.lang.String _SQLQuery
           
private  java.sql.Statement _statement
           
private static java.lang.String EMPTY_STRING
           
private static java.lang.String JNDI_DATASOURCE_NAME
           
private static int RI_BUFFER_SIZE
           
private static int RI_DEFAULT_BLOCK_SIZE
           
 
Fields inherited from class org.bsf.commons.ejb.SessionAdapterBean
_ejbContext
 
Fields inherited from class org.bsf.commons.ejb.GenericAdapterBean
 
Constructor Summary
RemoteIteratorBean()
           
 
Method Summary
 RemoteIteratorResultTable absolute(int p_position)
           
 RemoteIteratorResultTable absolute(int p_position, int p_blockSize)
           
private  void addCurrentResultSetRow(RemoteIteratorResultTable p_resultTable)
          Adds the current record to the given RemoteIteratorResultTable.
private  void closeDataSource()
          Closes the DB ressources (ResultSet, Statement, Connection).
private  void createMetadatas()
          Creates the meta data from the actual resultsets.
 void ejbActivate()
           
 void ejbCreate(java.lang.String p_query)
           
 void ejbPassivate()
           
 void ejbRemove()
          Ensures that everything is closed correctly (mainly the DB ressources).
private  void executeQuery()
          Prepares and executes the SQL query.
private  void firstQueryExecution()
          Should be called for the first execution of the Query (opens the DataSource and executes the query).
 java.util.List getColumnMetaData()
           
private  int getPosition()
           
 java.lang.Long getRowCount()
           
private  boolean isAfterLast()
           
private  boolean isBeforeFirst()
           
private  boolean isLast()
           
 RemoteIteratorResultTable next()
           
 RemoteIteratorResultTable next(int p_blockSize)
           
private  void openDataSource()
          Retrieves a connection to the Database.
private  void prepareQuery()
          Must be called before executeQuery as it creates the statement and configures it.
 RemoteIteratorResultTable previous()
           
 RemoteIteratorResultTable previous(int p_blockSize)
           
private  void restorePosition(int p_position, int p_lastReadBlockSize)
          Sets the cursor to the specified position and update the lastReadBlockSize.
 void setDefaultBlockSize(java.lang.Integer p_defaultBlockSize)
          Sets the default block size to be used for this RemoteIteratorBean.
 
Methods inherited from class org.bsf.commons.ejb.SessionAdapterBean
ejbCreate, getEJBContext, getUserName, setSessionContext
 
Methods inherited from class org.bsf.commons.ejb.GenericAdapterBean
getConnection, getEJBClassName, getEJBToolBox, getHome, handleCreateSessionException, handleExceptionAsSystemException, handleFinderException, handleRemoteException, handleSQLException, logDebug, logError, logError, logFatal, logFatal, logGraphBegin, logGraphEnd, logInfo, logWarn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RI_BUFFER_SIZE

private static final int RI_BUFFER_SIZE
See Also:
Constant Field Values

RI_DEFAULT_BLOCK_SIZE

private static final int RI_DEFAULT_BLOCK_SIZE
See Also:
Constant Field Values

EMPTY_STRING

private static final java.lang.String EMPTY_STRING
See Also:
Constant Field Values

JNDI_DATASOURCE_NAME

private static final java.lang.String JNDI_DATASOURCE_NAME
See Also:
Constant Field Values

_lastReadBlockSize

private int _lastReadBlockSize
Keeps the size of the last read block.


_position

private int _position
The curent position into the resultset (needed when passivated or activated).


_SQLQuery

private java.lang.String _SQLQuery

_columnMetadatas

private java.util.List _columnMetadatas

_defaultBlockSize

private int _defaultBlockSize

_statement

private transient java.sql.Statement _statement

_resultSet

private transient java.sql.ResultSet _resultSet

_connection

private transient java.sql.Connection _connection
Constructor Detail

RemoteIteratorBean

public RemoteIteratorBean()
Method Detail

createMetadatas

private void createMetadatas()
Creates the meta data from the actual resultsets.


ejbCreate

public void ejbCreate(java.lang.String p_query)
               throws javax.ejb.CreateException
Parameters:
p_query - The SQL statement to execute. It should be a valid SQL statement otherwise you'll get an SQL exception later :o) !!!
Throws:
java.lang.RuntimeException - if the given query is null or blank.
javax.ejb.CreateException

ejbRemove

public void ejbRemove()
Ensures that everything is closed correctly (mainly the DB ressources).


getColumnMetaData

public java.util.List getColumnMetaData()
Returns:
A List of ColumnMetaData corresponding to the executed SQL statement.
See Also:
ColumnMetadata

absolute

public RemoteIteratorResultTable absolute(int p_position)
Returns:
the block of rows starting at the given position and of the default block size.
See Also:
absolute(int p_position, int p_blockSize), RemoteIteratorResultTable

absolute

public RemoteIteratorResultTable absolute(int p_position,
                                          int p_blockSize)
Returns:
the block of rows starting at the given position and of the given size.
See Also:
absolute(int p_position), RemoteIteratorResultTable

previous

public RemoteIteratorResultTable previous()
Returns:
the previous "block" of rows (starting from before the first row of the actual block) as a RemoteIteratorResultTable. The default block size is used. Returns the default block size rows from the begining if the default block size to use is bigger than the available rows.
See Also:
previous(int p_blockSize), RemoteIteratorResultTable

previous

public RemoteIteratorResultTable previous(int p_blockSize)
Parameters:
p_blockSize - the size of the block to return. Should be greater than zero (not checked).
Returns:
the previous p_blockSize rows (starting from the actual position) as a RemoteIteratorResultTable. Return to the beginning of the actual block before returning the previous rows. Returns the p_blockSize rows from the begining if the given block size is bigger than the available rows.
See Also:
RemoteIteratorResultTable

next

public RemoteIteratorResultTable next()
Returns:
the next "block" of rows (starting from the actual position) as a RemoteIteratorResultTable. The default block size is used.
See Also:
next(int p_blockSize), RemoteIteratorResultTable

next

public RemoteIteratorResultTable next(int p_blockSize)
Parameters:
p_blockSize - the size of the block to return. Should be greater than zero (not checked).
Returns:
the next p_blockSize rows (starting from the actual position) as a RemoteIteratorResultTable.
See Also:
RemoteIteratorResultTable

getRowCount

public java.lang.Long getRowCount()
Returns:
the total number of records (the cursor remains on its current position).

isLast

private boolean isLast()
                throws java.sql.SQLException
Returns:
true if the current block is the last block.
Throws:
java.sql.SQLException

isAfterLast

private boolean isAfterLast()
                     throws java.sql.SQLException
Returns:
true if we are after the last record
Throws:
java.sql.SQLException

isBeforeFirst

private boolean isBeforeFirst()
                       throws java.sql.SQLException
Returns:
true if the cursor is before the first record, false otherwise.
Throws:
java.sql.SQLException

getPosition

private int getPosition()
                 throws java.sql.SQLException
Returns:
The current position of the cursor in the ResultSet, 0 if the resultset is null.
Throws:
java.sql.SQLException

restorePosition

private void restorePosition(int p_position,
                             int p_lastReadBlockSize)
                      throws java.sql.SQLException
Sets the cursor to the specified position and update the lastReadBlockSize.

Throws:
java.sql.SQLException

addCurrentResultSetRow

private void addCurrentResultSetRow(RemoteIteratorResultTable p_resultTable)
                             throws java.sql.SQLException
Adds the current record to the given RemoteIteratorResultTable.

Throws:
java.sql.SQLException - if there's a problem in the retrieval of the record...
java.lang.NullPointerException - if the given ResultTable is null.
See Also:
RemoteIteratorResultTable

prepareQuery

private void prepareQuery()
                   throws java.sql.SQLException
Must be called before executeQuery as it creates the statement and configures it.

Throws:
java.sql.SQLException

executeQuery

private void executeQuery()
                   throws java.sql.SQLException
Prepares and executes the SQL query.

Throws:
java.sql.SQLException - if there's a problem while preparing or executing the SQL.

firstQueryExecution

private void firstQueryExecution()
Should be called for the first execution of the Query (opens the DataSource and executes the query).


openDataSource

private void openDataSource()
                     throws java.sql.SQLException
Retrieves a connection to the Database.

Throws:
java.sql.SQLException

closeDataSource

private void closeDataSource()
Closes the DB ressources (ResultSet, Statement, Connection).


setDefaultBlockSize

public void setDefaultBlockSize(java.lang.Integer p_defaultBlockSize)
Sets the default block size to be used for this RemoteIteratorBean.


ejbActivate

public void ejbActivate()

ejbPassivate

public void ejbPassivate()