7.2.3. JDK5.0 field level annotations
In Release 1.4, we have added two additional field level annotations for customized behavior. The first one is @org.jboss.cache.aop.annotation.Transient. When applied to a field variable, it has the same effect as the Java language transient keyword. That is, PojoCache won't put this field into cache management (and therefore no replication).
The second one is @org.jboss.cache.aop.annotation.Serializable, when applied to a field varaiable, PojoCache will treat this variable as Serializable, even when it is PojoCacheable. However, the field will need to implement the Serializable interface such that it can be replicated.
Here is a code snippet that illustrates usage of these two annotations. Assuming that you have a Gadget class:
public class Gadget
{
// resource won't be replicated
@Transient Resource resource;
// specialAddress is treated as a Serializable object but still has object relationship
@Serializable SpecialAddress specialAddress;
// other state variables
}
Then when we do:
Gadget gadget = new Gadget();
Resource resource = new Resouce();
SepcialAddress specialAddress = new SpecialAddress();
// setters
gadget.setResource(resource);
gadget.setSpecialAddress(specialAddress);
cache1.putObject("/gadget", gadget); // put into PojoCache management
Gadget g2 = (Gadget)cache2.getObject("/gadget");
// retrieve it from another cache instance
g2.getResource();
// This is should be null becuase of @Transient tag so it is not replicated.
SepcialAddress d2 = g2.getSpecialAddress();
d2.setName("inet");
// This won't get replicated automatically because of @Serializable tag
ge.setSpecialAddress(d2);
// Now this will.