Database resources
Introduction
'Kauri database resources' is a convenience module that can be used to expose database resources through a RESTful uniform interface.
All you have to do is:
- Create a module with some POJO's you want to persist.
- Annotate them with JPA annotations (only @Entity is required).
- Add a META-INF/persistence.xml file and configure your persistence unit (connection-url, username, pasword)
- Add the kauri-dbresources-impl jar as a dependency to your project and import it's spring configuration in your project spring configuration
-
<import resource="classpath:org/kauriproject/dbresources/dbresources-beans.xml"/>
- Mount the JpaRestlet on a path of choice in your kauri.xml file.
JpaRestlet
This is the restlet that provides the database resources.
It will virtually create a URI-space for your entities, using the following structure:
- /<myentity> -> list of all myentity records
- /<myentity>/<id> -> myentity with id = id
- /<myentity>/<id>/otherentity -> list of all otherentity records that are a property of myentity with id = id
- /<myentity>?otherentity=<id> -> list of all myentity records with the entity otherentity with id=id as a property.
- ... and so on ...
Supported operations are:
- GET: retrieve a representation of the database resource
- PUT: Update a database resource (the URI must identify a specific resource !)
- POST: Create/add a new database resource instance (the URI must point to a list of resources of the according type !)
- DELETE: Delete the identified database resource (the URI must identify a specific resource !)
- and of course HEAD and OPTIONS
All resources have three default representations:
- text: a textual representation of your entity
- XML: a xml representation
- JSON: a json representation
Entities that are serializable, can also be retrieved as serialized java objects.
Via content negotiation (resulting in the right Accept header being set) the appropriate representation will be returned.
For POST/PUT operations, the payload may be JSON, XML or serialized java objects.
Restrictions
With the 0.2 Kauri release, database resources is in it's initial stable phase. We are aware of certain restrictions and imperfections, but before we tackle those issues we 'd like to have a better view on where this module is going and what features users want to see in it.
Use cases
- The main use case will be prototyping.
- It should however also be adequate for some simple projects, such as polls and site surveys
- In the future we will start a forms integration, which will provide a simple CRUD out of the box on top of this module that can be used for e.g. basic administration purposes.
- For bigger demands (such as heavy business applications), a specific service layer will probably be preferred over this module, but maybe the source code of this implementation might give some interesting pointers for starting.


There are no comments.