|
db4o 8.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Activatable
Activatable must be implemented by classes in order to support Transparent
Activation.
The Activatable interface may be added to persistent classes by hand or by
using the db4o enhancer. For further information on the enhancer see the
chapter "Enhancement" in the db4o tutorial.
The basic idea for Transparent Activation is as follows:
Objects have an activation depth of 0, i.e. by default they are not activated
at all. Whenever a method is called on such an object, the first thing to do
before actually executing the method body is to activate the object to level
1, i.e. populating its direct members.
To illustrate this approach, we will use the following simple class.
public class Item {
The basic sequence of actions to get the above scheme to work is the
following:
private Item _next;
public Item(Item next) {
_next = next;
}
public Item next() {
return _next;
}
}
- Whenever an object is instantiated from db4o, the database registers an
activator for this object. To enable this, the object has to implement the
Activatable interface and provide the according bind(Activator) method. The
default implementation of the bind method will simply store the given
activator reference for later use.
public class Item implements Activatable {
- The first action in every method body of an activatable object should be a
call to the corresponding Activator's activate() method. (Note that this is
not enforced by any interface, it is rather a convention, and other
implementations are possible.)
transient Activator _activator;
public void bind(Activator activator) {
if (null != _activator) {
throw new IllegalStateException();
}
_activator = activator;
}
// ...
}
public class Item implements Activatable {
- The activate() method will check whether the object is already activated.
If this is not the case, it will request the container to activate the object
to level 1 and set the activated flag accordingly.
public void activate() {
if (_activator == null) return;
_activator.activate();
}
public Item next() {
activate();
return _next;
}
}
To instruct db4o to actually use these hooks (i.e. to register the database
when instantiating an object), TransparentActivationSupport has to be
registered with the db4o configuration.
Configuration config = ...
Java: If you implement this interface manually and intend to pass this class through
the db4o bytecode instrumentation process, make sure you also implement the
config.add(new TransparentActivationSupport());
ActivatableInstrumented
marker interface.
Method Summary | |
---|---|
void |
activate(ActivationPurpose purpose)
should be called by every reading field access of an object. |
void |
bind(Activator activator)
called by db4o upon instantiation. |
Method Detail |
---|
void bind(Activator activator)
Activator
in a transient field of the object.
activator
- the Activatorvoid activate(ActivationPurpose purpose)
Activator.activate(ActivationPurpose)
on the Activator
that was previously passed to bind(Activator)
.
purpose
- TODO
|
db4o 8.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |