Skip to content

Commit

Permalink
Make sure that the DbSchemaDrop closes the DB once it is done + reuse…
Browse files Browse the repository at this point in the history
… DB between process and cmmn engine in cmmn engine configurator + null check in SpringAutoDeployTest
  • Loading branch information
filiphr committed Jul 15, 2024
1 parent c907daa commit 5cfb809
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@

package org.flowable.app.engine.impl.db;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;

import javax.sql.DataSource;

import org.flowable.app.engine.AppEngine;
import org.flowable.app.engine.AppEngineConfiguration;
import org.flowable.app.engine.test.FlowableAppTestCase;
import org.flowable.common.engine.impl.db.SchemaOperationsEngineDropDbCmd;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.common.engine.impl.test.ClosingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,14 +37,28 @@ public class DbSchemaDrop {
private static final Logger LOGGER = LoggerFactory.getLogger(DbSchemaDrop.class);

public static void main(String[] args) {
AppEngine appEngine = null;
try (InputStream inputStream = FlowableAppTestCase.class.getClassLoader().getResourceAsStream("flowable.app.cfg.xml")) {
AppEngine cmmnEngine = AppEngineConfiguration.createAppEngineConfigurationFromInputStream(inputStream).buildAppEngine();
CommandExecutor commandExecutor = cmmnEngine.getAppEngineConfiguration().getCommandExecutor();
appEngine = AppEngineConfiguration.createAppEngineConfigurationFromInputStream(inputStream).buildAppEngine();
CommandExecutor commandExecutor = appEngine.getAppEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(cmmnEngine.getAppEngineConfiguration().getEngineScopeType()));
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(appEngine.getAppEngineConfiguration().getEngineScopeType()));

} catch (IOException e) {
LOGGER.error("Could not create App engine", e);
} finally {
if (appEngine != null) {
DataSource dataSource = appEngine.getAppEngineConfiguration().getDataSource();
if (dataSource instanceof Closeable) {
try {
((Closeable) dataSource).close();
} catch (IOException e) {
// Ignored
}
} else if (dataSource instanceof ClosingDataSource) {
((ClosingDataSource) dataSource).onEngineClosed(appEngine);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
*/
package org.flowable.cmmn.test;

import java.io.Closeable;
import java.io.IOException;

import javax.sql.DataSource;

import org.flowable.common.engine.impl.db.SchemaOperationsEngineDropDbCmd;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.common.engine.impl.test.ClosingDataSource;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.impl.ProcessEngineImpl;

Expand All @@ -24,10 +30,26 @@
public class DbSchemaDrop {

public static void main(String[] args) {
ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(processEngine.getProcessEngineConfiguration().getEngineScopeType()));
ProcessEngineImpl processEngine = null;
try {
processEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(processEngine.getProcessEngineConfiguration().getEngineScopeType()));
} finally {
if (processEngine != null) {
DataSource dataSource = processEngine.getProcessEngineConfiguration().getDataSource();
if (dataSource instanceof Closeable) {
try {
((Closeable) dataSource).close();
} catch (IOException e) {
// Ignored
}
} else if (dataSource instanceof ClosingDataSource) {
((ClosingDataSource) dataSource).onEngineClosed(processEngine);
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="dataSource" class="org.flowable.common.engine.impl.test.ClosingDataSource">
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg>
<bean class="com.zaxxer.hikari.HikariConfig">
<property name="minimumIdle" value="0" />
<property name="jdbcUrl" value="${jdbc.url:jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000}"/>
<property name="driverClassName" value="${jdbc.driver:org.h2.Driver}"/>
<property name="username" value="${jdbc.username:sa}"/>
<property name="password" value="${jdbc.password:}"/>
</bean>
</constructor-arg>
</bean>
</constructor-arg>
</bean>

<bean id="processEngineConfiguration" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="${jdbc.url:jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000}" />
<property name="jdbcDriver" value="${jdbc.driver:org.h2.Driver}" />
<property name="jdbcUsername" value="${jdbc.username:sa}" />
<property name="jdbcPassword" value="${jdbc.password:}" />
<property name="dataSource" ref="dataSource" />
<property name="engineLifecycleListeners">
<list>
<ref bean="dataSource"/>
</list>
</property>
<property name="databaseSchemaUpdate" value="true" />

<property name="asyncExecutorActivate" value="false" />
Expand All @@ -30,10 +48,7 @@
</bean>

<bean id="cmmnEngineConfiguration" class="org.flowable.cmmn.engine.CmmnEngineConfiguration">
<property name="jdbcUrl" value="${jdbc.url:jdbc:h2:mem:flowable;DB_CLOSE_DELAY=1000}" />
<property name="jdbcDriver" value="${jdbc.driver:org.h2.Driver}" />
<property name="jdbcUsername" value="${jdbc.username:sa}" />
<property name="jdbcPassword" value="${jdbc.password:}" />
<property name="dataSource" ref="dataSource" />
<property name="databaseSchemaUpdate" value="true" />

<property name="asyncExecutorActivate" value="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@

package org.flowable.cmmn.engine.impl.db;

import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;

import javax.sql.DataSource;

import org.flowable.cmmn.engine.CmmnEngine;
import org.flowable.cmmn.engine.CmmnEngineConfiguration;
import org.flowable.cmmn.engine.test.FlowableCmmnTestCase;
import org.flowable.common.engine.impl.db.SchemaOperationsEngineDropDbCmd;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.common.engine.impl.test.ClosingDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -33,14 +37,28 @@ public class DbSchemaDrop {
private static final Logger LOGGER = LoggerFactory.getLogger(DbSchemaDrop.class);

public static void main(String[] args) {
CmmnEngine cmmnEngine = null;
try (InputStream inputStream = FlowableCmmnTestCase.class.getClassLoader().getResourceAsStream("flowable.cmmn.cfg.xml")) {
CmmnEngine cmmnEngine = CmmnEngineConfiguration.createCmmnEngineConfigurationFromInputStream(inputStream).buildCmmnEngine();
cmmnEngine = CmmnEngineConfiguration.createCmmnEngineConfigurationFromInputStream(inputStream).buildCmmnEngine();
CommandExecutor commandExecutor = cmmnEngine.getCmmnEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(cmmnEngine.getCmmnEngineConfiguration().getEngineScopeType()));

} catch (IOException e) {
LOGGER.error("Could not create CMMN engine", e);
} finally {
if (cmmnEngine != null) {
DataSource dataSource = cmmnEngine.getCmmnEngineConfiguration().getDataSource();
if (dataSource instanceof Closeable) {
try {
((Closeable) dataSource).close();
} catch (IOException e) {
// Ignored
}
} else if (dataSource instanceof ClosingDataSource) {
((ClosingDataSource) dataSource).onEngineClosed(cmmnEngine);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@

package org.flowable.dmn.engine.impl.db;

import java.io.Closeable;
import java.io.IOException;

import javax.sql.DataSource;

import org.flowable.common.engine.impl.db.SchemaOperationsEngineDropDbCmd;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.common.engine.impl.test.ClosingDataSource;
import org.flowable.dmn.engine.DmnEngines;
import org.flowable.dmn.engine.impl.DmnEngineImpl;

Expand All @@ -25,9 +31,25 @@
public class DbSchemaDrop {

public static void main(String[] args) {
DmnEngineImpl dmnEngine = (DmnEngineImpl) DmnEngines.getDefaultDmnEngine();
CommandExecutor commandExecutor = dmnEngine.getDmnEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(dmnEngine.getDmnEngineConfiguration().getEngineScopeType()));
DmnEngineImpl dmnEngine = null;
try {
dmnEngine = (DmnEngineImpl) DmnEngines.getDefaultDmnEngine();
CommandExecutor commandExecutor = dmnEngine.getDmnEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(dmnEngine.getDmnEngineConfiguration().getEngineScopeType()));
} finally {
if (dmnEngine != null) {
DataSource dataSource = dmnEngine.getDmnEngineConfiguration().getDataSource();
if (dataSource instanceof Closeable) {
try {
((Closeable) dataSource).close();
} catch (IOException e) {
// Ignored
}
} else if (dataSource instanceof ClosingDataSource) {
((ClosingDataSource) dataSource).onEngineClosed(dmnEngine);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@

package org.flowable.engine.impl.db;

import java.io.Closeable;
import java.io.IOException;

import javax.sql.DataSource;

import org.flowable.common.engine.impl.db.SchemaOperationsEngineDropDbCmd;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.common.engine.impl.test.ClosingDataSource;
import org.flowable.engine.ProcessEngines;
import org.flowable.engine.impl.ProcessEngineImpl;

Expand All @@ -29,5 +35,15 @@ public static void main(String[] args) {
CommandExecutor commandExecutor = processEngine.getProcessEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(processEngine.getProcessEngineConfiguration().getEngineScopeType()));
DataSource dataSource = processEngine.getProcessEngineConfiguration().getDataSource();
if (dataSource instanceof Closeable) {
try {
((Closeable) dataSource).close();
} catch (IOException e) {
// Ignored
}
} else if (dataSource instanceof ClosingDataSource) {
((ClosingDataSource) dataSource).onEngineClosed(processEngine);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@

package org.flowable.eventregistry.impl.db;

import java.io.Closeable;
import java.io.IOException;

import javax.sql.DataSource;

import org.flowable.common.engine.impl.db.SchemaOperationsEngineDropDbCmd;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.common.engine.impl.test.ClosingDataSource;
import org.flowable.eventregistry.impl.EventRegistryEngineImpl;
import org.flowable.eventregistry.impl.EventRegistryEngines;

Expand All @@ -25,9 +31,26 @@
public class DbSchemaDrop {

public static void main(String[] args) {
EventRegistryEngineImpl eventRegistryEngine = (EventRegistryEngineImpl) EventRegistryEngines.getDefaultEventRegistryEngine();
CommandExecutor commandExecutor = eventRegistryEngine.getEventRegistryEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(eventRegistryEngine.getEventRegistryEngineConfiguration().getEngineScopeType()));
EventRegistryEngineImpl eventRegistryEngine = null;
try {
eventRegistryEngine = (EventRegistryEngineImpl) EventRegistryEngines.getDefaultEventRegistryEngine();
CommandExecutor commandExecutor = eventRegistryEngine.getEventRegistryEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config,
new SchemaOperationsEngineDropDbCmd(eventRegistryEngine.getEventRegistryEngineConfiguration().getEngineScopeType()));
} finally {
if (eventRegistryEngine != null) {
DataSource dataSource = eventRegistryEngine.getEventRegistryEngineConfiguration().getDataSource();
if (dataSource instanceof Closeable) {
try {
((Closeable) dataSource).close();
} catch (IOException e) {
// Ignored
}
} else if (dataSource instanceof ClosingDataSource) {
((ClosingDataSource) dataSource).onEngineClosed(eventRegistryEngine);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@

package org.flowable.idm.engine.impl.db;

import java.io.Closeable;
import java.io.IOException;

import javax.sql.DataSource;

import org.flowable.common.engine.impl.db.SchemaOperationsEngineDropDbCmd;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
import org.flowable.common.engine.impl.test.ClosingDataSource;
import org.flowable.idm.engine.IdmEngine;
import org.flowable.idm.engine.IdmEngines;

Expand All @@ -25,9 +31,25 @@
public class DbSchemaDrop {

public static void main(String[] args) {
IdmEngine idmEngine = IdmEngines.getDefaultIdmEngine();
CommandExecutor commandExecutor = idmEngine.getIdmEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(idmEngine.getIdmEngineConfiguration().getEngineScopeType()));
IdmEngine idmEngine = null;
try {
idmEngine = IdmEngines.getDefaultIdmEngine();
CommandExecutor commandExecutor = idmEngine.getIdmEngineConfiguration().getCommandExecutor();
CommandConfig config = new CommandConfig().transactionNotSupported();
commandExecutor.execute(config, new SchemaOperationsEngineDropDbCmd(idmEngine.getIdmEngineConfiguration().getEngineScopeType()));
} finally {
if (idmEngine != null) {
DataSource dataSource = idmEngine.getIdmEngineConfiguration().getDataSource();
if (dataSource instanceof Closeable) {
try {
((Closeable) dataSource).close();
} catch (IOException e) {
// Ignored
}
} else if (dataSource instanceof ClosingDataSource) {
((ClosingDataSource) dataSource).onEngineClosed(idmEngine);
}
}
}
}
}
Loading

0 comments on commit 5cfb809

Please sign in to comment.