-
Notifications
You must be signed in to change notification settings - Fork 5
Persistence Service_136675804
nxi edited this page Apr 9, 2015
·
1 revision
Created by Tony Lam, last modified on Dec 22, 2009
The GumTree local persistence (ILocalPersistenceManager) service provides a managed way to store object and state locally for application recovery. The database used for persistence is called db4o (managed by service IObjectContainerManager), which is an small embedded object database for Java and OSGi. To use the persistence service, you will need to import plug-in org.gumtree.core.persistence, and have plug-in db4o_osgi available.
The local persistence service provides a simple way to store object using key-value pairs, backed by the default db4o object container offered by the GumTree platform. The following test case illustrates how this service can be used:
Developer note: Due to the constraint of OSGi class loading, the stored data MUST be located in exported package (ie, cannot persist object from internal packages).
This service provides a default object database, as well as keeping track of other object database based on user creation. Those databases are stored under <workspace>/.metadata/.plugins/org.gumtree.core.persistence/.
Developer note: We use the OSGi version db4o (Db4oService) and not the generic helper class (Db4o) to create new object container instance, since it solves the class loading problem.
To use this service for storage:
To retrieve object, use Native Query directly on the object container:
You can create a new object container with the local persistence manager:
If the database has already opened, it will return the database straight away.
// Should initially be empty assertNull(manager.retrieve(key, String.class)); assertFalse(manager.contains(key)); // Persist manager.persist(key, data); assertTrue(manager.contains(key)); assertEquals(data, manager.retrieve(key, String.class)); // Update manager.persist(key, newData); assertTrue(manager.contains(key)); assertEquals(newData, manager.retrieve(key, String.class)); // Remove manager.remove(key); assertNull(manager.retrieve(key, String.class)); assertFalse(manager.contains(key));
ILocalPersistenceManager manager = GTPlatform.getService(ILocalPersistenceManager.class); ObjectContainer db = manager.getDefaultObjectContainer(); db.store(object);
manager.getDefaultObjectContainer().query(...)
// Create a new one called "mydatabase" and do not overwrite ObjectContainer db = manager.createObjectContainer("mydatabase", false); db.store(object, "mydatabase");
Document generated by Confluence on Apr 01, 2015 00:11
Home | Developer Guide | Copyright © 2013 ANSTO