Prev | Current Page 301 | Next

Alexander Kolesnikov

"Tapestry 5: Building Web Applications"

This is how we can
define such a condition in Java:
celebrity.getId() >= indexFrom &&
celebrity.getId() <= indexTo
For this condition to work in our native query, we need to put it into the match
method of an implementation of the Predicate interface. Then we pass this
Predicate to the query method of our database. To do all this, the tutorial that
comes with db4o uses the "anonymous inner class" feature of the Java language that
allows creating an implementation of an interface "on-the-fly". Let's follow the
same approach:
public List getRange(final int indexFrom,
final int indexTo)
{
List result =
Appendix B
[ 255 ]
db.query(new Predicate()
{
public boolean match(Celebrity celebrity)
{
return celebrity.getId() >= indexFrom &&
celebrity.getId() <= indexTo;
}
});
return result;
}
This way, in pure Java, we can define any kind of condition, and there is no need
to resort to any specialized query languages. By the way, we had to make method
parameters final here since otherwise Java would not allow us to use them in an
inner class.
The Final Strokes
Finally, here is the complete source code of the new ObjectDataSource:
package com.


Pages:
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
zakłady bukmacherskie przeszycia łódź czlowiek.cieszyn.pl wróżby miłosne poker