f7cc311e77eba892fbbe273ee4e2b830c4b5330e
[so.git] / bpmn / MSOURN-plugin / src / main / java / org / openecomp / camunda / bpmn / plugin / urnmap / db / MyBatisExtendedSessionFactory.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * OPENECOMP - MSO\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
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \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
19  */\r
20 \r
21 package org.openecomp.camunda.bpmn.plugin.urnmap.db;\r
22 \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
30 \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
35 \r
36 public class MyBatisExtendedSessionFactory extends StandaloneProcessEngineConfiguration {\r
37 \r
38   private String resourceName;\r
39 \r
40   protected void init() {\r
41     throw new IllegalArgumentException(\r
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.");\r
43   }\r
44 \r
45   /**\r
46    * initialize the {@link ProcessEngineConfiguration} from an existing one,\r
47    * just using the database settings and initialize the database / MyBatis\r
48    * stuff.\r
49    */\r
50   public void initFromProcessEngineConfiguration(ProcessEngineConfigurationImpl processEngineConfiguration, String resourceName) {\r
51     this.resourceName = resourceName;\r
52 \r
53     setDatabaseType(processEngineConfiguration.getDatabaseType());\r
54     setDataSource(processEngineConfiguration.getDataSource());\r
55     setDatabaseTablePrefix(processEngineConfiguration.getDatabaseTablePrefix());\r
56 \r
57     initDataSource();\r
58     //initVariableTypes();\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
67   }\r
68 \r
69   /**\r
70    * In order to always open a new command context set the property\r
71    * "alwaysOpenNew" to true inside the CommandContextInterceptor.\r
72    *\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
75    */\r
76   @Override\r
77   protected Collection<? extends CommandInterceptor> getDefaultCommandInterceptorsTxRequired() {\r
78     List<CommandInterceptor> defaultCommandInterceptorsTxRequired = new ArrayList<CommandInterceptor>();\r
79     defaultCommandInterceptorsTxRequired.add(new LogInterceptor());\r
80     defaultCommandInterceptorsTxRequired.add(new CommandContextInterceptor(commandContextFactory, this, true));\r
81     return defaultCommandInterceptorsTxRequired;\r
82   }\r
83 \r
84   @Override\r
85   protected InputStream getMyBatisXmlConfigurationSteam() {\r
86     return ReflectUtil.getResourceAsStream(resourceName);\r
87   }\r
88 \r
89 }\r