aba43eb52275bc61727749f9cd7c97c26b2170b0
[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 /**
9  * Sets up the unit test (H2) database for Camunda.
10  */
11 public class CamundaDBSetup {
12         private static boolean isDBConfigured = false;
13
14         public static synchronized void configure() throws SQLException {
15                 if (isDBConfigured) {
16                         return;
17                 }
18
19                 System.out.println("Configuring the Camunda H2 database for MSO");
20
21                 Connection connection = null;
22                 PreparedStatement stmt = null;
23
24                 try {
25                         connection = DriverManager.getConnection(
26                                 "jdbc:h2:mem:camunda;DB_CLOSE_DELAY=-1", "sa", "");
27
28                         stmt = connection.prepareStatement("delete from ACT_HI_VARINST");
29                         stmt.executeUpdate();
30                         stmt.close();
31                         stmt = null;
32
33                         stmt = connection.prepareStatement("ALTER TABLE ACT_HI_VARINST alter column TEXT_ clob");
34                         stmt.executeUpdate();
35                         stmt.close();
36                         stmt = null;
37                         
38 //                      stmt = connection.prepareStatement("ALTER TABLE ACT_HI_VARINST alter column NAME_ clob");
39 //                      stmt.executeUpdate();
40 //                      stmt.close();
41 //                      stmt = null;
42
43                         stmt = connection.prepareStatement("delete from ACT_HI_DETAIL");
44                         stmt.executeUpdate();
45                         stmt.close();
46                         stmt = null;
47
48                         stmt = connection.prepareStatement("ALTER TABLE ACT_HI_DETAIL alter column TEXT_ clob");
49                         stmt.executeUpdate();
50                         stmt.close();
51                         stmt = null;
52
53 //                      stmt = connection.prepareStatement("ALTER TABLE ACT_HI_DETAIL alter column NAME_ clob");
54 //                      stmt.executeUpdate();
55 //                      stmt.close();
56 //                      stmt = null;
57
58                         stmt = connection.prepareStatement("ALTER TABLE ACT_RU_VARIABLE alter column TEXT_ clob");
59                         stmt.executeUpdate();
60                         stmt.close();
61                         stmt = null;
62
63                         connection.close();
64                         connection = null;
65
66                         isDBConfigured = true;
67                 } catch (SQLException e) {
68                         System.out.println("CamundaDBSetup caught " + e.getClass().getSimpleName());
69                         e.printStackTrace();
70                 } finally {
71                         if (stmt != null) {
72                                 try {
73                                         stmt.close();
74                                 } catch (Exception e) {
75                                         // Ignore
76                                 }
77                         }
78
79                         if (connection != null) {
80                                 try {
81                                         connection.close();
82                                 } catch (Exception e) {
83                                         // Ignore
84                                 }
85                         }
86                 }
87         }
88 }