|
db4o 6.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ObjectContainer
the interface to a db4o database, stand-alone or client/server.
The ObjectContainer interface provides methods
to store, query and delete objects and to commit and rollback
transactions.
An ObjectContainer can either represent a stand-alone database
or a connection to a db4o server
.
An ObjectContainer also represents a transaction. All work
with db4o always is transactional. Both commit()
and
rollback()
start new transactions immediately. For working
against the same database with multiple transactions, open a db4o server
with Db4o.openServer(String, int)
and
connect locally
or
over TCP
.
ExtObjectContainer for extended functionality.
Method Summary | ||
---|---|---|
void |
activate(java.lang.Object obj,
int depth)
activates all members on a stored object to the specified depth. |
|
boolean |
close()
closes the ObjectContainer . |
|
void |
commit()
commits the running transaction. |
|
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. |
|
ExtObjectContainer |
ext()
returns an ObjectContainer with extended functionality. |
|
|
get(java.lang.Object template)
Query-By-Example interface to retrieve objects. |
|
Query |
query()
creates a new S.O.D.A. |
|
|
query(java.lang.Class<TargetType> clazz)
queries for all instances of a class. |
|
|
query(Predicate<TargetType> predicate)
Native Query Interface. |
|
|
query(Predicate<TargetType> predicate,
java.util.Comparator<TargetType> comparator)
Native Query Interface. |
|
|
query(Predicate<TargetType> predicate,
QueryComparator<TargetType> comparator)
Native Query Interface. |
|
void |
rollback()
rolls back the running transaction. |
|
void |
set(java.lang.Object obj)
newly stores objects or updates stored objects. |
Method Detail |
---|
void activate(java.lang.Object obj, int depth)
"Why activation"
for an explanation why activation is necessary.maximumActivationDepth()
and
minimumActivationDepth()
in the
ObjectClass interface
.objectOnActivate
which can be used for cascaded activation.
obj
- the object to be activated.depth
- the member depth
to which activate is to cascade.Why activation?
,
Using callbacks
boolean close()
ObjectContainer
.
close()
automatically performs a
commit()
.
while(!close()){}
to kill all sessions using this container.
void commit()
void deactivate(java.lang.Object obj, int depth)
NULL
.
ObjectContainer
.deactivate()
triggers the callback method
objectOnDeactivate
.
obj
- the object to be deactivated.depth
- the member depth
to which deactivate is to cascade.Using callbacks
,
Why activation?
void delete(java.lang.Object obj)
configured 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 the callback method
objectOnDelete
which can be also used for cascaded deletes.
obj
- the object to be deleted from the
ObjectContainer
.ObjectClass.cascadeOnDelete(boolean)
,
ObjectField.cascadeOnDelete(boolean)
,
Using callbacks
ExtObjectContainer ext()
<T> ObjectSet<T> get(java.lang.Object template)
get()
creates an
ObjectSet
containing
all objects in the ObjectContainer
that match the passed
template object.get(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
.
get()
can respond to the callback
method objectOnActivate
.
template
- object to be used as an example to find all matching objects.ObjectSet
containing all found objects.Why activation?
,
Using callbacks
Query query()
Query
.
get(Object template)
for simple Query-By-Example.Native queries
are the recommended main db4o query
interface.
<TargetType> ObjectSet<TargetType> query(java.lang.Class<TargetType> clazz)
clazz
- the class to query for.
ObjectSet
returned by the query.<TargetType> ObjectSet<TargetType> query(Predicate<TargetType> predicate)
// C# .NET 2.0
IList <Cat> cats = db.Query <Cat> (delegate(Cat cat) {
return cat.Name == "Occam";
});
// 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");
}
});
// C# .NET 1.1
IList cats = db.Query(new CatOccam());
public class CatOccam : Predicate {
public boolean Match(Cat cat) {
return cat.Name == "Occam";
}
});
predicate
- the Predicate
containing the native query expression.
ObjectSet
returned by the query.<TargetType> ObjectSet<TargetType> query(Predicate<TargetType> predicate, QueryComparator<TargetType> comparator)
query(com.db4o.query.Predicate)
,
but will sort the resulting ObjectSet
according to the given QueryComparator
.
predicate
- the Predicate
containing the native query expression.comparator
- the QueryComparator
specifiying the sort order of the result
ObjectSet
returned by the query.<TargetType> ObjectSet<TargetType> query(Predicate<TargetType> predicate, java.util.Comparator<TargetType> comparator)
query(com.db4o.query.Predicate)
,
but will sort the resulting ObjectSet
according to the given com.db4o.query.Comparator
.
predicate
- the Predicate
containing the native query expression.comparator
- the Comparator
specifiying the sort order of the result
ObjectSet
returned by the query.void rollback()
deactivate()
and activate()
to reload an objects member values.
void set(java.lang.Object obj)
ObjectContainer
will be
stored when it is passed to set()
. An object already stored
in the ObjectContainer
will be updated.
set()
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
.
objectOnNew
or
objectOnUpdate
is triggered.
objectOnUpdate
might also be used for cascaded updates.
obj
- the object to be stored or updated.ExtObjectContainer#set(object, depth)
,
Configuration.updateDepth(int)
,
ObjectClass.updateDepth(int)
,
ObjectClass.cascadeOnUpdate(boolean)
,
ObjectField.cascadeOnUpdate(boolean)
,
Using callbacks
|
db4o 6.1 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |