Transparent Persistence Implementation
The basic logic of Transparent Persistence (TP) is the
following:
- classes
available for Transparent Persistence should implement Activatable
interface, which allows to bind an object in the reference cache to the
current object container.
- persistent
object should be initially explicitly stored to the database:
.NET:
objectContainer.Store(myObject)
myObject can be an object of any complexity including a linked list or a
collection (currently you must use db4o-specific implementation for transparent collections: ArrayList4). For complex objects all field objects will be registered with
the database with this call as well. - Stored
object are bound to the Transparent Persistent framework when they are
instantiated in the reference cache. This happens after the initial
store() or when an object is retrieved from the database through one of
the querying mechanisms.
- Whenever
a commit() call is issued by the user, TP framework scans for modified
persistent objects and implicitly calls store() on them before committing
the transaction. Implicit commit with the mentioned above changes also occurs when the database is closed.
Note that Transparent Persistence is based on Transparent
Activation, so it is strongly recommended to study Transparent Activation
documentation first.
In order to make use of Transparent Persistence you will
need:
- Enable
Transparent Activation (required for binding object instances to the TP
framework) on the database level:
.NET:
configuration.Add(new TransparentPersistenceSupport());
- Implement
Activatable/IActivatable interface for the persistent classes, either
manually or through using enhancement tools.
- Call
activate method at the beginning of all class methods that modify class
fields:
.NET
Activate(ActivationPurpose.Write)
Note that TransparentPersistenceSupport configuration implicitly adds TransparentActivationSupport. The fact is, that before
modification each field object should be loaded into the reference cache and
that is the job of TA. So TA should be utilised in any case before TP. You can also note that the way TA and TP links into objects is absolutely identical: TP also uses
the same activate
call, but in this case its purpose is WRITE.