bmpn sonar issue fix
[so.git] / bpmn / MSOCoreBPMN / src / main / java / org / openecomp / mso / bpmn / core / CamundaDBSetup.java
1 package org.openecomp.mso.bpmn.core;
2
3 import java.sql.Connection;
4 import java.sql.DriverManager;
5 import java.sql.PreparedStatement;
6 import java.sql.SQLException;
7
8 import org.openecomp.mso.logger.MsoLogger;
9
10 /**
11  * Sets up the unit test (H2) database for Camunda.
12  */
13 public class CamundaDBSetup {
14         private static boolean isDBConfigured = false;
15         private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
16         public static synchronized void configure() throws SQLException {
17                 if (isDBConfigured) {
18                         return;
19                 }
20
21                 System.out.println("Configuring the Camunda H2 database for MSO");
22
23                 Connection connection = null;
24                 PreparedStatement stmt = null;
25
26                 try {
27                         connection = DriverManager.getConnection(
28                                 "jdbc:h2:mem:camunda;DB_CLOSE_DELAY=-1", "sa", "");
29
30                         stmt = connection.prepareStatement("delete from ACT_HI_VARINST");
31                         stmt.executeUpdate();
32                         stmt.close();
33                         stmt = null;
34
35                         stmt = connection.prepareStatement("ALTER TABLE ACT_HI_VARINST alter column TEXT_ clob");
36                         stmt.executeUpdate();
37                         stmt.close();
38                         stmt = null;
39                         
40 //                      stmt = connection.prepareStatement("ALTER TABLE ACT_HI_VARINST alter column NAME_ clob");
41 //                      stmt.executeUpdate();
42 //                      stmt.close();
43 //                      stmt = null;
44
45                         stmt = connection.prepareStatement("delete from ACT_HI_DETAIL");
46                         stmt.executeUpdate();
47                         stmt.close();
48                         stmt = null;
49
50                         stmt = connection.prepareStatement("ALTER TABLE ACT_HI_DETAIL alter column TEXT_ clob");
51                         stmt.executeUpdate();
52                         stmt.close();
53                         stmt = null;
54
55 //                      stmt = connection.prepareStatement("ALTER TABLE ACT_HI_DETAIL alter column NAME_ clob");
56 //                      stmt.executeUpdate();
57 //                      stmt.close();
58 //                      stmt = null;
59
60                         stmt = connection.prepareStatement("ALTER TABLE ACT_RU_VARIABLE alter column TEXT_ clob");
61                         stmt.executeUpdate();
62                         stmt.close();
63                         stmt = null;
64
65                         connection.close();
66                         connection = null;
67
68                         isDBConfigured = true;
69                 } catch (SQLException e) {
70                         System.out.println("CamundaDBSetup caught " + e.getClass().getSimpleName());
71                         LOGGER.debug("SQLException :",e);
72                 } finally {
73                         if (stmt != null) {
74                                 try {
75                                         stmt.close();
76                                 } catch (Exception e) {
77                                         LOGGER.debug("Exception :",e);
78                                 }
79                         }
80
81                         if (connection != null) {
82                                 try {
83                                         connection.close();
84                                 } catch (Exception e) {
85                                         LOGGER.debug("Exception :",e);
86                                 }
87                         }
88                 }
89         }
90 }