Skip to content
svenmeier edited this page Dec 12, 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 automagically 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

Mapping provides propoid.db.mapping.Mappers which are used to map properties to database columns. propoid.db.mapping.DefaultMapping handles most common types.

Naming

Naming decides which table to be used for each Propoid and how to encode subclasses. propoid.db.naming.DefaultNaming uses a single-table-mapping for inheritance.

Factory

All Propoids read from the database are created by a factory. propoid.db.factory.DefaultFactory creates a new instance on each requested Propoid. propoid.db.factory.IdentityFactory caches Propoids by their type and identifier, thus offering object identity if required.

Cascading

Before Propoids are inserted, updated or deleted, this strategy is allowed to cascade operations to referenced Propoids. propoid.db.cascading.DefaultCascading allows registering of properties, which should be cascaded.

Versioning

On opening the database this strategy allows to perform required upgrades.

Clone this wiki locally