Skip Headers
Oracle® Fusion Middleware Integration Guide for Oracle TopLink with Coherence Gird
11g Release 1 (11.1.1)

Part Number E16596-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

"Traditional Coherence" Configuration

This section includes information on the CacheStore/CacheLoader configuration.

CacheStore/CacheLoader

The TopLink Grid CacheStore/CacheLoader configuration allows you to map classes using JPA, but use the Coherence API to interact with the Coherence cache. This allows Coherence to interact with the database.

You can also use asynchronous writing with the CacheStore/CacheLoader configuration, by using the Coherence "write behind" configuration.

In general:

  • Through a CacheLoader, all read operations get objects from the database. See "Reading Objects".

  • Through a CacheLoader, all write operations update the database. See "Writing Objects".

See "Examples" for detailed examples.

Reading Objects

In the Coherence CacheStore/CacheLoader, all read queries are directed to the database by the TopLink CacheLoader.

This figure illustrates a query in the Grid Read configuration:

  1. Application issues a get query.

  2. By using a CacheLoader, Coherence will load the from TopLink.

  3. TopLink will query the database.

Writing Objects

In the Coherence CacheStore/CacheLoader, TopLink performs all database writes (insert, update, delete) through the CacheStore.

This figure illustrates a query in the Grid Read configuration:

  1. Application issues a put query.

  2. By using a CacheStore, Coherence will store the from TopLink.

  3. TopLink will insert the object into the database.

Examples

In the cache configuration (coherence-cache-config.xml) define the cache, as shown in this example.

Example 1 Configuring the Cache

<cache-config>
  <caching-scheme-mapping>
    <cache-mapping>
      <cache-name>Employee</cache-name>
      <scheme-name>distributed-eclipselink</scheme-name>
    </caching-scheme-mapping>
  </caching-scheme-mapping>
  <caching-schemes>
    <distributed-scheme>
      <scheme-name>distributed-eclipselink</scheme-name>
      <service-name>EclipseLinkJPA</service-name>
      <backing-map-scheme>
        <read-write-backing-map-scheme>
          <internal-cache-scheme>
            <local-scheme />
          </internal-cache-scheme>
          <!-- 
            Define the cache scheme 
          -->
          <cachestore-scheme>
            <class-scheme>
            <!-- 
              Since the client code is using Coherence API we need the "standalone" version of the cache loader 
            -->
              <class-name>oracle.eclipselink.coherence.standalone.EclipseLinkJPACacheStore</class-name>
              <init-params>
                <init-param>
                  <param-type>java.lang.String</param-type>
                  <param-value>{cache-name}</param-value>
                </init-param>
                <init-param>
                  <param-type>java.lang.String</param-type>
                  <param-value>employee</param-value>
                </init-param>
              </init-params>
            </class-scheme>
          </cachestore-scheme>
        </read-write-backing-map-scheme>
      </backing-map-scheme>
      <autostart>true</autostart>
    </distributed-scheme>
  </caching-schemes></cache-config>

In Example 2, you set the employee information and add the new object to Coherence. This issues an INSERT to the CacheStore.

Example 2 Inserting Objects

Employee employee = new Employee();
employee.setId(NEW_EMP_ID);
employee.setFirstName("John");
employee.setLastName("Doe");
// Putting a new object into Coherence  will result in an INSERT in the CacheStore 
employeeCache.put(NEW_EMP_ID, employee);

Getting an object from the cache produces no SQL statements. Getting an object that is not in the cache produces a SELECT statement.

Example 3 Reading Objects

// Getting an object from cache produces no SQL
System.out.println("New Employee from cache is: " + employeeCache.get(NEW_EMP_ID));

// Getting an object not in cache will produce a SELECT in the CacheStore
System.out.println("Non-existant Employee from cache is: " + employeeCache.get(NON_EXISTANT_EMP_ID));