Striim 3.9.4 / 3.9.5 documentation

Replicating Oracle data to a Hazelcast "hot cache"

Striim provides a template for creating applications that read from Oracle and write to Hazelcast. See Creating a new application using a template for details.

See HazelcastWriter for information on the adapter properties.

To replicate Oracle data to Hazelcast:

  1. Write a Java class defining the Plain Old Java Objects (POJOs) corresponding to the Oracle table(s) to be replicated (see http://stackoverflow.com/questions/3527264/how-to-create-a-pojo for more information on POJOs), compile the Java class to a .jar file, copy it to the Striim/lib directory of each Striim server that will run the HazelcastWriter target, and restart the server.

  2. Write an XML file defining the object-relational mapping to be used to map Oracle table columns to Hazelcast maps (the "ORM file") and save it in a location accessible to the Striim cluster. Data types are converted as specified in the ORM file. Supported Java types on the Hazelcast side are:

    • binary (byte[])

    • Character, char

    • Double, double

    • Float, float

    • int, Integer

    • java.util.Date

    • Long, long

    • Short, short

    • String

    Odd mappings may throw invalid data errors, for example, when an Oracle VARCHAR2 column mapped to a long contains a value that is not a number. Oracle BLOB and CLOB types are not supported.

  3. Write a Striim application using DatabaseReader and HazelcastWriter to perform the initial load from Oracle to Hazelcast .

  4. Write a second Striim application using OracleReader and HazelcastWriter to perform continuous replication. 

This example assumes the following Oracle table definition: 

CREATE TABLE INV ( 
  SKU INT PRIMARY KEY NOT NULL,
  STOCK NUMBER(*,4),
  NAME varchar2(20),
  LAST_UPDATED date 
);

The following Java class defines a POJO corresponding to the table:

package com.customer.vo;
import java.io.Serializable;
import java.util.Date;
public class ProductInvObject  implements Serializable {

   public long sku = 0;
   public double stock = 0;
   public String name = null;
   public Date lastUpdated = null;

   public ProductInvObject ( ) {    }

   @Override
   public String toString() {
       return "sku : " + sku + ", STOCK:" + stock + ", NAME:" + name + ", LAST_UPDATED:" + lastUpdated  ;
   }
}

The following ORM file maps the Oracle table columns to Hazelcast maps:

<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/orm" version="2.4">

    <entity name="prodcInv" class="com.customer.vo.ProductInvObject" >  
        <table name="MYSCHEMA.INV"/>
        <attributes>
            <id name ="sku" attribute-type="long"  >
                <column nullable="false" name="SKU" />
            </id>
            <basic name="stock" attribute-type="double" >
                <column nullable="false" name="STOCK"  />
            </basic>
            <basic name="name" attribute-type="String" >
                <column  name="NAME" />
            </basic>
            <basic name="lastUpdated"  attribute-type="java.util.Date" >
                <column name="LAST_UPDATED" />
            </basic>
        </attributes>
    </entity>

</entity-mappings>

 Assuming that the ORM file has been saved to Striim/Samples/Ora2HCast/invObject_orm.xml, the following Striim application will perform the initial load:

CREATE APPLICATION InitialLoadOra2HC;

CREATE SOURCE OracleCDCIn USING DatabaseReader (
  Username:'striim',
  Password:'passwd',
  ConnectionURL:'203.0.113.49:1521:orcl',
  Tables:'MYSCHEMA.INV'
)
OUTPUT TO OracleCDCStream;

CREATE TARGET HazelOut USING HazelcastWriter (
  ConnectionURL: '203.0.1113.50:5702',
  ormFile:"Samples/Ora2HCast/invObject_orm.xml",
  mode: "initialLoad",
  maps: 'MYSCHEMA.INV,invCache'
)
INPUT FROM OracleCDCStream;

END APPLICATION InitialLoadOra2HC;

Once InitialLoadOra2HC has copied all the data, the following application will perform continuous replication of new data:

CREATE APPLICATION ReplicateOra2HC;

CREATE SOURCE OracleCDCIn USING OracleReader (
  Username:'striim',
  Password:'passwd',
  ConnectionURL:'203.0.113.49:1521:orcl',
  Tables:'MYSCHEMA.INVmyschema.ATM'
)
OUTPUT TO OracleCDCStream;

CREATE TARGET HazelOut USING HazelcastWriter (
  ConnectionURL: '203.0.1113.50:5702',
  ormFile:"Samples/Ora2HCast/invObject_orm.xml",
  mode: "incremental",
  maps: 'MYSCHEMA.INV,invCache'
)
INPUT FROM OracleCDCStream;

END APPLICATION ReplicateOra2HCInitialLoadOra2HC;

Note

If the Hazelcast cluster goes down, the data in the map will be lost. To restore it, stop the replication application, do the initial load again, then restart replication.