Package org.sormula.active

An implementation of the active record pattern built on top of sormula.

See:
          Description

Class Summary
ActiveDatabase A lightweight class for defining the DataSource to be used by ActiveRecord and related classes.
ActiveRecord<R extends ActiveRecord<R>> Base class for active records.
ActiveTable<R extends ActiveRecord<R>> Performs all database operations for ActiveRecord objects.
ActiveTransaction A class to group multiple active record operations within one JDBC transaction.
 

Exception Summary
ActiveException Exception that originates in the activerecord package.
 

Package org.sormula.active Description

An implementation of the active record pattern built on top of sormula. Classes in this package may be used as an independent alternative to other classes in sormula.

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:

   // get part by primary key
   Inventory inventory = Inventory.table.select(partNumber);

   // update
   inventory.setQuantity(inventory.getQuantity() - 42);
   inventory.update();
   
For all active record and active table methods that modify the database, if no 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();
    }