Montag, 31. Juli 2017

Using Eclipse CDO as a lightweight ORM solution in web applications


For one of my projects I had to decide for an object relational mapping (ORM) solution to be used in a web environment. There is not much to think about when deciding which framework to use. Yet, I wanted to try out Eclipse CDO [1] as an alternative to, for example, hibernate.
The project is powered by CDO since a year, now. And it has proven to be a lightweight ORM solution. No JPA annotations, just design your EMF model, create instances and let CDO handle the rest...

A full request/response cycle

The following sketch shows the involved steps when a user (HTML5 client/browser) sends a HTTP request to a service that consumes the CDO storage.
Request/Response process

The web application is driven by (JAX-RS) REST services, so any call/request is served by the appropriate REST service. 
For each call which requires DB access, a new CDO transaction is opened, the request is processed, the result is converted to JSON and the transaction closed/committed.
Conversion of EMF model instances is done using Eclipse Texo [2] in most scenarios, but special view models are also created using a JSON java library like org.json [3].

The overall setup of the CDO server/backend:
  • CDO DBStore with embedded H2 RDBMS
  • disabled auditing, disabled branching (not needed by project)
  • one resource per user, central meta data resources (for example, user accounts, roles, permissions management), managed in different resource folders
    • simulation of a document oriented database
    • simplifies authorization a lot
  • nginx proxy for simple HTTPS setup
  • OSGi environment with embedded Jetty, packaged using a maven/tycho enabled Eclipse RCP product build
  • a very limited virtual host (for now): 512 MB RAM, single core Xeon CPU, Ubuntu 16.04 server
Have you ever considered using CDO as an ORM solution? Or are you already using it in a web context? What are your experiences?

[1] Eclipse CDO:
[2] Eclipse Texo: