You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by Apache Wiki <wi...@apache.org> on 2013/07/18 09:40:33 UTC
[Metamodel Wiki] Update of "examples/PojoDataContext" by KasperSorensen
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Metamodel Wiki" for change notification.
The "examples/PojoDataContext" page has been changed by KasperSorensen:
https://wiki.apache.org/metamodel/examples/PojoDataContext
Comment:
Converted 'POJO datastores - Query your Java objects!' page to wiki format
New page:
= POJO datastores - Query your Java objects! =
With the MetaModel-pojo module of MetaModel you can use MetaModel's query engine to fire queries on a collection of regular Java objects (Java beans, Maps or arrays).
Assume we have a Person class:
{{{#!java
public class Person {
private String name;
private int age;
// getters and setters
}
}}}
And some list of persons:
{{{#!java
List<Person> persons = ...
}}}
You can easily wrap this collection in a PojoDataContext and query it like a database, for instance to get all the adult names:
{{{#!java
TableDataProvider<Person> provider = new ObjectTableDataProvider<Person>("persons",Person.class,persons);
DataContext dc = new PojoDataContext(provider);
DataSet ds = dc.query().from("persons").select("name").where("age").greaterThan(18).execute();
while (ds.next()) {
Row row = ds.getRow();
String name = (String) row.getValue(0);
System.out.println(name);
}
ds.close();
}}}
----
CategoryExamples