| |
|
| com.db4o.ObjectContainer
Method Summary | |
public void | activate(Object obj, int depth) activates all members on a stored object to the specified depth.
See
com.db4o.config.Configuration.activationDepth(int) "Why activation" for an explanation why activation is necessary.
The activate method activates a graph of persistent objects in memory.
Only deactivated objects in the graph will be touched: their
fields will be loaded from the database. | public boolean | close() closes the ObjectContainer . | public void | commit() commits the running transaction.
Transactions are back-to-back. | public void | deactivate(Object obj, int depth) deactivates a stored object by setting all members to NULL .
Primitive types will be set to their default values.
Examples: ../com/db4o/samples/activate.
Calls to this method save memory.
The method has no effect, if the passed object is not stored in the
ObjectContainer .
deactivate() triggers the callback method
com.db4o.ext.ObjectCallbacks.objectOnDeactivate objectOnDeactivate .
Be aware that calling this method with a depth parameter greater than
1 sets members on member objects to null. | public void | delete(Object obj) deletes a stored object permanently.
Note that this method has to be called for every single object
individually. | public ExtObjectContainer | ext() returns an ObjectContainer with extended functionality.
Every ObjectContainer that db4o provides can be casted to
an ExtObjectContainer. | public ObjectSet<T> | get(Object template) Query-By-Example interface to retrieve objects.
get() creates an
ObjectSet ObjectSet containing
all objects in the ObjectContainer that match the passed
template object.
Calling get(NULL) returns all objects stored in the
ObjectContainer .
Query Evaluation
All non-null members of the template object are compared against
all stored objects of the same class.
Primitive type members are ignored if they are 0 or false respectively.
Arrays and all supported Collection classes are
evaluated for containment. | public Query | query() creates a new S.O.D.A. | public ObjectSet<TargetType> | query(Class<TargetType> clazz) queries for all instances of a class.
Parameters: clazz - the class to query for. | public ObjectSet<TargetType> | query(Predicate<TargetType> predicate) Native Query Interface.
Native Queries allow typesafe, compile-time checked and refactorable
querying, following object-oriented principles. | public ObjectSet<TargetType> | query(Predicate<TargetType> predicate, QueryComparator<TargetType> comparator) Native Query Interface. | public ObjectSet<TargetType> | query(Predicate<TargetType> predicate, Comparator<TargetType> comparator) Native Query Interface. | public void | rollback() rolls back the running transaction. | public void | set(Object obj) newly stores objects or updates stored objects.
An object not yet stored in the ObjectContainer will be
stored when it is passed to set() . |
close | public boolean close() throws Db4oIOException(Code) | | closes the ObjectContainer .
A call to close() automatically performs a
ObjectContainer.commit commit() .
Note that every session opened with Db4o.openFile() requires one
close()call, even if the same filename was used multiple times.
Use while(!close()){} to kill all sessions using this container.
success - true denotes that the last used instance of this containerand the database file were closed. throws: Db4oIOException - I/O operation failed or was unexpectedly interrupted. |
ext | public ExtObjectContainer ext()(Code) | | returns an ObjectContainer with extended functionality.
Every ObjectContainer that db4o provides can be casted to
an ExtObjectContainer. This method is supplied for your convenience
to work without a cast.
The ObjectContainer functionality is split to two interfaces
to allow newcomers to focus on the essential methods.
this, casted to ExtObjectContainer |
get | public ObjectSet<T> get(Object template) throws Db4oIOException, DatabaseClosedException(Code) | | Query-By-Example interface to retrieve objects.
get() creates an
ObjectSet ObjectSet containing
all objects in the ObjectContainer that match the passed
template object.
Calling get(NULL) returns all objects stored in the
ObjectContainer .
Query Evaluation
All non-null members of the template object are compared against
all stored objects of the same class.
Primitive type members are ignored if they are 0 or false respectively.
Arrays and all supported Collection classes are
evaluated for containment. Differences in length/size() are
ignored.
Consult the documentation of the Configuration package to
configure class-specific behaviour.
Returned Objects
The objects returned in the
ObjectSet ObjectSet are instantiated
and activated to the preconfigured depth of 5. The
com.db4o.config.Configuration.activationDepth activation depth may be configured
com.db4o.config.Configuration.activationDepth globally or
com.db4o.config.ObjectClass individually for classes .
db4o keeps track of all instantiatied objects. Queries will return
references to these objects instead of instantiating them a second time.
Objects newly activated by get() can respond to the callback
method
com.db4o.ext.ObjectCallbacks.objectOnActivate objectOnActivate .
Parameters: template - object to be used as an example to find all matching objects.
ObjectSet ObjectSet containing all found objects.
See Also: com.db4o.config.Configuration.activationDepth See Also: Why activation? See Also: ObjectCallbacks See Also: Using callbacks throws: Db4oIOException - I/O operation failed or was unexpectedly interrupted. throws: DatabaseClosedException - db4o database file was closed or failed to open. |
query | public ObjectSet<TargetType> query(Predicate<TargetType> predicate) throws Db4oIOException, DatabaseClosedException(Code) | | Native Query Interface.
Native Queries allow typesafe, compile-time checked and refactorable
querying, following object-oriented principles. Native Queries expressions
are written as if one or more lines of code would be run against all
instances of a class. A Native Query expression should return true to mark
specific instances as part of the result set.
db4o will attempt to optimize native query expressions and execute them
against indexes and without instantiating actual objects, where this is
possible.
The syntax of the enclosing object for the native query expression varies,
depending on the language version used. Here are some examples,
how a simple native query will look like in some of the programming languages
and dialects that db4o supports:
// 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";
}
});
Summing up the above:
In order to run a Native Query, you can
- use the delegate notation for .NET 2.0.
- extend the Predicate class for all other language dialects
A class that extends Predicate is required to
implement the #match() / #Match() method, following the native query
conventions:
- The name of the method is "#match()" (Java) / "#Match()" (.NET).
- The method must be public public.
- The method returns a boolean.
- The method takes one parameter.
- The Type (.NET) / Class (Java) of the parameter specifies the extent.
- For all instances of the extent that are to be included into the
resultset of the query, the match method should return true. For all
instances that are not to be included, the match method should return
false.
Parameters: predicate - the Predicate containing the native query expression. the ObjectSet returned by the query. throws: Db4oIOException - I/O operation failed or was unexpectedly interrupted. throws: DatabaseClosedException - db4o database file was closed or failed to open. |
|
|
|