See: Description
Class | Description |
---|---|
ActiveDatabase |
A lightweight class for defining the
DataSource to be used by ActiveRecord
and related classes. |
ActiveRecord<R extends ActiveRecord<? super R>> |
Base class for active records.
|
ActiveTable<R extends ActiveRecord<? super R>> |
Performs all database operations for
ActiveRecord objects. |
ActiveTransaction |
A class to group multiple active record operations within one JDBC transaction.
|
Exception | Description |
---|---|
ActiveException |
Exception that originates in the activerecord package.
|
NoDefaultActiveDatabaseException |
Indicates there is no active database defined but default was expected with
ActiveDatabase.getDefault() . |
ActiveRecord
objects know about their ActiveDatabase
so they may be inserted, updated, deleted by simply calling the inherited methods
ActiveRecord.save()
, ActiveRecord.insert()
,
ActiveRecord.update()
, and ActiveRecord.delete()
. An
active record may also be processed by analogous methods in ActiveTable
,
ActiveTable.save(ActiveRecord)
,
ActiveTable.insert(ActiveRecord)
,
ActiveTable.update(ActiveRecord)
,
ActiveTable.delete(ActiveRecord)
.
ActiveTable
can find active records and operate upon a Collection
of active records.
For example:
For all active record and active table methods that modify the database, if no// get part by primary key Inventory inventory = Inventory.table.select(partNumber); // update inventory.setQuantity(inventory.getQuantity() - 42); inventory.update();
ActiveTransaction
is used and the connection obtained from
DataSource
has autocommit turned off, then an ActiveTransaction
will be created for the duration of each active record method. Therefore you can use the active
record methods with or without an ActiveTransaction
. However it is
probably better to group related active record methods into a single ActiveTransaction
.
For example:
ActiveTransaction transaction = new ActiveTransaction(new ActiveDatabase(dataSource)); try { transaction.begin(); // get part by primary key Inventory inventory = Inventory.table.select(partNumber); // update inventory.setQuantity(inventory.getQuantity() - 42); inventory.update(); transaction.commit(); } catch (ActiveException e) { transaction.rollback(); }