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.mso.bpmn.core.mybatis;
23 import java.io.InputStream;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
28 import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
29 import org.camunda.bpm.engine.impl.cfg.StandaloneProcessEngineConfiguration;
30 import org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor;
31 import org.camunda.bpm.engine.impl.interceptor.CommandInterceptor;
32 import org.camunda.bpm.engine.impl.interceptor.LogInterceptor;
33 import org.camunda.bpm.engine.impl.util.ReflectUtil;
37 * A special process engine that provides access to MyBatis mappings.
40 public class CustomMyBatisSessionFactory extends
41 StandaloneProcessEngineConfiguration {
43 private String resourceName;
46 * Overridden to ensure nobody ever tries to initialize this process engine
47 * in the normal way. We are using this process engine only for MyBatis
51 protected void init() {
52 throw new UnsupportedOperationException("init");
56 * Initialize the ProcessEngineConfiguration from an existing one, just
57 * using the database settings to initialize the database / MyBatis stuff.
59 public void initFromProcessEngineConfiguration(
60 ProcessEngineConfigurationImpl processEngineConfiguration,
61 String resourceName) {
62 this.resourceName = resourceName;
64 setDatabaseType(processEngineConfiguration.getDatabaseType());
65 setDataSource(processEngineConfiguration.getDataSource());
66 setDatabaseTablePrefix(processEngineConfiguration
67 .getDatabaseTablePrefix());
70 // initVariableTypes();
71 initCommandContextFactory();
72 initTransactionFactory();
73 initTransactionContextFactory();
74 initCommandExecutors();
75 initSqlSessionFactory();
76 initIncidentHandlers();
77 initIdentityProviderSessionFactory();
78 initSessionFactories();
82 * In order to always open a new command context set the property
83 * "alwaysOpenNew" to true inside the CommandContextInterceptor.
85 * If you execute the custom queries inside the process engine (for example
86 * in a service task), you have to do this.
89 protected Collection<? extends CommandInterceptor> getDefaultCommandInterceptorsTxRequired() {
90 List<CommandInterceptor> defaultCommandInterceptorsTxRequired =
91 new ArrayList<CommandInterceptor>();
92 defaultCommandInterceptorsTxRequired.add(new LogInterceptor());
93 defaultCommandInterceptorsTxRequired.add(new CommandContextInterceptor(
94 commandContextFactory, this, true));
95 return defaultCommandInterceptorsTxRequired;
99 protected InputStream getMyBatisXmlConfigurationSteam() {
100 return ReflectUtil.getResourceAsStream(resourceName);