|
db4o 7.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.db4o.query.Predicate<ExtentType>
public abstract class Predicate<ExtentType>
Base class for native queries.
Native Queries provide the ability to run one or more lines
of code against all instances of a class. Native query expressions should
return true to mark specific instances as part of the result set.
db4o will attempt to optimize native query expressions and run them
against indexes and without instantiating actual objects, where this is
possible.
The syntax of the enclosing object for the native query expression varies
slightly, 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.
Field Summary | |
---|---|
static java.lang.String |
PREDICATEMETHOD_NAME
public for implementation reasons, please ignore. |
Constructor Summary | |
---|---|
Predicate()
|
|
Predicate(java.lang.Class<ExtentType> extentType)
|
Method Summary | |
---|---|
boolean |
appliesTo(ExtentType candidate)
public for implementation reasons, please ignore. |
java.lang.Class<? extends ExtentType> |
extentType()
public for implementation reasons, please ignore. |
abstract boolean |
match(ExtentType candidate)
The match method that needs to be implemented by the user. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String PREDICATEMETHOD_NAME
Constructor Detail |
---|
public Predicate()
public Predicate(java.lang.Class<ExtentType> extentType)
Method Detail |
---|
public java.lang.Class<? extends ExtentType> extentType()
public abstract boolean match(ExtentType candidate)
candidate
- the candidate object passed from db4o
public boolean appliesTo(ExtentType candidate)
|
db4o 7.4 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |