state of the objects
Persistent object read from file are attached to the data access
session and the to the file persistence.
JOAFIP defines and supports the following object states:
-
Transient
- an object is
transient if it has just been instantiated using the new
operator, and it has no persistent
representation in the file. Transient instances will be destroyed by
the garbage collector if the application doesn't hold a reference
anymore.
- To be
persisted
- an object have its state when it is newly referenced by an object
having persistent state or to be persisted state, also when add to
persitent objet pool ( IDataAccessSession#setObject )
-
Persistent
- a persistent
instance has a representation in the file. It has been loaded. JOAFIP
will detect any changes made to an object
in
persistent state and synchronize the state with the file when saving.
-
Detached
- a detached
instance is an object that has been persistent, but close
done ( saving or not ). The reference to the object is
still valid, of course, but not usable since detached from data access
session.
Making transient objects persistent, assuming
"IDataAccessSession
dataAccessSession=filePersistence.createDataAccessSession()"
- dataAccessSession.open()
- MyClass myEntity=new
MyClas(....)
- IDataAccessSession.setObject(key,myEntity)
- dataAccessSession.close(EnumFilePersistenceCloseAction.SAVE),
- dataAccessSession.open()
- MyRootClass root=dataAccessSession.getObject(key)
- MyClass myEntity=new
MyClas(....)
- root.set(myEntity),
supposing set method make root object referencing myEntity object.
- dataAccessSession.close(EnumFilePersistenceCloseAction.SAVE),
Loading a object
- IDataAccessSession.open()
- by getting a root
object
using MyRootClass root=dataAccessSession.getObject(key)
- getting object in
relation with root, like MyClass myEntity=root.get(...)
- dataAccessSession.close( save or not )
Below the object persistent
state transition diagram:
This work is licensed under a Creative Commons Attribution 3.0 Unported License.
© 2007-2012, joafip