org.sormula.operation.cascade.lazy
Class DurableLazySelector<R>

java.lang.Object
  extended by org.sormula.operation.cascade.lazy.AbstractLazySelector<R>
      extended by org.sormula.operation.cascade.lazy.DurableLazySelector<R>
Type Parameters:
R - type of source row class
All Implemented Interfaces:
java.io.Serializable, LazySelectable

public class DurableLazySelector<R>
extends AbstractLazySelector<R>

A lazy cascade selector that uses a DataSource or data source name to create the Database when performing the lazy select. Source rows must be selected with an operation that uses a database created with Database.Database(DataSource), Database.Database(DataSource, String), Database.Database(String), or Database.Database(String, String)

This class is slightly less efficient than SimpleLazySelector because a Database and Table are created when selector needs to be used. It is more flexible since it can be used any time even when original connection has been closed.

DurableLazySelector is good for scenario's when source row may be serialzed to disk, for example, in web application where source row is stored in web session.

Since:
1.8 and 2.2
Author:
Jeff Miller
See Also:
Serialized Form

Constructor Summary
DurableLazySelector()
          Constructs for use when DurableLazySelector is base class of row that will contain lazy select fields.
DurableLazySelector(R source)
          Constructs for use as delegate for row that will contain lazy select fields.
 
Method Summary
protected  void closeDatabase()
          Closes Database created with openDatabase().
 javax.sql.DataSource getDataSource()
          Gets the DataSource from database used by pendingLazySelects(Database).
 java.lang.String getDataSourceName()
          Gets the JNDI name to use to look up DataSource.
 java.lang.String getSchema()
          Gets the schema from database used by pendingLazySelects(Database).
protected  void openDatabase()
          Creates a new instance of a Database from data source name or data source obtained in pendingLazySelects(Database).
 void pendingLazySelects(Database database)
          DataSource and schema are obtained from database parameter.
 
Methods inherited from class org.sormula.operation.cascade.lazy.AbstractLazySelector
begin, checkLazySelects, commit, getDatabase, getPendingLazySelectFields, getSource, initDatabase, initPendingLazySelectCascadeFields, isLocalTransaction, isPendingLazySelects, isUseTransaction, lazySelect, rollback, setDatabase, setUseTransaction
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DurableLazySelector

public DurableLazySelector()
Constructs for use when DurableLazySelector is base class of row that will contain lazy select fields. Typically the derived class is the one side of a one-to-many relationship or derived class has a reference to the other class in a one-to-one relationship. AbstractLazySelector.setUseTransaction(boolean) is true by default.


DurableLazySelector

public DurableLazySelector(R source)
Constructs for use as delegate for row that will contain lazy select fields. AbstractLazySelector.setUseTransaction(boolean) is true by default.

Parameters:
source - row that contains fields with SelectCascade.lazy() is true; typically source is the one side of a one-to-many relationship or source has a reference to the other class in a one-to-one relationship
Method Detail

pendingLazySelects

public void pendingLazySelects(Database database)
                        throws LazyCascadeException
DataSource and schema are obtained from database parameter.

Specified by:
pendingLazySelects in interface LazySelectable
Overrides:
pendingLazySelects in class AbstractLazySelector<R>
Parameters:
database - database that was used to select source row
Throws:
LazyCascadeException - if Database.getDataSource() is null

getDataSourceName

public java.lang.String getDataSourceName()
Gets the JNDI name to use to look up DataSource. This name was obtained from database by pendingLazySelects(Database).

Returns:
data source JNDI name or null if none
Since:
1.9 and 2.3

getDataSource

public javax.sql.DataSource getDataSource()
Gets the DataSource from database used by pendingLazySelects(Database).

Returns:
data source to use for lazy selects

getSchema

public java.lang.String getSchema()
Gets the schema from database used by pendingLazySelects(Database).

Returns:
schema to use for lazy selects

openDatabase

protected void openDatabase()
                     throws LazyCascadeException
Creates a new instance of a Database from data source name or data source obtained in pendingLazySelects(Database). Data source will be looked up in JNDI if data source name is known and data source is not known.

Specified by:
openDatabase in class AbstractLazySelector<R>
Throws:
LazyCascadeException - if error
Since:
1.9 and 2.3

closeDatabase

protected void closeDatabase()
                      throws LazyCascadeException
Closes Database created with openDatabase().

Specified by:
closeDatabase in class AbstractLazySelector<R>
Throws:
LazyCascadeException - if error
Since:
1.9 and 2.3