public class DatabaseTablePrefixTest extends TestCase {
public void testPerformDatabaseSchemaOperationCreate() throws Exception{
// both process engines will be using this datasource.
PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(),
"org.h2.Driver",
"jdbc:h2:mem:DatabaseTablePrefixTest;DB_CLOSE_DELAY=1000",
"sa",
"" );
// create two schemas is the database
Connection connection = pooledDataSource.getConnection();
connection.createStatement().execute("drop schema if exists SCHEMA1");
connection.createStatement().execute("drop schema if exists SCHEMA2");
connection.createStatement().execute("create schema SCHEMA1");
connection.createStatement().execute("create schema SCHEMA2");
connection.close();
// configure & build two different process engines, each having a separate table prefix
ProcessEngineConfigurationImpl config1 = createCustomProcessEngineConfiguration()
.setProcessEngineName("DatabaseTablePrefixTest-engine1")
.setDataSource(pooledDataSource)
.setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema
config1.setDatabaseTablePrefix("SCHEMA1.");
ProcessEngine engine1 = config1.buildProcessEngine();
ProcessEngineConfigurationImpl config2 = createCustomProcessEngineConfiguration()
.setProcessEngineName("DatabaseTablePrefixTest-engine2")
.setDataSource(pooledDataSource)
.setDatabaseSchemaUpdate("NO_CHECK"); // disable auto create/drop schema
config2.setDatabaseTablePrefix("SCHEMA2.");
ProcessEngine engine2 = config2.buildProcessEngine();
// create the tables in SCHEMA1
connection = pooledDataSource.getConnection();
connection.createStatement().execute("set schema SCHEMA1");
engine1.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA1");
connection.close();
// create the tables in SCHEMA2
connection = pooledDataSource.getConnection();
connection.createStatement().execute("set schema SCHEMA2");
engine2.getManagementService().databaseSchemaUpgrade(connection, "", "SCHEMA2");
connection.close();
// if I deploy a process to one engine, it is not visible to the other