Client-side persistence with eXPL requires writing a resource provider with database connectivity and the ability to perform basic read and write operations. The following examples illustrate resource provider design for interacting with Object-Relational Mapping (ORM) implementations, where database tables are mapped to annotated entity classes. Obviously this section is about Java programming, not eXPL per se. A resource provider has the following requirements:
- Identify one or more resources by name, each one representing a particular table or view
- For each resource, implement one or both of the axiom collection import/export provider methods
- For each import/export implemtation, map an entity class to an axiom archetype*
- An import method must execute a database query and marshall the result as an axiom collection
- An export method must unmarshall each axiom received to an entity object and write it to the database
- The provider may need to throttle data traffic to prevent the application appearing to go unresponsive
* An axiom archetype contains metadata about an axiom collection: term names, term sequence order and term types. Resource providers are passed archetypes in order to marshall an unmarshall axioms.
Application Stack
Persistence examples shown here are from the Classy eXPL project - see eXPL Extensions. Each application has a resource provider sitting on top of a framework which creates and populates a test database. The provider is dependent on the framework, so some understanding of the framework is needed to make sense of the code. Note that most of the code is open-source.
Each application consists of a small number of classes which perform persistence operations by calling to the Classy Data library, which in turn calls to the Ormlite Object Relational Mapping (ORM) library which in turns calls to a database driver which ultimately makes native calls to the operating system on which the application is running. Here is a brief description of the application stack on which the resource providers sit:
- eXPL Extensions- A package containing helper classes to which common tasks are delegated
- Classy Data - A lighweight JPA persistence framework.
- Ormlite ORM - An Object-Relational Mapping package, is popular with Android developers and has many supported databases.
- Database Driver - Currently only drivers SQLite and H2 are supported by Classy Data
- Java Runtime - Java can be installed on all popular operating systems. Java SE Version 7 is the minimum requirement
