The Persistence API is a Java client library, which provides the generic RDF persistence framework. It allows serialization and de-serialization of the Java objects into RDF repositories (based on RQL and RUL languages) and will provide Criteria API, which allows creation and execution of RQL queries dynamically in the program code. Main functionalities of the Persistence API include:
The architecture of the framework is depicted on the following figure. Persistence API users can use modules shaded in gray. The rest of modules are internal and are not normally accessed by users (tools developers).
Main purpose of Entity Manager is to separate business logic from RDF. By simple annotations, user can connect his Bean class with RDFSuite, without knowing RQL/RUL. Entity Manager Provides RDF persistent framework for the Java objects defined for the various artefacts and used to implement application logic of the KP-Lab tools. Following methods are provided:
|URI persist(Object entity)|| Serialize Java DAO into RDF repository. This will update existing or create new |
RDF resource with properties specified in Java object.
|<T> T find(Class<T> type, URI uri)|| Deserialize Java object of the specified type from the RDF statements |
stored in the RDF repository.
|void remove (URI uri)||Removes resource from RDF repository, based on given uri of the resource.|
|<T> List<T> executeCriteria(Criteria cri. teria, Class<T> type)||Execute criteria query and translate RDF resources of the result graph to the Java objects of the specified type.|
To develop a tool, which will manage knowledge artefact with the specified RDF Scheme, it is assumed that the tool developer will follow the following steps.
Persistence API provides following Java annotations for users to create DAO:
|RDFResource||Namespace typeName||Class annotation.Required annotation.|
|URId||N/A||Field or Method Annotation. This is required annotation, each DAO must have exactly one|
|Property||Name targetEntity|| Field or Method AnnotationtargetEntity must be specified for Collections. |
required annotation, each DAO must have at least one
|InverseProperty||Name targetEntity||Field or Method Annotation.targetEntity must be specified for Collections|
DAO used with Entity Manager are independent, they can be freely serialized like any other Java Beans. However there are several requirements that are placed on these DAO:
Persistence API specifies and utilizes Lazy collections in order to greatly improve performance when deserializing from RDF repository. Main idea behind lazy collections is that DAO are fetched from RDFSuite only when they are really needed.
This feature of Persistence API is very similar to one in Hibernate. Lazy collections are transparent to users and they don’t need to change they code in any way in order to utilize this feature. Users need to be aware of this feature though, and they need to keep Entity Manager collection open in order to be able to use lazy fetching (if connection was closed, exception would be thrown). Currently, following collections have support for lazy initialization:
Persistence API tries to follow Java RDF (JRDF) specification. Currently, all Java's Primitive Data Types plus Date/xsd:dateTime are supported. If user wants to have support for additional typed, he can do so by registering (even in runtime) a new datatype in LiteralFactory class
RDF Model used in Persistence API is slightly extended JRDF Model. We have extended it to support datatypes and resource view. It is aimed to be resource-centric and independent on underlying RDF storage. Following figure shows UML class diagram of RDF Object model used in Persistence API to parse result from RDF suite:
Most of the time, user does not need to access this model, because he/she is working with DAO objects only. However, there may be situations when it is better for the user to get result not in the form of a DAO class, but in the form of an object of some RDF Java object model. Persistence API will provide “parametric query” methods which parse well defined subset of RQL into RDF Model. This way, user does not need to parse difficult results from KMS Request Engine him/herself. Persistence API can also provide specific methods that will generate complex queries and return result in form of a RDF Model. Functionality of these methods is very specific and thus done upon users’ needs. Results from Criteria API can also be returned in form of a RDF Model, if needed.