R
- record typepublic abstract class ActiveRecord<R extends ActiveRecord<? super R>> extends java.lang.Object implements LazySelectable, java.io.Serializable
table(Class)
for an example how to add
a static member named table to the subclass that extends ActiveRecord.
Since 4.1, related cascades are performed in batch mode for batch operations.
Constructor and Description |
---|
ActiveRecord()
Constructs.
|
Modifier and Type | Method and Description |
---|---|
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.
|
int |
deleteBatch()
Deletes record from database in batch mode.
|
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.
|
int |
insertBatch()
Inserts record into database in batch mode.
|
void |
pendingLazySelects(Database database)
Informs a lazy selector that there are lazy selects to be performed.
|
int |
save()
Saves record into database.
|
int |
saveBatch()
Saves record into database in batch mode.
|
static <R extends ActiveRecord<? super R>> |
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.
|
int |
updateBatch()
Updates record in database in batch mode.
|
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<? super 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();
R
- record typerecordClass
- type of records of tableActiveException
- 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 saveBatch() throws ActiveException
ActiveTable.saveBatch(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 insertBatch() throws ActiveException
ActiveTable.insertBatch(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 updateBatch() throws ActiveException
ActiveTable.updateBatch(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 int deleteBatch() throws ActiveException
ActiveTable.deleteBatch(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 selectActiveException
- 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