LATEST VERSION: 8.2.5 - CHANGELOG
Pivotal GemFire® v8.2

JCA Resource Adapter Example

JCA Resource Adapter Example

This example shows how to use the JCA Resource Adapter in GemFire .

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
“weblogic.jndi.WLInitialContextFactory”);
env.put(Context.PROVIDER_URL, “t3://localhost:7001”);
Context ctx = new InitialContext(env);
UserTransaction utx = (UserTransaction)
	ctx.lookup(“javax.transaction.UserTransaction”);
utx.begin();
      // The XA Resource
javax.sql.DataSource ds = (DataSource(ctx.lookup(“derby”);
javax.sql.Connection derbyConn = ds.getConnection();
Statement stmt = conn.createStatement();
stmt.executeUpdate(“insert into test values(2,4) “);
     //Performing GemFire Connection Factory lookup
GFConnectionFactory cf = (GFConnectionFactory) ctx.lookup(“gfe/jca”);

//The following step that obtains the connection is what
//begins the LocalTransaction on GemFire.
//If this is absent, GFE operations will not be part of any transaction.

GFConnection gemfireConn cf = (GFConnectionFactory) ctx.lookup(“gfe/jca”);

testRegion.put(“foo”, “bar-”);
utx.commit();

//The connection can also be closed within the transaction.
derbyConn.close();
gemfireConn.close();