org.flowable.idm.spring.SpringIdmEngineConfiguration Maven / Gradle / Ivy
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.idm.spring;
import javax.sql.DataSource;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
import org.flowable.common.engine.impl.interceptor.CommandInterceptor;
import org.flowable.idm.engine.IdmEngine;
import org.flowable.idm.engine.IdmEngineConfiguration;
import org.flowable.idm.engine.IdmEngines;
import org.flowable.idm.engine.impl.cfg.StandaloneIdmEngineConfiguration;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
import org.springframework.transaction.PlatformTransactionManager;
/**
* @author Tijs Rademakers
* @author David Syer
* @author Joram Barrez
*/
public class SpringIdmEngineConfiguration extends IdmEngineConfiguration implements ApplicationContextAware {
protected PlatformTransactionManager transactionManager;
protected ApplicationContext applicationContext;
protected Integer transactionSynchronizationAdapterOrder;
public SpringIdmEngineConfiguration() {
this.transactionsExternallyManaged = true;
}
@Override
public IdmEngine buildIdmEngine() {
IdmEngine idmEngine = super.buildIdmEngine();
IdmEngines.setInitialized(true);
return idmEngine;
}
public void setTransactionSynchronizationAdapterOrder(Integer transactionSynchronizationAdapterOrder) {
this.transactionSynchronizationAdapterOrder = transactionSynchronizationAdapterOrder;
}
@Override
public void initDefaultCommandConfig() {
if (defaultCommandConfig == null) {
defaultCommandConfig = new CommandConfig().setContextReusePossible(true);
}
}
@Override
public CommandInterceptor createTransactionInterceptor() {
if (transactionManager == null) {
throw new FlowableException("transactionManager is required property for SpringIdmEngineConfiguration, use " + StandaloneIdmEngineConfiguration.class.getName() + " otherwise");
}
return new SpringTransactionInterceptor(transactionManager);
}
@Override
public void initTransactionContextFactory() {
if (transactionContextFactory == null && transactionManager != null) {
transactionContextFactory = new SpringTransactionContextFactory(transactionManager, transactionSynchronizationAdapterOrder);
}
}
@Override
public IdmEngineConfiguration setDataSource(DataSource dataSource) {
if (dataSource instanceof TransactionAwareDataSourceProxy) {
return (IdmEngineConfiguration) super.setDataSource(dataSource);
} else {
// Wrap datasource in Transaction-aware proxy
DataSource proxiedDataSource = new TransactionAwareDataSourceProxy(dataSource);
return (IdmEngineConfiguration) super.setDataSource(proxiedDataSource);
}
}
public PlatformTransactionManager getTransactionManager() {
return transactionManager;
}
public void setTransactionManager(PlatformTransactionManager transactionManager) {
this.transactionManager = transactionManager;
}
public ApplicationContext getApplicationContext() {
return applicationContext;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy