R
- type of row class that is to be lazily selectedpublic abstract class AbstractLazySelector<R> extends java.lang.Object implements LazySelectable, java.io.Serializable
checkLazySelects(String)
only once per lazy select field.
This class may be used as a super class of row that has a reference to a lazy select field or it may be used as a delegate when row requires a different super class.
Subclass must implement openDatabase()
to create the Database
to use for the lazy
select. Usually pendingLazySelects(Database)
is overridden to record information about the
current Database
to be used by openDatabase()
.
Constructor and Description |
---|
AbstractLazySelector()
Constructs for use when AbstractLazySelector is base class of row that will contain lazy select fields.
|
AbstractLazySelector(R source)
Constructs for use as delegate for row that will contain lazy select fields.
|
Modifier and Type | Method and Description |
---|---|
protected void |
begin()
Starts a transaction for
lazySelect(Field) . |
void |
checkLazySelects(java.lang.String fieldName)
Checks if field should be selected.
|
protected abstract void |
closeDatabase()
Invoked by
checkLazySelects(String) to close the Database instance that
was used to perform the lazy selects. |
protected void |
commit()
Commits the transaction for
lazySelect(Field) . |
Database |
getDatabase()
Gets the database to use for lazy select.
|
java.util.Map<java.lang.String,java.lang.reflect.Field> |
getPendingLazySelectFields()
Gets the fields that will be initialized with lazy select.
|
R |
getSource()
Gets the owner of the field(s) that will be lazily selected.
|
protected void |
initPendingLazySelectCascadeFields()
Initializes map of all fields that have a lazy select.
|
boolean |
isLocalTransaction()
Reports if this class has created a transaction for use when performing a lazy select.
|
boolean |
isPendingLazySelects()
Reports lazy select status.
|
boolean |
isUseTransaction()
Reports if a transaction will be created if needed.
|
protected void |
lazySelect(java.lang.reflect.Field field)
Performs lazy select for all select cascades of field where
SelectCascade.lazy() is
true. |
protected abstract void |
openDatabase()
Invoked by
checkLazySelects(String) to create a Database instance that will be used to
perform the lazy selects. |
void |
pendingLazySelects(Database database)
Notifies selector that at least one field has lazy select to be performed.
|
protected void |
rollback()
Rolls back the transaction for
lazySelect(Field) . |
void |
setDatabase(Database database)
Sets the database to use for lazy selects.
|
void |
setUseTransaction(boolean useTransaction)
Sets transaction use.
|
public AbstractLazySelector()
setUseTransaction(boolean)
is true by default.public AbstractLazySelector(R source)
setUseTransaction(boolean)
is true by default.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 relationshipprotected abstract void openDatabase() throws LazyCascadeException
checkLazySelects(String)
to create a Database
instance that will be used to
perform the lazy selects.LazyCascadeException
- if errorprotected abstract void closeDatabase() throws LazyCascadeException
checkLazySelects(String)
to close the Database
instance that
was used to perform the lazy selects.LazyCascadeException
- if errorpublic R getSource()
public boolean isUseTransaction()
public void setUseTransaction(boolean useTransaction)
Database.getTransaction()
reports false from Transaction.isActive()
,
meaning no transaction is active, then this class will create a transaction with begin()
prior to performing the lazy
selects.useTransaction
- true to create a transaction for lazy select if none is active; false to never
create a transactionbegin()
,
commit()
,
rollback()
public boolean isLocalTransaction()
public Database getDatabase()
public void setDatabase(Database database)
database
- lazy select database (typically created in openDatabase()
public boolean isPendingLazySelects()
pendingLazySelects(Database)
is invoked. Set to false when checkLazySelects(String)
determines that
there are no more fields to select.public java.util.Map<java.lang.String,java.lang.reflect.Field> getPendingLazySelectFields()
checkLazySelects(String)
is invoked while isPendingLazySelects()
is true.public void pendingLazySelects(Database database) throws LazyCascadeException
checkLazySelects(String)
to perform the lazy select.pendingLazySelects
in interface LazySelectable
database
- perform lazy selects from this databaseLazyCascadeException
- if errorpublic void checkLazySelects(java.lang.String fieldName) throws LazyCascadeException
lazySelect(Field)
will be invoked to
select the field. A field is selected only once.checkLazySelects
in interface LazySelectable
fieldName
- name of field to select with lazy selectLazyCascadeException
- if errorprotected void lazySelect(java.lang.reflect.Field field) throws LazyCascadeException
SelectCascade.lazy()
is
true.field
- field to affectLazyCascadeException
- if errorprotected void initPendingLazySelectCascadeFields() throws LazyCascadeException
getPendingLazySelectFields()
.LazyCascadeException
- if errorprotected void begin() throws SormulaException
lazySelect(Field)
. A transaction is used only if isUseTransaction()
is
true and the transaction for database is not already in use.SormulaException
- if errorprotected void commit() throws SormulaException
lazySelect(Field)
. A transaction is committed only
if begin()
started a transaction as indicated by true from isLocalTransaction()
.SormulaException
- if errorprotected void rollback() throws SormulaException
lazySelect(Field)
. A transaction is rolled back only
if begin()
started a transaction as indicated by true from isLocalTransaction()
.SormulaException
- if error