Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Texo/EntityManagerObjectStore"
(New page: __TOC__ == Introduction == The Texo ObjectStore concept integrates the model layer with JPA. It makes it possible to query using an EClass or to perform cross reference queries. In addit...) |
|||
(13 intermediate revisions by one other user not shown) | |||
Line 3: | Line 3: | ||
== Introduction == | == Introduction == | ||
− | The Texo ObjectStore concept integrates the model layer with JPA. It makes it possible to query using an EClass | + | The Texo Entity Manager ObjectStore concept integrates the model layer with JPA. It provides the following functionality: |
+ | * It makes it possible to query using an EClass | ||
+ | * Supports cross reference queries | ||
+ | * Supports (de-)serialization with (de-)resolving of references in the XML/XMI against the ObjectStore (the database) | ||
+ | |||
+ | If you want more specific Dao functionality, check out the [[Texo/Dao|Texo Dao]] support. | ||
+ | |||
+ | The Entity Manager Object Store is implemented as a Texo component, so you can replace its implementation by your own class using the [[Texo/Components|Texo Component]] framework. | ||
== Jar files/Plugins == | == Jar files/Plugins == | ||
− | The Texo Object Store | + | The Texo Object Store is defined in the org.eclipse.emf.texo.server plugin which is part of the Texo runtime feature (see [[Texo/Download_and_Install|Download & Install]]). |
− | == Creating an Object Store == | + | == Creating an Object Store using the Object Store Factory == |
+ | |||
+ | The runtime layer uses an [http://git.eclipse.org/c/texo/org.eclipse.emf.texo.git/tree/runtime/org.eclipse.emf.texo.server/src/org/eclipse/emf/texo/server/store/ObjectStoreFactory.java Object Store factory] to create an object store. The object store factory uses the request uri to determine what store to create. Next to the entity manager object store described here there are other implementations such the [[Texo/EMFResourceObjectStore|EMFResourceObjectStore]]. | ||
+ | |||
+ | You can implement/set your own object store factory using the [[Texo/Components|Texo Component]] infrastructure or by calling ObjectStoreFactory.setInstance with your own instance. | ||
+ | |||
+ | == Creating an the Entity Manager Object Store Directly == | ||
An Object Store instance can be created directly if you have an EntityManager available: | An Object Store instance can be created directly if you have an EntityManager available: | ||
<source lang="java">EntityManagerObjectStore objectStore = new EntityManagerObjectStore(); | <source lang="java">EntityManagerObjectStore objectStore = new EntityManagerObjectStore(); | ||
− | objectStore.setEntityManager( | + | objectStore.setEntityManager(entityManager); |
− | // the URI is used for de-resolving references when serializing to XML | + | // the URI is used for de-resolving references when serializing to XML, see below |
objectStore.setUri("http://jpa.test"); | objectStore.setUri("http://jpa.test"); | ||
</source> | </source> | ||
− | + | '''Note that for the ObjectStore to be able to read the model layer: the model package class needs to be loaded and initialized, just touching it is enough, for example:''' | |
+ | <source lang="java">LibraryModelPackage.initialize(); | ||
+ | </source> | ||
== Cross Reference Queries == | == Cross Reference Queries == | ||
+ | |||
+ | The ObjectStore allows you to retrieve all the objects which reference a certain target object: | ||
+ | <source lang="java">// get maximum 3 referers and include containment referers | ||
+ | List<Object> referers = objectStore.getReferingObjects(target, 3, true); | ||
+ | </source> | ||
+ | |||
+ | See the ObjectStore getReferingObjects api and the isReferenced method. | ||
+ | |||
+ | == EntityManager == | ||
+ | |||
+ | The ObjectStore needs an EntityManager to perform database queries. The ObjectStore uses the standard Texo approach to get an instance of the EntityManager, see [[Texo/EntityManagerHandling|this]] wiki page for more information. | ||
== (De-)Serializing XML with correct id's == | == (De-)Serializing XML with correct id's == | ||
Line 26: | Line 52: | ||
When (de-)serializing XML most of the time the references to other objects should be serialized as external references (the referenced object is not present in the XML). When de-serializing the XML these references should be correctly resolved to objects again. This resolving needs to be able to read the objects from the database again. | When (de-)serializing XML most of the time the references to other objects should be serialized as external references (the referenced object is not present in the XML). When de-serializing the XML these references should be correctly resolved to objects again. This resolving needs to be able to read the objects from the database again. | ||
− | This (de-)resolving of references while reading from the database is done using the ObjectStore. | + | This (de-)resolving of references while reading from the database is done using the ObjectStore. It is quite simple: |
+ | <source lang="java">// serialize a set of objects to xml, use XMI (specified by the second parameter | ||
+ | String xml = objectStore.toXML(objects, true); | ||
+ | // and get it back | ||
+ | List<Object> objects = objectStore.fromXML(xml, true); | ||
+ | </source> |
Latest revision as of 09:17, 8 December 2015
Contents
Introduction
The Texo Entity Manager ObjectStore concept integrates the model layer with JPA. It provides the following functionality:
- It makes it possible to query using an EClass
- Supports cross reference queries
- Supports (de-)serialization with (de-)resolving of references in the XML/XMI against the ObjectStore (the database)
If you want more specific Dao functionality, check out the Texo Dao support.
The Entity Manager Object Store is implemented as a Texo component, so you can replace its implementation by your own class using the Texo Component framework.
Jar files/Plugins
The Texo Object Store is defined in the org.eclipse.emf.texo.server plugin which is part of the Texo runtime feature (see Download & Install).
Creating an Object Store using the Object Store Factory
The runtime layer uses an Object Store factory to create an object store. The object store factory uses the request uri to determine what store to create. Next to the entity manager object store described here there are other implementations such the EMFResourceObjectStore.
You can implement/set your own object store factory using the Texo Component infrastructure or by calling ObjectStoreFactory.setInstance with your own instance.
Creating an the Entity Manager Object Store Directly
An Object Store instance can be created directly if you have an EntityManager available:
EntityManagerObjectStore objectStore = new EntityManagerObjectStore(); objectStore.setEntityManager(entityManager); // the URI is used for de-resolving references when serializing to XML, see below objectStore.setUri("http://jpa.test");
Note that for the ObjectStore to be able to read the model layer: the model package class needs to be loaded and initialized, just touching it is enough, for example:
LibraryModelPackage.initialize();
Cross Reference Queries
The ObjectStore allows you to retrieve all the objects which reference a certain target object:
// get maximum 3 referers and include containment referers List<Object> referers = objectStore.getReferingObjects(target, 3, true);
See the ObjectStore getReferingObjects api and the isReferenced method.
EntityManager
The ObjectStore needs an EntityManager to perform database queries. The ObjectStore uses the standard Texo approach to get an instance of the EntityManager, see this wiki page for more information.
(De-)Serializing XML with correct id's
When (de-)serializing XML most of the time the references to other objects should be serialized as external references (the referenced object is not present in the XML). When de-serializing the XML these references should be correctly resolved to objects again. This resolving needs to be able to read the objects from the database again.
This (de-)resolving of references while reading from the database is done using the ObjectStore. It is quite simple:
// serialize a set of objects to xml, use XMI (specified by the second parameter String xml = objectStore.toXML(objects, true); // and get it back List<Object> objects = objectStore.fromXML(xml, true);