Added @Override annotation to method signature
[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         
17         private CamundaDBSetup() {
18             /**
19              * Constructor.
20              */
21         }
22         
23         public static synchronized void configure() throws SQLException {
24                 if (isDBConfigured) {
25                         return;
26                 }
27
28                 LOGGER.debug ("Configuring the Camunda H2 database for MSO");
29
30                 Connection connection = null;
31                 PreparedStatement stmt = null;
32
33                 try {
34                         connection = DriverManager.getConnection(
35                                 "jdbc:h2:mem:camunda;DB_CLOSE_DELAY=-1", "sa", "");
36
37                         stmt = connection.prepareStatement("delete from ACT_HI_VARINST");
38                         stmt.executeUpdate();
39                         stmt.close();
40                         stmt = null;
41
42                         stmt = connection.prepareStatement("ALTER TABLE ACT_HI_VARINST alter column TEXT_ clob");
43                         stmt.executeUpdate();
44                         stmt.close();
45                         stmt = null;
46                         
47 //                      stmt = connection.prepareStatement("ALTER TABLE ACT_HI_VARINST alter column NAME_ clob");
48 //                      stmt.executeUpdate();
49 //                      stmt.close();
50 //                      stmt = null;
51
52                         stmt = connection.prepareStatement("delete from ACT_HI_DETAIL");
53                         stmt.executeUpdate();
54                         stmt.close();
55                         stmt = null;
56
57                         stmt = connection.prepareStatement("ALTER TABLE ACT_HI_DETAIL alter column TEXT_ clob");
58                         stmt.executeUpdate();
59                         stmt.close();
60                         stmt = null;
61
62 //                      stmt = connection.prepareStatement("ALTER TABLE ACT_HI_DETAIL alter column NAME_ clob");
63 //                      stmt.executeUpdate();
64 //                      stmt.close();
65 //                      stmt = null;
66
67                         stmt = connection.prepareStatement("ALTER TABLE ACT_RU_VARIABLE alter column TEXT_ clob");
68                         stmt.executeUpdate();
69                         stmt.close();
70                         stmt = null;
71
72                         connection.close();
73                         connection = null;
74
75                         isDBConfigured = true;
76                 } catch (SQLException e) {
77                     LOGGER.debug ("CamundaDBSetup caught " + e.getClass().getSimpleName());
78                         LOGGER.debug("SQLException :",e);
79                 } finally {
80                         if (stmt != null) {
81                                 try {
82                                         stmt.close();
83                                 } catch (Exception e) {
84                                         LOGGER.debug("Exception :",e);
85                                 }
86                         }
87
88                         if (connection != null) {
89                                 try {
90                                         connection.close();
91                                 } catch (Exception e) {
92                                         LOGGER.debug("Exception :",e);
93                                 }
94                         }
95                 }
96         }
97 }