Menu

orm_filters

Luis M. Villa

Retrieve an object using filters

(Return to examples index)

This section will be short. If you want to use complex conditions, you have to user filters. A Filter is a class that contains a part of a query string, and an array of parameters:

// This is a filter
Filter oneFilter = new Filter("userId>?", new Object[] { 1 });

// This is another filter
Filter anotherFilter = new Filter("deleted=?", new Object[] { false });

// ... and this is a filter that make an AND of the previous
Filter mixedFilter = oneFilter.and(anotherFilter);

So, let's retrieve an object using a filter:

final Issue issue = new IssuesDb().orm().loadOne(Issue.class,
    new Filter("id=?", new Object[] { 1 }));

Done. We have retrieved our first objects from the database. Our next step is to fetch a collection of objects.


Related

Wiki: Examples
Wiki: examples_toc
Wiki: orm_collection
Wiki: orm_get_by_id

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.