Part 2 – Avatar Persistence

Oracle presents: Avatar 2.0 – where to next?

Niko Köbler
Data illustration via Shutterstock

Niko Köbler continues his investigation of the new version of Oracle’s Avatar and its Model Store API.

Under the title “Avatar Persistence”, Oracle introduced a Model Store API that makes it possible to save objects in different databases with a unified API (JSON). These databases can either be relational or non-relational (NoSQL).

Read part one of Avatar 2.0 here

Since Avatar persistence is based on JPA (with the EclipseLink implementation), it’s only possible to communicate with other databases via the JDBC driver. The following example illustrates the use of the new Model Store API:

// define a connection to a data store
var store = avatar.newStore(‘mysql’, {
    host: 'localhost',
    port: 3306,
    database: 'test',
    username: 'root'
});

// define object 'Family'
var Family = avatar.newModel('family', {
        "name" : {
            type : "string",
            primary : true
        },
        "description" : "string"
    });
// define object 'Product'
var Product = avatar.newModel('product', {
        "name" : {
            type : "string",
            primary : true
        },
        "price" : "number",
        "quantity" : "integer"
    });

// create a relation between the two objects
Family.hasMany(Product, {
    as : 'products',
    foreign : 'family'
});

// bind the objects to the store
store.bind(Family, Product);

// create an product object and save it to the store
store.connect(function() {
  Product.create({
    name: 'myProduct',
    price: 1.00,
    quantity: 2,
  }, function(err, product) {
    console.log(JSON.stringify(product));
    store.disconnect(function() {
      // done
    });
  });
});

So far, the JDBC communication with the Oracle Database, MySQL and Derby database has tested positive. On the NoSQL side, the Oracle NoSQL database is already supported. A MongoDB driver will soon follow.

In addition, as a small gift, users have been given Model Store API asynchronous processing of JDBC calls. Since JDBC blocks, Avatar encapsulates the calls and returns the results as Promise.

The client framework and JMS

The client framework which provided a comfortable binding using the JSF expression language and rendered widgets based on jQuery UI has been removed entirely. From the beginning, this framework was not a mature solution.

On the UI side Oracle said a year ago that users could fall back on the framework of their choice (eg. Angular, Knockout, Backbone, ember, and so forth) as “only” a protocol-based communication was taking place between server and client and the client components did not rely on the server. What was once a “can” has now become a “must” and the result is that the entire client library disappears.

Avatar 2.0 architecture

Avatar 2.0 architecture © Niko Köbler via blog.n-k.de

JMS is in a similar situation. There was already an integrated solution, which, packages the synchronous JMS calls (JMS 1.1 / Java EE 6 specification) in an asynchronous call – just like the JDBC layer. However, now that the Application Server is eliminated as a runtime environment, a JMS environment is no longer available. However, Oracle wants to develop a remote thin client based on their own internal t3 protocol in order to reach JMS resources using a WebLogic app server.

REST in peace

REST, push and socket services have also suffered as a result of the elimination of the application server. Oracle claims that the majority of users that gave feedback, preferred using implementations built on Node.js and defining the services from there. For REST services, this could be the Express Package, and for Socket Services Node-WS and Server-Sent Events, the respective package from the Node Package Manager (NPM).

Hopefully we’ll soon know, what exactly Avatar 2.0 will look like. The source code is not yet available, but “in a few weeks to months” it should be posted on the project page. So far the “old” Project Avatar is still visible there. From the community itself, Oracle wants lots of feedback. To do this, make sure to sign up to the mailing list.

Read part one of Nico Köbler’s analysis of Avatar 2.0

Originally published on JAXenter.de / translated by Anna Job

Author
Niko Köbler
Niko Köbler is a freelance software architect and Java and JavaScript developer, as well as a regular speaker at JAX conferences.

Comments
comments powered by Disqus