config.setDatabaseMetaDataCacheFactory(new SimpleDatabaseMetaDataCacheFactory());
config.setStateManagerFactory(factory);
// config.setDispatcherFactory(new JGroupsCommandDispatcherFactory());
config.setDurabilityFactory(new FineDurabilityFactory());
DataSource ds = new DataSource();
ds.setCluster("cluster");
ds.setConfigurationFactory(new SimpleDatabaseClusterConfigurationFactory<javax.sql.DataSource, DataSourceDatabase>(config));
@SuppressWarnings("unchecked")
InvocationHandler<javax.sql.DataSource, DataSourceDatabase, javax.sql.DataSource, SQLException, ProxyFactory<javax.sql.DataSource, DataSourceDatabase, javax.sql.DataSource, SQLException>> handler = (InvocationHandler<javax.sql.DataSource, DataSourceDatabase, javax.sql.DataSource, SQLException, ProxyFactory<javax.sql.DataSource, DataSourceDatabase, javax.sql.DataSource, SQLException>>) Proxy.getInvocationHandler(ds.getProxy());
ProxyFactory<javax.sql.DataSource, DataSourceDatabase, javax.sql.DataSource, SQLException> proxyFactory = handler.getProxyFactory();
try
{
Connection c1 = proxyFactory.get(db1).getConnection();
try
{
this.createTable(c1);
try
{
Connection c2 = proxyFactory.get(db2).getConnection();
try
{
this.createTable(c2);
try
{
Connection c = ds.getConnection();
try
{
c.setAutoCommit(false);
PreparedStatement ps = c.prepareStatement("INSERT INTO test (id, name) VALUES (?, ?)");
try
{
ps.setInt(1, 1);
ps.setString(2, "1");
ps.addBatch();
ps.setInt(1, 2);
ps.setString(2, "2");
ps.addBatch();
ps.executeBatch();
}
finally
{
Resources.close(ps);
}
c.commit();
this.validate(c1);
this.validate(c2);
}
finally
{
Resources.close(c);
}
}
finally
{
this.dropTable(c2);
}
}
finally
{
c2.close();
}
}
finally
{
this.dropTable(c1);
}
}
finally
{
c1.close();
}
}
finally
{
ds.stop();
}
}