-
Notifications
You must be signed in to change notification settings - Fork 1
/
_tableActionForBulk.javajet
executable file
·253 lines (250 loc) · 12.3 KB
/
_tableActionForBulk.javajet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<%@ jet
%>
<%
//issue 0010346 Parallelization crash with "Drop table if exists and create"
Boolean isParallelize ="true".equalsIgnoreCase(ElementParameterParser.getValue(node, "__PARALLELIZE__"));
boolean isLog4jEnabled_tableAction = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
if (!isParallelize) {
//end issue 0010346 Parallelization crash with "Drop table if exists and create"
manager = getManager(dbmsId, cid);
manager.setNode(node);
if(!("NONE").equals(tableAction)) {
if(("DROP_CREATE").equals(tableAction)) {
%>
java.sql.Statement stmtDrop_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Droping table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>.");
<%}%>
stmtDrop_<%=cid%>.execute("<%=manager.getDropTableSQL()%>");
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Drop table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
stmtDrop_<%=cid%>.close();
java.sql.Statement stmtCreate_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Creating table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>.");
<%}%>
stmtCreate_<%=cid%>.execute("<%=manager.getCreateTableSQL(stmtStructure)%>)");
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Create table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
stmtCreate_<%=cid%>.close();
<%
} else if(("CREATE").equals(tableAction)) {
%>
java.sql.Statement stmtCreate_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Creating table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>.");
<%}%>
stmtCreate_<%=cid%>.execute("<%=manager.getCreateTableSQL(stmtStructure)%>)");
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Create table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
stmtCreate_<%=cid%>.close();
<%
} else if(("CREATE_TMP").equals(tableAction)) {
%>
java.sql.Statement stmtCreate_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Creating table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>.");
<%}%>
stmtCreate_<%=cid%>.execute(("<%=manager.getCreateTableSQL(stmtStructure)%>)".replaceAll("VARCHAR[(]\\d+?[)]","text")).replaceAll("not null","").replaceAll("CREATE TABLE","CREATE UNLOGGED TABLE "));
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Create table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
stmtCreate_<%=cid%>.close();
<%
}else if(("CREATE_IF_NOT_EXISTS").equals(tableAction) || ("DROP_IF_EXISTS_AND_CREATE").equals(tableAction)) {
boolean tableNameCaseSensitive=false;
if(DB2.equalsIgnoreCase(dbmsId)||GREENPLUM.equalsIgnoreCase(dbmsId)||PARACCEL.equalsIgnoreCase(dbmsId)
||POSTGRESQL.equalsIgnoreCase(dbmsId)||POSTGREPLUS.equalsIgnoreCase(dbmsId)){
tableNameCaseSensitive=true;
}
if (ORACLE.equalsIgnoreCase(dbmsId)) {
%>
<%=manager.generateCode4TabelExist()%>
java.sql.DatabaseMetaData dbMetaData_<%=cid%> = conn_<%=cid%>.getMetaData();
if(tableNameForSearch_<%=cid%>.indexOf("\"")==-1){
tableNameForSearch_<%=cid%> = tableNameForSearch_<%=cid%>.toUpperCase();
}else{
tableNameForSearch_<%=cid%> = tableNameForSearch_<%=cid%>.replaceAll("\"","");
}
java.sql.ResultSet rsTable_<%=cid%> = dbMetaData_<%=cid%>.getTables(null, dbschemaForSearch_<%=cid%>, tableNameForSearch_<%=cid%>, new String[]{"TABLE"});
boolean whetherExist_<%=cid%> = false;
if(rsTable_<%=cid%>.next()) {
whetherExist_<%=cid%> = true;
}
rsTable_<%=cid%>.close();
<%
} else if(SYBASE.equalsIgnoreCase(dbmsId)){
%>
java.sql.DatabaseMetaData dbMetaData_<%=cid%> = conn_<%=cid%>.getMetaData();
java.sql.ResultSet rsTable_<%=cid%> = dbMetaData_<%=cid%>.getTables(null, null, null, new String[]{"TABLE"});
boolean whetherExist_<%=cid%> = false;
while(rsTable_<%=cid%>.next()) {
String table_<%=cid%> = rsTable_<%=cid%>.getString("TABLE_NAME");
String schema_<%=cid%> = rsTable_<%=cid%>.getString("TABLE_SCHEM");
if(table_<%=cid%>.equalsIgnoreCase(<%=table%>)
&& (schema_<%=cid%>.equalsIgnoreCase(dbschema_<%=cid%>) || dbschema_<%=cid%>.trim().length() ==0)) {
whetherExist_<%=cid%> = true;
break;
}
}
rsTable_<%=cid%>.close();
<%
} else if( DB2.equalsIgnoreCase(dbmsId) ){
%>
java.sql.DatabaseMetaData dbMetaData_<%=cid%> = conn_<%=cid%>.getMetaData();
java.sql.ResultSet rsTable_<%=cid%> = dbMetaData_<%=cid%>.getTables(null, null, null, new String[]{"TABLE"});
boolean whetherExist_<%=cid%> = false;
while(rsTable_<%=cid%>.next()) {
String table_<%=cid%> = rsTable_<%=cid%>.getString("TABLE_NAME");
String bkSchema_<%=cid%> = rsTable_<%=cid%>.getString("TABLE_SCHEM");
if(table_<%=cid%>.equals(<%=table%>)
&& (bkSchema_<%=cid%>.equals(schema_<%=cid%>) || (schema_<%=cid%>.trim().length() ==0 && dbUser_<%=cid%>.equalsIgnoreCase(bkSchema_<%=cid%>)))) {
whetherExist_<%=cid%> = true;
break;
}
}
rsTable_<%=cid%>.close();
<%
} else if ( GREENPLUM.equalsIgnoreCase(dbmsId) || POSTGRESQL.equalsIgnoreCase(dbmsId) || POSTGREPLUS.equalsIgnoreCase(dbmsId) || VERTICA.equalsIgnoreCase(dbmsId)) {
%>
java.sql.DatabaseMetaData dbMetaData_<%=cid%> = conn_<%=cid%>.getMetaData();
java.sql.ResultSet rsTable_<%=cid%> = dbMetaData_<%=cid%>.getTables(null, null, null, new String[]{"TABLE"});
boolean whetherExist_<%=cid%> = false;
String defaultSchema_<%=cid%> = "public";
if(dbschema_<%=cid%> == null || dbschema_<%=cid%>.trim().length() == 0) {
java.sql.Statement stmtSchema_<%=cid%> = conn_<%=cid%>.createStatement();
java.sql.ResultSet rsSchema_<%=cid%> = stmtSchema_<%=cid%>.executeQuery("select current_schema() ");
while(rsSchema_<%=cid%>.next()){
defaultSchema_<%=cid%> = rsSchema_<%=cid%>.getString("current_schema");
}
rsSchema_<%=cid%>.close();
stmtSchema_<%=cid%>.close();
}
while(rsTable_<%=cid%>.next()) {
String table_<%=cid%> = rsTable_<%=cid%>.getString("TABLE_NAME");
String schema_<%=cid%> = rsTable_<%=cid%>.getString("TABLE_SCHEM");
if(table_<%=cid%>.equals<%if(!tableNameCaseSensitive){%>IgnoreCase<%}%>(<%=table%>)
&& (schema_<%=cid%>.equals<%if(!tableNameCaseSensitive){%>IgnoreCase<%}%>(dbschema_<%=cid%>) || ((dbschema_<%=cid%> ==null || dbschema_<%=cid%>.trim().length() ==0) && defaultSchema_<%=cid%>.equals<%if(!tableNameCaseSensitive){%>IgnoreCase<%}%>(schema_<%=cid%>)))) {
whetherExist_<%=cid%> = true;
break;
}
}
rsTable_<%=cid%>.close();
<%
} else if(EXASOL.equalsIgnoreCase(dbmsId)) {
%>
String tableForSearch_<%=cid%> = <%=table%>;
if(tableForSearch_<%=cid%> != null){
if(tableForSearch_<%=cid%>.startsWith("\"") && tableForSearch_<%=cid%>.endsWith("\"")){
tableForSearch_<%=cid%> = tableForSearch_<%=cid%>.substring(1,tableForSearch_<%=cid%>.length()-1);
}else{
tableForSearch_<%=cid%> = tableForSearch_<%=cid%>.toUpperCase();
}
}
java.sql.DatabaseMetaData dbMetaData_<%=cid%> = conn_<%=cid%>.getMetaData();
java.sql.ResultSet rsTable_<%=cid%> = dbMetaData_<%=cid%>.getTables(null, conn_<%=cid%>.getSchema(), tableForSearch_<%=cid%>, new String[]{"TABLE"});
boolean whetherExist_<%=cid%> = false;
if(rsTable_<%=cid%>.next()) {
whetherExist_<%=cid%> = true;
}
rsTable_<%=cid%>.close();
<%
} else{
%>
java.sql.DatabaseMetaData dbMetaData_<%=cid%> = conn_<%=cid%>.getMetaData();
java.sql.ResultSet rsTable_<%=cid%> = dbMetaData_<%=cid%>.getTables(null, null, null, new String[]{"TABLE"});
boolean whetherExist_<%=cid%> = false;
while(rsTable_<%=cid%>.next()) {
String table_<%=cid%> = rsTable_<%=cid%>.getString("TABLE_NAME");
if(table_<%=cid%>.equals<%if(!tableNameCaseSensitive){%>IgnoreCase<%}%>(<%=table%>)) {
whetherExist_<%=cid%> = true;
break;
}
}
rsTable_<%=cid%>.close();
<%
}
if(("CREATE_IF_NOT_EXISTS").equals(tableAction)) {
%>
if(!whetherExist_<%=cid%>) {
java.sql.Statement stmtCreate_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Creating table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>.");
<%}%>
stmtCreate_<%=cid%>.execute("<%=manager.getCreateTableSQL(stmtStructure)%>)");
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Create table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
stmtCreate_<%=cid%>.close();
}
<%
} else {
%>
if(whetherExist_<%=cid%>) {
java.sql.Statement stmtDrop_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Droping table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>.");
<%}%>
stmtDrop_<%=cid%>.execute("<%=manager.getDropTableSQL()%>");
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Drop table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
stmtDrop_<%=cid%>.close();
}
java.sql.Statement stmtCreate_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Creating table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>." );
<%}%>
stmtCreate_<%=cid%>.execute("<%=manager.getCreateTableSQL(stmtStructure)%>)");
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Create table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
stmtCreate_<%=cid%>.close();
<%
}
} else if(("CLEAR").equals(tableAction)) {
%>
java.sql.Statement stmtClear_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Clearing table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>.");
<%}%>
stmtClear_<%=cid%>.executeUpdate("<%=manager.getDeleteTableSQL()%>");
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%>- Clear table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
stmtClear_<%=cid%>.close();
<%
}else if(("TRUNCATE").equals(tableAction)) {
%>
java.sql.Statement stmtTruncCount_<%=cid%> = conn_<%=cid%>.createStatement();
java.sql.ResultSet rsTruncCount_<%=cid%> = stmtTruncCount_<%=cid%>.executeQuery("<%=manager.getSelectionSQL()%>");
java.sql.Statement stmtTrunc_<%=cid%> = conn_<%=cid%>.createStatement();
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Trancating table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%>.");
<%}%>
stmtTrunc_<%=cid%>.executeUpdate("<%=manager.getTruncateTableSQL()%>");
<%if(isLog4jEnabled_tableAction){%>
log.info("<%=cid%> - Truncate table <%=manager.getLProtectedChar()%>" + tableName_<%=cid%> + "<%=manager.getRProtectedChar()%> has succeeded.");
<%}%>
while(rsTruncCount_<%=cid%>.next()) {
deletedCount_<%=cid%> += rsTruncCount_<%=cid%>.getInt(1);
}
rsTruncCount_<%=cid%>.close();
stmtTruncCount_<%=cid%>.close();
stmtTrunc_<%=cid%>.close();
<%
}
%>
//in mysql when autoCommit=true don't commit.
if (! conn_<%=cid%>.getAutoCommit()) {
conn_<%=cid%>.commit();
}
<%
}
//issue 0010346 Parallelization crash with "Drop table if exists and create"
}
//end issue 0010346 Parallelization crash with "Drop table if exists and create"
%>