Skip to content

Commit

Permalink
Added molgenis-data-jpa documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
erwinwinder committed Jan 15, 2014
1 parent d7b6547 commit c654006
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
Binary file added molgenis-data-jpa/doc/molgenis-data-jpa.dia
Binary file not shown.
67 changes: 67 additions & 0 deletions molgenis-data-jpa/doc/molgenis-data-jpa.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
## Introduction
The molgenis-data-jpa package is an jpa data backend for Molgenis. All entities descibed in the Molgenis dsl model xml files and that are generated using the Molgenis generator can be used with the Data Api. It provides functionality to query, create, update and delete jpa entities.

For this package to work you must configure your spring applicationcontext for use with jpa. You can do this by including the `org.molgenis.DatabaseConfig` spring configuration class.

## Core molgenis-data-jpa classes
<img src="molgenis-data-jpa.png" />

**The light grey classes are provided by the core molgenis-data module**

**The classes marked 'generated' will be generated by the Molgenis generator**

### JpaEntity
The JpaEntity interface is implemented by all jpa entities. The concrete jpa entities are generated by the Molgenis generater according to the domain specific xml configuration files. The entities are strongly typed but they also implement the `Entity` interface so you can them like any other entity implementation.

The entities contain a field named `ENTITY_NAME` that contains the name of the entity.
Alsp for all fieldnames constants are generated.

### JpaRepository
For all jpa entities defined in the configuration file a jpa repository is generated that is derived from the `AbstractJpaRepository`. It is a wrapper around the `javax.persistence.EntityManager`. For every jpa entity there is a strongly type jpa repository.

The required metadata classes are also generated.

### JpaEntitySourceImpl
This is generated to contain all jpa repositories. One exists per application. The url is always `jpa://`.

### JpaEntitySourceFactory
Just returns the generated `JpaEntitySourceImpl` as there can be only one JpaEntitySource per application.
The url prefix is `jpa://`.

### JpaEntitySourceRegistrator
This class will registers the jpa entity source if it is in your spring context. It is annotated with `@Component` so when you have this class inculded in your spring component scan, everything will be automatically registered (example `@ComponentScan("org.molgenis")`).

## Usage example

*** Model ***

```
<?xml version="1.0" encoding="UTF-8"?>
<molgenis name="org.molgenis">
<module name="test">
<entity name="Person">
<field name="id" type="autoid" />
<field name="name" type="string" />
</entity>
</module>
</molgenis>
```

*** Find a Person with name 'Piet' ***

```
DataService dataService = ...;
Query q = new QueryImpl().eq(Person.NAME, "Piet");
Person person = dataService.findOne(Person.ENTITY_NAME, q);
```











Binary file added molgenis-data-jpa/doc/molgenis-data-jpa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c654006

Please sign in to comment.