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