2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.camunda.bpmn.plugin.urnmap.db;
23 import org.camunda.bpm.engine.ProcessEngineConfiguration;
24 import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
25 import org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration;
26 import org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor;
27 import org.camunda.bpm.engine.impl.interceptor.CommandInterceptor;
28 import org.camunda.bpm.engine.impl.interceptor.LogInterceptor;
29 import org.camunda.bpm.engine.impl.util.ReflectUtil;
31 import java.io.InputStream;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.List;
36 public class MyBatisExtendedSessionFactory extends StandaloneProcessEngineConfiguration {
38 private String resourceName;
40 protected void init() {
41 throw new IllegalArgumentException(
42 "Normal 'init' on process engine only used for extended MyBatis mappings is not allowed, please use 'initFromProcessEngineConfiguration'. You cannot construct a process engine with this configuration.");
46 * initialize the {@link ProcessEngineConfiguration} from an existing one,
47 * just using the database settings and initialize the database / MyBatis
50 public void initFromProcessEngineConfiguration(ProcessEngineConfigurationImpl processEngineConfiguration, String resourceName) {
51 this.resourceName = resourceName;
53 setDatabaseType(processEngineConfiguration.getDatabaseType());
54 setDataSource(processEngineConfiguration.getDataSource());
55 setDatabaseTablePrefix(processEngineConfiguration.getDatabaseTablePrefix());
58 //initVariableTypes();
59 initCommandContextFactory();
60 initTransactionFactory();
61 initTransactionContextFactory();
62 initCommandExecutors();
63 initSqlSessionFactory();
64 initIncidentHandlers();
65 initIdentityProviderSessionFactory();
66 initSessionFactories();
70 * In order to always open a new command context set the property
71 * "alwaysOpenNew" to true inside the CommandContextInterceptor.
73 * If you execute the custom queries inside the process engine
74 * (for example in a service task), you have to do this.
77 protected Collection<? extends CommandInterceptor> getDefaultCommandInterceptorsTxRequired() {
78 List<CommandInterceptor> defaultCommandInterceptorsTxRequired = new ArrayList<CommandInterceptor>();
79 defaultCommandInterceptorsTxRequired.add(new LogInterceptor());
80 defaultCommandInterceptorsTxRequired.add(new CommandContextInterceptor(commandContextFactory, this, true));
81 return defaultCommandInterceptorsTxRequired;
85 protected InputStream getMyBatisXmlConfigurationSteam() {
86 return ReflectUtil.getResourceAsStream(resourceName);