Skip to content
svenmeier edited this page Dec 9, 2011 · 35 revisions

Working with Sqlite is very easy with propoid-db, create a repository and start right away without any setup:

Repository repository = new Repositiory(context, "foos");

All required tables will automatically be created once you perform operations on the repository.

Inserting and updating

To insert a new object just pass it to Repository#insert():

repository.insert(new Foo());

An object can similarily be updated:

repository.update(foo);

Queries

Objects can be queried with a fully typed API:

Match<Foo> match = repository.query(Where.equal(new Foo().bar, "BAR"));

Note that a database operation is performed only after you invoke a method on the query match, e.g.:

List<Foo> foos = match.list(Order.ascending(new Foo().bar);

The #list() method is special in that all its elements are backed by a life database cursor. To close its resources you have to call Closable#close() on it or even simpler just consume all its elements, e.g.:

for (Foo foo : foos) {
}
// all foos are consumed now

Indices

To increase performance of your application you might want to add indices to your repository:

Foo foo = new Foo();
repository.index(foo, false, foo.bar);

Settings

Each repository is highly configurable through a set of settings, e.g.:

Repository repository = new Repository(context, "foos", new FoosMapping(), new FoosFactory());

Mapping

Naming

Factory

Cascading

Versioning

Clone this wiki locally