|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sormula.active.ActiveRecord<R>
R
- record typepublic abstract class ActiveRecord<R extends ActiveRecord<R>>
Base class for active records. See table(Class)
for an example how to add
a static member named table to the sublcass that extends ActiveRecord.
Constructor Summary | |
---|---|
ActiveRecord()
Constructs. |
Method Summary | ||
---|---|---|
void |
attach(ActiveDatabase activeDatabase)
Associates an active database with this active record. |
|
void |
checkLazySelects(java.lang.String fieldName)
Selects record(s) from database for field based upon definitions in select annotations of field where SelectCascade.lazy() is true. |
|
protected ActiveTable<R> |
createTable()
Creates an ActiveTable for record class returned by getRecordClass() . |
|
int |
delete()
Deletes record from database. |
|
void |
detach()
Sets active database to null. |
|
ActiveDatabase |
getActiveDatabase()
Gets database set by attach(ActiveDatabase) . |
|
java.lang.Class<R> |
getRecordClass()
Class definition of this record. |
|
int |
insert()
Inserts record into database. |
|
void |
pendingLazySelects(Database database)
Informs a lazy selector that there are lazy selects to be performed. |
|
int |
save()
Saves record into database. |
|
static
|
table(java.lang.Class<R> recordClass)
Creates a table that can be used to for records of type recordClass for the default active database. |
|
int |
update()
Updates record in database. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ActiveRecord()
Method Detail |
---|
public ActiveDatabase getActiveDatabase()
attach(ActiveDatabase)
.
public void attach(ActiveDatabase activeDatabase)
insert()
, save()
,
update()
, and delete()
methods use active database to know what
database to act upon. The method is invoked by ActiveTable
methods insert or modify
table or when an active record is selected as result of a cascade. This method must be
invoked on an active record that was created with new operator prior to using insert()
,
save()
, update()
, and delete()
.
activeDatabase
- the database for this recordpublic void detach()
public static <R extends ActiveRecord<R>> ActiveTable<R> table(java.lang.Class<R> recordClass) throws ActiveException
Use like:public class SomeRecord extends ActiveRecord≶SomeRecord> { private static final long serialVersionUID = 1L; public static final ActiveTable<SomeRecord> table = table(SomeRecord.class); ... }
List<SomeRecord> records = SomeRecord.table.selectAll();
recordClass
- type of records of table
ActiveException
- if errorpublic int save() throws ActiveException
ActiveTable.save(ActiveRecord)
.
The database used is getActiveDatabase()
. If no active database is set for
this record, then the default active database is used, ActiveDatabase.getDefault()
.
ActiveException
- if errorpublic int insert() throws ActiveException
ActiveTable.insert(ActiveRecord)
.
The database used is getActiveDatabase()
. If no active database is set for
this record, then the default active database is used, ActiveDatabase.getDefault()
.
ActiveException
- if errorpublic int update() throws ActiveException
ActiveTable.update(ActiveRecord)
.
The database used is getActiveDatabase()
. If no active database is set for
this record, then the default active database is used, ActiveDatabase.getDefault()
.
ActiveException
- if errorpublic int delete() throws ActiveException
ActiveTable.delete(ActiveRecord)
.
The database used is getActiveDatabase()
. If no active database is set for
this record, then the default active database is used, ActiveDatabase.getDefault()
.
ActiveException
- if errorpublic java.lang.Class<R> getRecordClass()
Object.getClass()
public void checkLazySelects(java.lang.String fieldName) throws ActiveException
SelectCascade.lazy()
is true. Typically this method is invoked by the "get" method
associated with field. For example:
public List<SomeChild> getChildList() { lazySelectCascade("childList"); return childList; }
This method may be invoked more than once per field but the field will only be selected upon
the first invocation. Each time that an active record is selected, all lazy select cascaded
fields are initialized by pendingLazySelects(Database)
. Invoking this method on an
active record that has not been selected (created with new operator) has no affect.
checkLazySelects
in interface LazySelectable
fieldName
- field to select
ActiveException
- if errorpublic void pendingLazySelects(Database database)
ScalarSelectOperation.readNext()
when a least one field has a SelectCascade.lazy()
set to true. Use Table.getLazySelectCascadeFields()
to know which fields are to be lazily selected.
pendingLazySelects
in interface LazySelectable
database
- the database where lazy select fields are to be readprotected ActiveTable<R> createTable() throws ActiveException
ActiveTable
for record class returned by getRecordClass()
.
Default active database is used if none is available for this record.
ActiveException
- if error
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |