[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOURN-plugin / src / main / java / org / openecomp / camunda / bpmn / plugin / urnmap / db / MyBatisExtendedSessionFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.camunda.bpmn.plugin.urnmap.db;
22
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;
30
31 import java.io.InputStream;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.List;
35
36 public class MyBatisExtendedSessionFactory extends StandaloneProcessEngineConfiguration {
37
38   private String resourceName;
39
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.");
43   }
44
45   /**
46    * initialize the {@link ProcessEngineConfiguration} from an existing one,
47    * just using the database settings and initialize the database / MyBatis
48    * stuff.
49    */
50   public void initFromProcessEngineConfiguration(ProcessEngineConfigurationImpl processEngineConfiguration, String resourceName) {
51     this.resourceName = resourceName;
52
53     setDatabaseType(processEngineConfiguration.getDatabaseType());
54     setDataSource(processEngineConfiguration.getDataSource());
55     setDatabaseTablePrefix(processEngineConfiguration.getDatabaseTablePrefix());
56
57     initDataSource();
58     //initVariableTypes();
59     initCommandContextFactory();
60     initTransactionFactory();
61     initTransactionContextFactory();
62     initCommandExecutors();
63     initSqlSessionFactory();
64     initIncidentHandlers();
65     initIdentityProviderSessionFactory();
66     initSessionFactories();
67   }
68
69   /**
70    * In order to always open a new command context set the property
71    * "alwaysOpenNew" to true inside the CommandContextInterceptor.
72    *
73    * If you execute the custom queries inside the process engine
74    * (for example in a service task), you have to do this.
75    */
76   @Override
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;
82   }
83
84   @Override
85   protected InputStream getMyBatisXmlConfigurationSteam() {
86     return ReflectUtil.getResourceAsStream(resourceName);
87   }
88
89 }