
Geode JTA Transaction Example
An example code fragment shows how to run a JTA global transaction using Geode as the JTA transaction manager.
The external data sources used in this transaction are configured in the cache.xml
file. See Configuring Database Connections Using JNDI for a configuration example.
Region r = ...; // the region data source
ds = ...; // other data source
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
}