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

GemFire JTA Transaction Example

GemFire JTA Transaction Example

This example shows how to run a JTA global transaction using GemFire as the JTA transaction manager.

The external data sources used in this transaction are configured in cache.xml. See Configuring Database Connections Using JNDI for examples.
Region r = ...; // the gemfire regionDataSource 
ds = ...; // other datasource    

  try  {     
         Context ctx = cache.getJNDIContext();      
         Connection conn =  null;
         UserTransaction
         tx = (UserTransaction)
         ctx.lookup("java:/UserTransaction");     
         tx.begin();
         conn = ds.getConnection();
         Statement stmt = conn.createStatement();
         String sqlSTR =  "insert into " + tableName + " values (........ )";
         stmt.executeUpdate(sqlSTR);   
         r.put("key", "value");
         stmt.close();     
         tx.commit();
         conn.close();
      } catch (NamingException e) { 
         // handle the exception   
   }