Persistence Introduction  |  Persistence Rules  |  Persistence Example

 

API Overview

Introduction

The following schematics illustrates how the Persistence packages interact.

 

Description

The Persistence API provides methods to store and retrieve data like a database. A database has tables which contain fields. The fields can contain different information (date, strings, numbers and so on). In the Persistence API a database table is represented by the ClassDescriptor (.meta package) and the Entity (.app package) represent the fields.

Basic steps

The PackagePersistentMaster (.app package) provides the describing information off the Entity instances to be persisted. The PackagePersistenceMaster has to be implemented for every Entity instances to be persisted. The Entity instances are identified by the abstraction of the actual Java class, called the classtype.

See, ExamplePackagePersistenceMaster.java as an example implementation of PackagePersistentMaster.

Next step is to register the PackagePersistenceMaster at the PersistenceRuntime. The PersistenceRuntime is a singleton instance that is visible to all applications on the device. The application itself can decide if it wants to work with user specific data or all the data on the device (shared).

See, ReadWriteEntities.java method SetupPersistenceRuntime.

The SetupPersistenceRuntime method gets the TransactionManager from the PersistenceRuntime instance with the .getTransactionManager method. In this step the application decides if it wants to work with user data or shared (user independent) data. A TransactionManager is mandatory for every data access and controls the transactions (read, read/write).

The Persistence API is now set up properly and you can read, write or query data. In detail

  Method Description
ReadWriteEntities.java WriteReplaceEntity Writes new entities. In case an entity already exists, it will be replaced
  ReadEntity Reads an entity with its associated entity.
  DeleteEntity Deletes an entity

 

 

.