Wednesday, August 20, 2014

In previous post, we saw how to configure coherence adapter. In this post, we see how and where we can use this coherence adapter.

We have different operation in coherence adapter, Put operation is used to put the data to coherence cache and get operation used to get data from coherence cache.In this post, we see how to use this coherence adapter in real world.

We have created one database table (StudentInfo), we read the data (student information) from that table based on the Id (Student Id) which is primary key in the table. We use coherence adapter to get and put the data to cache. First we check whether the data is there in coherence cache, if data is there then we directly get the data from cache instead of database and if data is not there then we query the data from database and then put the data to coherence cache so that next time when same request come, we get the data from cache instead of making a database call. This has positive impact on performance.

Let’s start with the use case.

Create one SOA project and add one BPEL to it.

First configure the db adapter which read the data from database. Provide DB JNDI name. Click here to see how to create Java derby database data source. Choose DB connection and choose “Select” operation.

Coherence adapter sample


Select “StudentInfo” table and add selection criteria.

Coherence adapter sample


Now drag coherence adapter and choose “Put” operation. Click here to see how to configure coherence adapter for Put operation.

Drag another coherence adapter and choose “Get” operation. Click here to see how to configure coherence adapter for Get operation.

Now composite should look like below.

Coherence adapter use case


Now open the BPEL and add three invokes to it, connect first invoke to queryCoherence adapter, second to “putDataToCoherence” adapter and third to DB adapter.

Now add one switch case after first coherence adapter which check whether the data exist in cache or not.

Coherence adapter use case


Now we set the coherence cache key at run time. First create a string variable and before query coherence cache assign value to that variable.

coherence cache key


Now go to coherence adapter invoke and go to Properties tab and select “jca.coherence.key”. Assign above created variable to it.

jca.coherence.key


Do it same for put data to coherence adapter invoke.

Your BPEL should look like below.

Coherence Adapter sample



Deploy your composite and test it.

Testing Result:

When we test this composite, it will get the data from database.

Coherence Adapter testing


When we test it again with same request then it take the data from cache instead of database.

Coherence Adapter testing



Download sample code from here.







3 comments :

  1. Hi I am new to soa suite 12c. I am working with coherence adapter in Jdeveloper12c. If I do any updations in DB it is not getting reflected in cache. I mean both are not synchronised. please help me in solving this issue. Thanks in advance

    ReplyDelete
    Replies
    1. Hi Satha,

      You need to put the updates to cache using coherence adapter.

      Delete
  2. Ya i need to update the cache using coherence adapter. i heard something about "refresh-ahead". Is it useful for the same. please give me a clear idea

    ReplyDelete