public class ObjectContainerSession extends java.lang.Object implements InternalObjectContainer, TransientClass, ObjectContainerSpec
| Modifier and Type | Field and Description |
|---|---|
protected ObjectContainerBase |
_server |
protected Transaction |
_transaction |
| Constructor and Description |
|---|
ObjectContainerSession(ObjectContainerBase server) |
ObjectContainerSession(ObjectContainerBase server,
Transaction trans) |
| Modifier and Type | Method and Description |
|---|---|
void |
activate(java.lang.Object obj)
activates an object with the current activation strategy.
|
void |
activate(java.lang.Object obj,
int depth)
activates all members on a stored object to the specified depth.
|
void |
backup(Storage storage,
java.lang.String path)
backs up a database file of an open ObjectContainer.
|
void |
backup(java.lang.String path)
backs up a database file of an open ObjectContainer.
|
void |
bind(java.lang.Object obj,
long id)
binds an object to an internal object ID.
|
Callbacks |
callbacks() |
void |
callbacks(Callbacks cb) |
ClassMetadata |
classMetadataForID(int id) |
ClassMetadata |
classMetadataForName(java.lang.String name) |
ClassMetadata |
classMetadataForReflectClass(ReflectClass reflectClass) |
boolean |
close()
closes the
ObjectContainer. |
void |
commit()
commits the running transaction.
|
Config4Impl |
configImpl() |
Configuration |
configure()
returns the Configuration context for this ObjectContainer.
|
ObjectContainerBase |
container() |
void |
deactivate(java.lang.Object obj)
deactivates an object.
|
void |
deactivate(java.lang.Object obj,
int depth)
deactivates a stored object by setting all members to
NULL. |
void |
delete(java.lang.Object obj)
deletes a stored object permanently.
|
java.lang.Object |
descend(java.lang.Object obj,
java.lang.String[] path)
returns a member at the specific path without activating intermediate objects.
|
ExtObjectContainer |
ext()
returns an ObjectContainer with extended functionality.
|
<T> QLin<T> |
from(java.lang.Class<T> clazz) |
java.lang.Object |
getByID(long id)
returns the stored object for an internal ID.
|
java.lang.Object |
getByUUID(Db4oUUID uuid)
returns a stored object for a
Db4oUUID. |
long |
getID(java.lang.Object obj)
returns the internal unique object ID.
|
NativeQueryHandler |
getNativeQueryHandler() |
ObjectInfo |
getObjectInfo(java.lang.Object obj)
returns the
ObjectInfo for a stored object. |
HandlerRegistry |
handlers() |
Db4oDatabase |
identity()
returns the Db4oDatabase object for this ObjectContainer.
|
int |
instanceCount(ClassMetadata clazz,
Transaction trans) |
boolean |
isActive(java.lang.Object obj)
tests if an object is activated.
|
boolean |
isCached(long id)
tests if an object with this ID is currently cached.
|
boolean |
isClient() |
boolean |
isClosed()
tests if this
ObjectContainer is closed. |
boolean |
isStored(java.lang.Object obj)
tests if an object is stored in this
ObjectContainer. |
ReflectClass[] |
knownClasses()
returns all class representations that are known to this
ObjectContainer because they have been used or stored.
|
java.lang.Object |
lock()
returns the main synchronization lock.
|
EventRegistryImpl |
newEventRegistry() |
ObjectContainer |
openSession()
opens a new ObjectContainer on top of this ObjectContainer.
|
java.lang.Object |
peekPersisted(java.lang.Object object,
int depth,
boolean committed)
returns a transient copy of a persistent object with all members set
to the values that are currently stored to the database.
|
void |
purge()
unloads all clean indices from memory and frees unused objects.
|
void |
purge(java.lang.Object obj)
unloads a specific object from the db4o reference mechanism.
|
Query |
query()
creates a new S.O.D.A.
|
ObjectSet |
query(java.lang.Class clazz)
queries for all instances of a class.
|
ObjectSet |
query(Predicate predicate)
Native Query Interface.
|
<T> ObjectSet<T> |
query(Predicate<T> predicate,
QueryComparator<T> comparator)
Native Query Interface.
|
ObjectSet |
query(Predicate predicate,
java.util.Comparator comparator)
Native Query Interface.
|
ObjectSet |
queryByExample(java.lang.Object template)
Query-By-Example interface to retrieve objects.
|
GenericReflector |
reflector()
Return the reflector currently being used by db4objects.
|
void |
refresh(java.lang.Object obj,
int depth)
refreshs all members on a stored object to the specified depth.
|
void |
releaseSemaphore(java.lang.String name)
releases a semaphore, if the calling transaction is the owner.
|
void |
rollback()
rolls back the running transaction.
|
boolean |
setSemaphore(java.lang.String name,
int waitForAvailability)
attempts to set a semaphore.
|
void |
store(java.lang.Object obj)
newly stores objects or updates stored objects.
|
void |
store(java.lang.Object obj,
int depth)
deep update interface to store or update objects.
|
void |
storeAll(Transaction transaction,
Iterator4 objects) |
StoredClass |
storedClass(java.lang.Object clazz)
returns a
StoredClass meta information object. |
StoredClass[] |
storedClasses()
returns an array of all
StoredClass meta information objects. |
java.lang.Object |
syncExec(Closure4 block) |
SystemInfo |
systemInfo()
returns the
SystemInfo for this ObjectContainer. |
Transaction |
transaction() |
UpdateDepthProvider |
updateDepthProvider() |
long |
version()
returns the current transaction serial number.
|
protected final ObjectContainerBase _server
protected final Transaction _transaction
public ObjectContainerSession(ObjectContainerBase server, Transaction trans)
public ObjectContainerSession(ObjectContainerBase server)
public void backup(java.lang.String path)
throws Db4oIOException,
DatabaseClosedException,
NotSupportedException
ExtObjectContainerStorage used for backup is the one configured for this container.backup in interface ExtObjectContainerpath - Db4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.NotSupportedException - is thrown when the operation is not supported in current
configuration/environmentpublic void backup(Storage storage, java.lang.String path) throws Db4oIOException, DatabaseClosedException, NotSupportedException
ExtObjectContainerbackup in interface ExtObjectContainerstorage - the Storage to be used for backuppath - a fully qualified pathDb4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.NotSupportedException - is thrown when the operation is not supported in current
configuration/environmentpublic void bind(java.lang.Object obj,
long id)
throws InvalidIDException,
DatabaseClosedException
ExtObjectContainerset(Object) is
necessary to update the stored object.getID(Object).bind in interface ExtObjectContainerobj - the object that is to be boundid - the internal id the object is to be bound toInvalidIDException - when the provided id is outside the scope of the
database IDs.DatabaseClosedException - db4o database file was closed or failed to open.ExtObjectContainer.getID(java.lang.Object)public Config4Impl configImpl()
configImpl in interface InternalObjectContainerpublic Configuration configure()
ExtObjectContainerDb4o class, the global
Configuration context
is copied into the ObjectContainer. The
Configuration
can be modified individually for
each ObjectContainer without any effects on the global settings.configure in interface ExtObjectContainerConfiguration the Configuration
context for this ObjectContainerDb4o.configure()public java.lang.Object descend(java.lang.Object obj,
java.lang.String[] path)
ExtObjectContainerdescend in interface ExtObjectContainerobj - the parent object that is to be used as the starting point.path - an array of field names to navigate bypublic java.lang.Object getByID(long id)
throws DatabaseClosedException,
InvalidIDException
ExtObjectContainergetID(Object).
Objects will not be activated by this method. They will be returned in the
activation state they are currently in, in the local cache.getByID in interface ExtObjectContainerid - the internal IDnull,
if no object is associated with this ID in this ObjectContainer.DatabaseClosedException - db4o database file was closed or failed to open.InvalidIDException - when the provided id is outside the scope of the
file length.Why activation?public java.lang.Object getByUUID(Db4oUUID uuid) throws DatabaseClosedException, Db4oIOException
ExtObjectContainerDb4oUUID.
Db4oUUID for an
object use ExtObjectContainer.getObjectInfo(Object) and ObjectInfo.getUUID().getByUUID in interface ExtObjectContaineruuid - the UUIDDatabaseClosedException - db4o database file was closed or failed to open.Db4oIOException - I/O operation failed or was unexpectedly interrupted.Why activation?public long getID(java.lang.Object obj)
ExtObjectContainerObjectContainer.
An object carries the same ID in every db4o session. Internal IDs can
be used to look up objects with the very fast
getByID method.ExtObjectContainer.getObjectInfo(Object), ObjectInfo.getUUID() and
ExtObjectContainer.getByUUID(Db4oUUID) for long-term external references to
objects.getID in interface ExtObjectContainerobj - any object0, if the passed
object is not stored in this ObjectContainer.public ObjectInfo getObjectInfo(java.lang.Object obj)
ExtObjectContainerObjectInfo for a stored object.
ObjectContainer.getObjectInfo in interface ExtObjectContainerobj - the stored objectObjectInfopublic Db4oDatabase identity()
ExtObjectContaineridentity in interface ExtObjectContainerpublic boolean isActive(java.lang.Object obj)
ExtObjectContainerisActive returns false if an object is not
stored within the ObjectContainer.isActive in interface ExtObjectContainerobj - to be testedtrue if the passed object is active.public boolean isCached(long id)
ExtObjectContainerisCached in interface ExtObjectContainerid - the internal IDpublic boolean isClosed()
ExtObjectContainerObjectContainer is closed.
isClosed in interface ExtObjectContainertrue if this ObjectContainer is closed.public boolean isStored(java.lang.Object obj)
throws DatabaseClosedException
ExtObjectContainerObjectContainer.
isStored in interface ExtObjectContainerobj - to be testedtrue if the passed object is stored.DatabaseClosedException - db4o database file was closed or failed to open.public ReflectClass[] knownClasses()
ExtObjectContainerknownClasses in interface ExtObjectContainerpublic java.lang.Object lock()
ExtObjectContainerlock in interface ExtObjectContainerpublic java.lang.Object peekPersisted(java.lang.Object object,
int depth,
boolean committed)
ExtObjectContainercommitted parameter it is possible to specify,
whether the desired object should contain the committed values or the
values that were set by the running transaction with
ObjectContainer.store(java.lang.Object).
peekPersisted in interface ExtObjectContainerobject - the object that is to be cloneddepth - the member depth to which the object is to be instantiatedcommitted - whether committed or set values are to be returnedpublic void purge()
ExtObjectContainerpurge in interface ExtObjectContainerpublic void purge(java.lang.Object obj)
ExtObjectContainerpurge(Object) is not
"known" to the ObjectContainer afterwards, so this method may also be
used to create multiple copies of objects.purge(Object) has
no influence on the persistence state of objects. "Purged" objects can be
reretrieved with queries.purge in interface ExtObjectContainerobj - the object to be removed from the reference mechanism.public GenericReflector reflector()
ExtObjectContainerreflector in interface ExtObjectContainerpublic void refresh(java.lang.Object obj,
int depth)
ExtObjectContainerrefresh in interface ExtObjectContainerobj - the object to be refreshed.depth - the member depth
to which refresh is to cascade.public void releaseSemaphore(java.lang.String name)
ExtObjectContainerreleaseSemaphore in interface ExtObjectContainername - the name of the semaphore to be released.public void store(java.lang.Object obj,
int depth)
ExtObjectContainerObjectContainer#set(Object),
this method allows a manual specification of the depth, the passed object is to be updated.store in interface ExtObjectContainerobj - the object to be stored or updated.depth - the depth to which the object is to be updatedcom.db4o.ObjectContainer#setpublic boolean setSemaphore(java.lang.String name,
int waitForAvailability)
ExtObjectContainerObjectContainers.
ExtObjectContainer.releaseSemaphore(java.lang.String)ObjectContainer.close()ObjectServer is
closed.ObjectContainer looses the connection and is timed
out.ObjectContainer.commit() or ObjectContainer.rollback().getID(Object)setSemaphore in interface ExtObjectContainername - the name of the semaphore to be setwaitForAvailability - the time in milliseconds to wait for other
transactions to release the semaphore. The parameter may be zero, if
the method is to return immediately.true, if the semaphore could be set or if the
calling transaction already owned the semaphore.
false, if the semaphore is owned by another
transaction.public StoredClass storedClass(java.lang.Object clazz)
ExtObjectContainerStoredClass meta information object.
storedClass in interface ExtObjectContainerclazz - class name, Class object, or example object.StoredClass meta information object.public StoredClass[] storedClasses()
ExtObjectContainerStoredClass meta information objects.storedClasses in interface ExtObjectContainerpublic SystemInfo systemInfo()
ExtObjectContainerSystemInfo for this ObjectContainer.
SystemInfo supplies methods that provide
information about system state and system settings of this
ObjectContainer.systemInfo in interface ExtObjectContainerSystemInfo for this ObjectContainer.public long version()
ExtObjectContainerversion in interface ExtObjectContainerpublic void activate(java.lang.Object obj)
throws Db4oIOException,
DatabaseClosedException
ExtObjectContainerConfiguration.activationDepth() )
and all configured settings for ObjectClass.maximumActivationDepth(int)
and ObjectClass.maximumActivationDepth(int) will be respected.TransparentActivationSupport )
the parameter object will only be activated, if it does not implement
Activatable. All referenced members that do not implement
Activatable will also be activated. Any Activatable objects
along the referenced graph will break cascading activation.activate in interface ExtObjectContainerDb4oIOExceptionDatabaseClosedExceptionpublic void activate(java.lang.Object obj,
int depth)
throws Db4oIOException,
DatabaseClosedException
ObjectContainer"Why activation"
for an explanation why activation is necessary.maximumActivationDepth() and
minimumActivationDepth() in the
ObjectClass interface.activate in interface ObjectContainerobj - the object to be activated.depth - the member depth
to which activate is to cascade.Db4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.Why activation?,
Using callbackspublic boolean close()
throws Db4oIOException
ObjectContainerObjectContainer.
close() automatically performs a
commit().
while(!close()){} to kill all sessions using this container.close in interface ObjectContainerDb4oIOException - I/O operation failed or was unexpectedly interrupted.public void commit()
throws Db4oIOException,
DatabaseClosedException,
DatabaseReadOnlyException,
UniqueFieldValueConstraintViolationException
ObjectContainercommit in interface ObjectContainerDb4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.DatabaseReadOnlyException - database was configured as read-only.UniqueFieldValueConstraintViolationExceptionpublic void deactivate(java.lang.Object obj,
int depth)
throws DatabaseClosedException
ObjectContainerNULL.
ObjectContainer.deactivate() triggers Deactivating and Deactivated callbacks.
deactivate in interface ObjectContainerobj - the object to be deactivated.depth - the member depth
to which deactivate is to cascade.DatabaseClosedException - db4o database file was closed or failed to open.Using callbacks,
Why activation?public void deactivate(java.lang.Object obj)
throws DatabaseClosedException
ExtObjectContainerdeactivate in interface ExtObjectContainerobj - the object to be deactivated.DatabaseClosedExceptionpublic void delete(java.lang.Object obj)
throws Db4oIOException,
DatabaseClosedException,
DatabaseReadOnlyException
ObjectContainerconfigured for the class
or for one of the member fields.
ObjectContainer.
set() with the same object newly stores the object
to the ObjectContainer.delete() triggers Deleting and Deleted callbacks,
which can be also used for cascaded deletes.delete in interface ObjectContainerobj - the object to be deleted from the
ObjectContainer.Db4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.DatabaseReadOnlyException - database was configured as read-only.ObjectClass.cascadeOnDelete(boolean),
ObjectField.cascadeOnDelete(boolean),
Using callbackspublic ExtObjectContainer ext()
ObjectContainerext in interface ObjectContainerpublic ObjectSet queryByExample(java.lang.Object template) throws Db4oIOException, DatabaseClosedException
ObjectContainerqueryByExample() creates an
ObjectSet containing
all objects in the ObjectContainer that match the passed
template object.queryByExample(NULL) returns all objects stored in the
ObjectContainer.Collection classes are
evaluated for containment. Differences in length/size() are
ignored.
ObjectSet are instantiated
and activated to the preconfigured depth of 5. The
activation depth
may be configured globally or
individually for classes.
queryByExample() can respond to the Activating callback
method.
queryByExample in interface ObjectContainertemplate - object to be used as an example to find all matching objects.ObjectSet containing all found objects.Db4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.Why activation?,
Using callbackspublic Query query() throws DatabaseClosedException
ObjectContainerQuery.
ObjectContainer.queryByExample(Object) for simple Query-By-Example.Native queries are the recommended main db4o query
interface.
query in interface ObjectContainerDatabaseClosedException - db4o database file was closed or failed to open.public ObjectSet query(java.lang.Class clazz) throws Db4oIOException, DatabaseClosedException
ObjectContainerquery in interface ObjectContainerclazz - the class to query for.ObjectSet returned by the query.Db4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.public ObjectSet query(Predicate predicate) throws Db4oIOException, DatabaseClosedException
ObjectContainer
// Java JDK 5
List <Cat> cats = db.query(new Predicate<Cat>() {
public boolean match(Cat cat) {
return cat.getName().equals("Occam");
}
});
// Java JDK 1.2 to 1.4
List cats = db.query(new Predicate() {
public boolean match(Cat cat) {
return cat.getName().equals("Occam");
}
});
// Java JDK 1.1
ObjectSet cats = db.query(new CatOccam());
public static class CatOccam extends Predicate {
public boolean match(Cat cat) {
return cat.getName().equals("Occam");
}
});
query in interface ObjectContainerpredicate - the Predicate containing the native query expression.ObjectSet returned by the query.Db4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.public <T> ObjectSet<T> query(Predicate<T> predicate, QueryComparator<T> comparator) throws Db4oIOException, DatabaseClosedException
ObjectContainerObjectContainer.query(com.db4o.query.Predicate),
but will sort the resulting ObjectSet according to the given QueryComparator.query in interface ObjectContainerpredicate - the Predicate containing the native query expression.comparator - the QueryComparator specifying the sort order of the resultObjectSet returned by the query.Db4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.public void rollback()
throws Db4oIOException,
DatabaseClosedException,
DatabaseReadOnlyException
ObjectContainerdeactivate()
and activate() to reload an objects member values.rollback in interface ObjectContainerDb4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.DatabaseReadOnlyException - database was configured as read-only.public void store(java.lang.Object obj)
throws DatabaseClosedException,
DatabaseReadOnlyException
ObjectContainerObjectContainer will be
stored when it is passed to store(). An object already stored
in the ObjectContainer will be updated.
store() unless a deep
global or
class-specific
update depth was configured or cascaded updates were
defined in the class
or in one of the member fields.
Depending if the passed object is newly stored or updated, Creating/Created
or Updating/Updated callback method is triggered.
Callbacks
might also be used for cascaded updates.store in interface ObjectContainerobj - the object to be stored or updated.DatabaseClosedException - db4o database file was closed or failed to open.DatabaseReadOnlyException - database was configured as read-only.ExtObjectContainer#set(object, depth),
Configuration.updateDepth(int),
ObjectClass.updateDepth(int),
ObjectClass.cascadeOnUpdate(boolean),
ObjectField.cascadeOnUpdate(boolean),
Using callbackspublic ObjectContainerBase container()
container in interface InternalObjectContainerpublic Transaction transaction()
transaction in interface InternalObjectContainerpublic void callbacks(Callbacks cb)
callbacks in interface InternalObjectContainerpublic Callbacks callbacks()
callbacks in interface InternalObjectContainerpublic final NativeQueryHandler getNativeQueryHandler()
getNativeQueryHandler in interface InternalObjectContainerpublic ClassMetadata classMetadataForReflectClass(ReflectClass reflectClass)
classMetadataForReflectClass in interface InternalObjectContainerpublic ClassMetadata classMetadataForName(java.lang.String name)
classMetadataForName in interface InternalObjectContainerpublic ClassMetadata classMetadataForID(int id)
classMetadataForID in interface InternalObjectContainerpublic HandlerRegistry handlers()
handlers in interface InternalObjectContainerpublic java.lang.Object syncExec(Closure4 block)
syncExec in interface InternalObjectContainerpublic int instanceCount(ClassMetadata clazz, Transaction trans)
instanceCount in interface InternalObjectContainerpublic ObjectSet query(Predicate predicate, java.util.Comparator comparator) throws Db4oIOException, DatabaseClosedException
ObjectContainerObjectContainer.query(com.db4o.query.Predicate),
but will sort the resulting ObjectSet according to the given Comparator.query in interface ObjectContainerpredicate - the Predicate containing the native query expression.comparator - the java.util.Comparator specifying the sort order of the resultObjectSet returned by the query.Db4oIOException - I/O operation failed or was unexpectedly interrupted.DatabaseClosedException - db4o database file was closed or failed to open.public boolean isClient()
isClient in interface InternalObjectContainerpublic void storeAll(Transaction transaction, Iterator4 objects)
storeAll in interface InternalObjectContainerpublic UpdateDepthProvider updateDepthProvider()
updateDepthProvider in interface InternalObjectContainerpublic ObjectContainer openSession()
ExtObjectContaineropenSession in interface ExtObjectContainerpublic EventRegistryImpl newEventRegistry()
newEventRegistry in interface InternalObjectContainerpublic <T> QLin<T> from(java.lang.Class<T> clazz)