embulk-output-oracle 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +155 -110
- data/build.gradle +6 -6
- data/classpath/embulk-output-jdbc-0.3.0.jar +0 -0
- data/classpath/embulk-output-oracle-0.3.0.jar +0 -0
- data/lib/embulk/output/oracle.rb +3 -3
- data/src/main/cpp/common/dir-path-load.cpp +424 -424
- data/src/main/cpp/common/dir-path-load.h +36 -36
- data/src/main/cpp/common/embulk-output-oracle.cpp +196 -196
- data/src/main/cpp/common/org_embulk_output_oracle_oci_OCI.h +77 -77
- data/src/main/cpp/linux/build.sh +21 -21
- data/src/main/cpp/win/build.bat +31 -31
- data/src/main/cpp/win/dllmain.cpp +25 -25
- data/src/main/cpp/win/embulk-output-oracle.sln +39 -39
- data/src/main/cpp/win/embulk-output-oracle.vcxproj +175 -175
- data/src/main/java/org/embulk/output/OracleOutputPlugin.java +22 -66
- data/src/main/java/org/embulk/output/oracle/DirectBatchInsert.java +289 -289
- data/src/main/java/org/embulk/output/oracle/InsertMethod.java +8 -8
- data/src/main/java/org/embulk/output/oracle/OracleCharset.java +32 -19
- data/src/main/java/org/embulk/output/oracle/OracleOutputConnection.java +165 -134
- data/src/main/java/org/embulk/output/oracle/OracleOutputConnector.java +49 -49
- data/src/main/java/org/embulk/output/oracle/TimestampFormat.java +37 -37
- data/src/main/java/org/embulk/output/oracle/oci/ColumnDefinition.java +26 -26
- data/src/main/java/org/embulk/output/oracle/oci/OCI.java +139 -139
- data/src/main/java/org/embulk/output/oracle/oci/OCIManager.java +64 -64
- data/src/main/java/org/embulk/output/oracle/oci/OCIWrapper.java +96 -96
- data/src/main/java/org/embulk/output/oracle/oci/RowBuffer.java +99 -99
- data/src/main/java/org/embulk/output/oracle/oci/TableDefinition.java +24 -24
- data/src/test/cpp/common/embulk-output-oracle-test.cpp +69 -69
- data/src/test/cpp/linux/build.sh +19 -19
- data/src/test/cpp/win/build.bat +28 -28
- data/src/test/cpp/win/embulk-output-oracle-test.vcxproj +154 -154
- data/src/test/java/org/embulk/input/filesplit/LocalFileSplitInputPlugin.java +187 -187
- data/src/test/java/org/embulk/input/filesplit/PartialFile.java +49 -49
- data/src/test/java/org/embulk/input/filesplit/PartialFileInputStream.java +154 -154
- data/src/test/java/org/embulk/output/oracle/ChildFirstClassLoader.java +42 -42
- data/src/test/java/org/embulk/output/oracle/EmbulkPluginTester.java +120 -120
- data/src/test/java/org/embulk/output/oracle/EmptyConfigSource.java +100 -100
- data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTest.java +172 -161
- data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTestImpl.java +445 -413
- data/src/test/java/org/embulk/output/oracle/TimestampFormatTest.java +57 -57
- data/src/test/resources/data/test1/test1.csv +3 -3
- data/src/test/resources/yml/test-insert-direct.yml +26 -26
- data/src/test/resources/yml/test-insert-oci-split.yml +26 -26
- data/src/test/resources/yml/test-insert-oci.yml +26 -26
- data/src/test/resources/yml/test-insert.yml +25 -25
- data/src/test/resources/yml/test-replace-long-name-multibyte.yml +25 -0
- data/src/test/resources/yml/test-replace-long-name.yml +25 -25
- data/src/test/resources/yml/test-replace.yml +25 -25
- data/src/test/resources/yml/test-string-timestamp.yml +25 -0
- data/src/test/resources/yml/test-url.yml +24 -24
- metadata +6 -5
- data/classpath/embulk-output-jdbc-0.2.4.jar +0 -0
- data/classpath/embulk-output-oracle-0.2.4.jar +0 -0
- data/src/main/java/org/embulk/output/oracle/setter/OracleColumnSetterFactory.java +0 -31
@@ -1,413 +1,445 @@
|
|
1
|
-
package org.embulk.output.oracle;
|
2
|
-
|
3
|
-
import static org.junit.Assert.assertEquals;
|
4
|
-
|
5
|
-
import java.io.BufferedReader;
|
6
|
-
import java.io.BufferedWriter;
|
7
|
-
import java.io.File;
|
8
|
-
import java.io.FileReader;
|
9
|
-
import java.io.FileWriter;
|
10
|
-
import java.io.IOException;
|
11
|
-
import java.lang.reflect.Constructor;
|
12
|
-
import java.math.BigDecimal;
|
13
|
-
import java.net.URISyntaxException;
|
14
|
-
import java.sql.Connection;
|
15
|
-
import java.sql.DriverManager;
|
16
|
-
import java.sql.ResultSet;
|
17
|
-
import java.sql.SQLException;
|
18
|
-
import java.sql.Statement;
|
19
|
-
import java.sql.Timestamp;
|
20
|
-
import java.text.DateFormat;
|
21
|
-
import java.text.ParseException;
|
22
|
-
import java.text.SimpleDateFormat;
|
23
|
-
import java.util.ArrayList;
|
24
|
-
import java.util.Collections;
|
25
|
-
import java.util.Comparator;
|
26
|
-
import java.util.Date;
|
27
|
-
import java.util.Iterator;
|
28
|
-
import java.util.List;
|
29
|
-
import java.util.TimeZone;
|
30
|
-
import java.util.regex.Matcher;
|
31
|
-
import java.util.regex.Pattern;
|
32
|
-
|
33
|
-
import org.embulk.input.filesplit.LocalFileSplitInputPlugin;
|
34
|
-
import org.embulk.output.OracleOutputPlugin;
|
35
|
-
import org.embulk.spi.InputPlugin;
|
36
|
-
import org.embulk.spi.OutputPlugin;
|
37
|
-
|
38
|
-
|
39
|
-
public class OracleOutputPluginTestImpl
|
40
|
-
{
|
41
|
-
private EmbulkPluginTester tester = new EmbulkPluginTester(OutputPlugin.class, "oracle", OracleOutputPlugin.class);
|
42
|
-
|
43
|
-
|
44
|
-
public String beforeClass()
|
45
|
-
{
|
46
|
-
try {
|
47
|
-
Class.forName("oracle.jdbc.OracleDriver");
|
48
|
-
|
49
|
-
try (Connection connection = connect()) {
|
50
|
-
String version = connection.getMetaData().getDriverVersion();
|
51
|
-
System.out.println("Driver version = " + version);
|
52
|
-
return version;
|
53
|
-
}
|
54
|
-
|
55
|
-
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
56
|
-
//throw new RuntimeException("You should put Oracle JDBC driver on 'driver' directory.");
|
57
|
-
System.err.println("Warning: put Oracle JDBC driver on 'driver' directory in order to test embulk-output-oracle plugin.");
|
58
|
-
|
59
|
-
} catch (SQLException e) {
|
60
|
-
System.err.println(e);
|
61
|
-
//throw new RuntimeException("You should prepare a schema on Oracle (database = 'TESTDB', user = 'TEST_USER', password = 'test_pw').");
|
62
|
-
System.err.println("Warning: prepare a schema on Oracle (database = 'TESTDB', user = 'TEST_USER', password = 'test_pw').");
|
63
|
-
// for example
|
64
|
-
// CREATE USER EMBULK_USER IDENTIFIED BY "embulk_pw";
|
65
|
-
// GRANT DBA TO EMBULK_USER;
|
66
|
-
}
|
67
|
-
|
68
|
-
return null;
|
69
|
-
}
|
70
|
-
|
71
|
-
|
72
|
-
public void testInsert() throws Exception
|
73
|
-
{
|
74
|
-
String table = "TEST1";
|
75
|
-
|
76
|
-
dropTable(table);
|
77
|
-
createTable(table);
|
78
|
-
|
79
|
-
run("/yml/test-insert.yml");
|
80
|
-
|
81
|
-
assertTable(table);
|
82
|
-
}
|
83
|
-
|
84
|
-
public void testInsertCreate() throws Exception
|
85
|
-
{
|
86
|
-
String table = "TEST1";
|
87
|
-
|
88
|
-
dropTable(table);
|
89
|
-
|
90
|
-
run("/yml/test-insert.yml");
|
91
|
-
|
92
|
-
assertGeneratedTable(table);
|
93
|
-
}
|
94
|
-
|
95
|
-
public void testInsertDirect() throws Exception
|
96
|
-
{
|
97
|
-
String table = "TEST1";
|
98
|
-
|
99
|
-
dropTable(table);
|
100
|
-
createTable(table);
|
101
|
-
|
102
|
-
run("/yml/test-insert-direct.yml");
|
103
|
-
|
104
|
-
assertTable(table);
|
105
|
-
}
|
106
|
-
|
107
|
-
public void testInsertOCI() throws Exception
|
108
|
-
{
|
109
|
-
String table = "TEST1";
|
110
|
-
|
111
|
-
dropTable(table);
|
112
|
-
createTable(table);
|
113
|
-
|
114
|
-
run("/yml/test-insert-oci.yml");
|
115
|
-
|
116
|
-
assertTable(table);
|
117
|
-
}
|
118
|
-
|
119
|
-
public void testInsertOCISplit() throws Exception
|
120
|
-
{
|
121
|
-
tester.addPlugin(InputPlugin.class, "filesplit", LocalFileSplitInputPlugin.class);
|
122
|
-
|
123
|
-
String table = "TEST1";
|
124
|
-
|
125
|
-
dropTable(table);
|
126
|
-
createTable(table);
|
127
|
-
|
128
|
-
run("/yml/test-insert-oci-split.yml");
|
129
|
-
|
130
|
-
assertTable(table);
|
131
|
-
}
|
132
|
-
|
133
|
-
public void testUrl() throws Exception
|
134
|
-
{
|
135
|
-
String table = "TEST1";
|
136
|
-
|
137
|
-
dropTable(table);
|
138
|
-
createTable(table);
|
139
|
-
|
140
|
-
run("/yml/test-url.yml");
|
141
|
-
|
142
|
-
assertTable(table);
|
143
|
-
}
|
144
|
-
|
145
|
-
public void testReplace() throws Exception
|
146
|
-
{
|
147
|
-
String table = "TEST1";
|
148
|
-
|
149
|
-
dropTable(table);
|
150
|
-
createTable(table);
|
151
|
-
|
152
|
-
run("/yml/test-replace.yml");
|
153
|
-
|
154
|
-
assertGeneratedTable(table);
|
155
|
-
}
|
156
|
-
|
157
|
-
public void testReplaceCreate() throws Exception
|
158
|
-
{
|
159
|
-
String table = "TEST1";
|
160
|
-
|
161
|
-
dropTable(table);
|
162
|
-
|
163
|
-
run("/yml/test-replace.yml");
|
164
|
-
|
165
|
-
assertGeneratedTable(table);
|
166
|
-
}
|
167
|
-
|
168
|
-
|
169
|
-
public void testReplaceLongName() throws Exception
|
170
|
-
{
|
171
|
-
String table = "TEST12345678901234567890123456";
|
172
|
-
|
173
|
-
dropTable(table);
|
174
|
-
createTable(table);
|
175
|
-
|
176
|
-
run("/yml/test-replace-long-name.yml");
|
177
|
-
|
178
|
-
assertGeneratedTable(table);
|
179
|
-
}
|
180
|
-
|
181
|
-
|
182
|
-
{
|
183
|
-
String
|
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
|
-
|
254
|
-
|
255
|
-
assertEquals("
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
assertEquals(
|
260
|
-
assertEquals(
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
assertEquals(
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
try
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
}
|
405
|
-
|
406
|
-
private
|
407
|
-
{
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
1
|
+
package org.embulk.output.oracle;
|
2
|
+
|
3
|
+
import static org.junit.Assert.assertEquals;
|
4
|
+
|
5
|
+
import java.io.BufferedReader;
|
6
|
+
import java.io.BufferedWriter;
|
7
|
+
import java.io.File;
|
8
|
+
import java.io.FileReader;
|
9
|
+
import java.io.FileWriter;
|
10
|
+
import java.io.IOException;
|
11
|
+
import java.lang.reflect.Constructor;
|
12
|
+
import java.math.BigDecimal;
|
13
|
+
import java.net.URISyntaxException;
|
14
|
+
import java.sql.Connection;
|
15
|
+
import java.sql.DriverManager;
|
16
|
+
import java.sql.ResultSet;
|
17
|
+
import java.sql.SQLException;
|
18
|
+
import java.sql.Statement;
|
19
|
+
import java.sql.Timestamp;
|
20
|
+
import java.text.DateFormat;
|
21
|
+
import java.text.ParseException;
|
22
|
+
import java.text.SimpleDateFormat;
|
23
|
+
import java.util.ArrayList;
|
24
|
+
import java.util.Collections;
|
25
|
+
import java.util.Comparator;
|
26
|
+
import java.util.Date;
|
27
|
+
import java.util.Iterator;
|
28
|
+
import java.util.List;
|
29
|
+
import java.util.TimeZone;
|
30
|
+
import java.util.regex.Matcher;
|
31
|
+
import java.util.regex.Pattern;
|
32
|
+
|
33
|
+
import org.embulk.input.filesplit.LocalFileSplitInputPlugin;
|
34
|
+
import org.embulk.output.OracleOutputPlugin;
|
35
|
+
import org.embulk.spi.InputPlugin;
|
36
|
+
import org.embulk.spi.OutputPlugin;
|
37
|
+
|
38
|
+
|
39
|
+
public class OracleOutputPluginTestImpl
|
40
|
+
{
|
41
|
+
private EmbulkPluginTester tester = new EmbulkPluginTester(OutputPlugin.class, "oracle", OracleOutputPlugin.class);
|
42
|
+
|
43
|
+
|
44
|
+
public String beforeClass()
|
45
|
+
{
|
46
|
+
try {
|
47
|
+
Class.forName("oracle.jdbc.OracleDriver");
|
48
|
+
|
49
|
+
try (Connection connection = connect()) {
|
50
|
+
String version = connection.getMetaData().getDriverVersion();
|
51
|
+
System.out.println("Driver version = " + version);
|
52
|
+
return version;
|
53
|
+
}
|
54
|
+
|
55
|
+
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
56
|
+
//throw new RuntimeException("You should put Oracle JDBC driver on 'driver' directory.");
|
57
|
+
System.err.println("Warning: put Oracle JDBC driver on 'driver' directory in order to test embulk-output-oracle plugin.");
|
58
|
+
|
59
|
+
} catch (SQLException e) {
|
60
|
+
System.err.println(e);
|
61
|
+
//throw new RuntimeException("You should prepare a schema on Oracle (database = 'TESTDB', user = 'TEST_USER', password = 'test_pw').");
|
62
|
+
System.err.println("Warning: prepare a schema on Oracle (database = 'TESTDB', user = 'TEST_USER', password = 'test_pw').");
|
63
|
+
// for example
|
64
|
+
// CREATE USER EMBULK_USER IDENTIFIED BY "embulk_pw";
|
65
|
+
// GRANT DBA TO EMBULK_USER;
|
66
|
+
}
|
67
|
+
|
68
|
+
return null;
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
public void testInsert() throws Exception
|
73
|
+
{
|
74
|
+
String table = "TEST1";
|
75
|
+
|
76
|
+
dropTable(table);
|
77
|
+
createTable(table);
|
78
|
+
|
79
|
+
run("/yml/test-insert.yml");
|
80
|
+
|
81
|
+
assertTable(table);
|
82
|
+
}
|
83
|
+
|
84
|
+
public void testInsertCreate() throws Exception
|
85
|
+
{
|
86
|
+
String table = "TEST1";
|
87
|
+
|
88
|
+
dropTable(table);
|
89
|
+
|
90
|
+
run("/yml/test-insert.yml");
|
91
|
+
|
92
|
+
assertGeneratedTable(table);
|
93
|
+
}
|
94
|
+
|
95
|
+
public void testInsertDirect() throws Exception
|
96
|
+
{
|
97
|
+
String table = "TEST1";
|
98
|
+
|
99
|
+
dropTable(table);
|
100
|
+
createTable(table);
|
101
|
+
|
102
|
+
run("/yml/test-insert-direct.yml");
|
103
|
+
|
104
|
+
assertTable(table);
|
105
|
+
}
|
106
|
+
|
107
|
+
public void testInsertOCI() throws Exception
|
108
|
+
{
|
109
|
+
String table = "TEST1";
|
110
|
+
|
111
|
+
dropTable(table);
|
112
|
+
createTable(table);
|
113
|
+
|
114
|
+
run("/yml/test-insert-oci.yml");
|
115
|
+
|
116
|
+
assertTable(table);
|
117
|
+
}
|
118
|
+
|
119
|
+
public void testInsertOCISplit() throws Exception
|
120
|
+
{
|
121
|
+
tester.addPlugin(InputPlugin.class, "filesplit", LocalFileSplitInputPlugin.class);
|
122
|
+
|
123
|
+
String table = "TEST1";
|
124
|
+
|
125
|
+
dropTable(table);
|
126
|
+
createTable(table);
|
127
|
+
|
128
|
+
run("/yml/test-insert-oci-split.yml");
|
129
|
+
|
130
|
+
assertTable(table);
|
131
|
+
}
|
132
|
+
|
133
|
+
public void testUrl() throws Exception
|
134
|
+
{
|
135
|
+
String table = "TEST1";
|
136
|
+
|
137
|
+
dropTable(table);
|
138
|
+
createTable(table);
|
139
|
+
|
140
|
+
run("/yml/test-url.yml");
|
141
|
+
|
142
|
+
assertTable(table);
|
143
|
+
}
|
144
|
+
|
145
|
+
public void testReplace() throws Exception
|
146
|
+
{
|
147
|
+
String table = "TEST1";
|
148
|
+
|
149
|
+
dropTable(table);
|
150
|
+
createTable(table);
|
151
|
+
|
152
|
+
run("/yml/test-replace.yml");
|
153
|
+
|
154
|
+
assertGeneratedTable(table);
|
155
|
+
}
|
156
|
+
|
157
|
+
public void testReplaceCreate() throws Exception
|
158
|
+
{
|
159
|
+
String table = "TEST1";
|
160
|
+
|
161
|
+
dropTable(table);
|
162
|
+
|
163
|
+
run("/yml/test-replace.yml");
|
164
|
+
|
165
|
+
assertGeneratedTable(table);
|
166
|
+
}
|
167
|
+
|
168
|
+
|
169
|
+
public void testReplaceLongName() throws Exception
|
170
|
+
{
|
171
|
+
String table = "TEST12345678901234567890123456";
|
172
|
+
|
173
|
+
dropTable(table);
|
174
|
+
createTable(table);
|
175
|
+
|
176
|
+
run("/yml/test-replace-long-name.yml");
|
177
|
+
|
178
|
+
assertGeneratedTable(table);
|
179
|
+
}
|
180
|
+
|
181
|
+
public void testReplaceLongNameMultibyte() throws Exception
|
182
|
+
{
|
183
|
+
String table = "TEST12345678901234567890";
|
184
|
+
|
185
|
+
run("/yml/test-replace-long-name-multibyte.yml");
|
186
|
+
|
187
|
+
assertGeneratedTable(table);
|
188
|
+
}
|
189
|
+
|
190
|
+
public void testStringTimestamp() throws Exception
|
191
|
+
{
|
192
|
+
String table = "TEST1";
|
193
|
+
|
194
|
+
dropTable(table);
|
195
|
+
createTable(table);
|
196
|
+
|
197
|
+
run("/yml/test-string-timestamp.yml");
|
198
|
+
|
199
|
+
assertTable(table, TimeZone.getDefault());
|
200
|
+
}
|
201
|
+
|
202
|
+
private void dropTable(String table) throws SQLException
|
203
|
+
{
|
204
|
+
String sql = String.format("DROP TABLE %s", table);
|
205
|
+
executeSQL(sql, true);
|
206
|
+
}
|
207
|
+
|
208
|
+
private void createTable(String table) throws SQLException
|
209
|
+
{
|
210
|
+
String sql = String.format("CREATE TABLE %s ("
|
211
|
+
+ "ID CHAR(4),"
|
212
|
+
+ "VARCHAR2_ITEM VARCHAR2(40),"
|
213
|
+
+ "INTEGER_ITEM NUMBER(4,0),"
|
214
|
+
+ "NUMBER_ITEM NUMBER(10,2),"
|
215
|
+
+ "DATE_ITEM DATE,"
|
216
|
+
+ "TIMESTAMP_ITEM TIMESTAMP,"
|
217
|
+
+ "PRIMARY KEY (ID))", table);
|
218
|
+
executeSQL(sql);
|
219
|
+
}
|
220
|
+
|
221
|
+
private void assertTable(String table) throws Exception
|
222
|
+
{
|
223
|
+
assertTable(table, TimeZone.getTimeZone("GMT"));
|
224
|
+
}
|
225
|
+
|
226
|
+
|
227
|
+
private void assertTable(String table, TimeZone timeZone) throws Exception
|
228
|
+
{
|
229
|
+
List<List<Object>> rows = select(table);
|
230
|
+
|
231
|
+
/*
|
232
|
+
A001,ABCDE,0,123.45,2015/03/05,2015/03/05 12:34:56
|
233
|
+
A002,あいうえお,-9999,-99999999.99,2015/03/06,2015/03/06 23:59:59
|
234
|
+
A003,,,,,
|
235
|
+
*/
|
236
|
+
|
237
|
+
assertEquals(3, rows.size());
|
238
|
+
Iterator<List<Object>> i1 = rows.iterator();
|
239
|
+
{
|
240
|
+
Iterator<Object> i2 = i1.next().iterator();
|
241
|
+
assertEquals("A001", i2.next());
|
242
|
+
assertEquals("ABCDE", i2.next());
|
243
|
+
assertEquals(new BigDecimal("0"), i2.next());
|
244
|
+
assertEquals(new BigDecimal("123.45"), i2.next());
|
245
|
+
assertEquals(toTimestamp("2015/03/05 00:00:00", timeZone), i2.next());
|
246
|
+
assertEquals(toOracleTimestamp("2015/03/05 12:34:56", timeZone), i2.next());
|
247
|
+
}
|
248
|
+
{
|
249
|
+
Iterator<Object> i2 = i1.next().iterator();
|
250
|
+
assertEquals("A002", i2.next());
|
251
|
+
assertEquals("あいうえお", i2.next());
|
252
|
+
assertEquals(new BigDecimal("-9999"), i2.next());
|
253
|
+
assertEquals(new BigDecimal("-99999999.99"), i2.next());
|
254
|
+
assertEquals(toTimestamp("2015/03/06 00:00:00", timeZone), i2.next());
|
255
|
+
assertEquals(toOracleTimestamp("2015/03/06 23:59:59", timeZone), i2.next());
|
256
|
+
}
|
257
|
+
{
|
258
|
+
Iterator<Object> i2 = i1.next().iterator();
|
259
|
+
assertEquals("A003", i2.next());
|
260
|
+
assertEquals(null, i2.next());
|
261
|
+
assertEquals(null, i2.next());
|
262
|
+
assertEquals(null, i2.next());
|
263
|
+
assertEquals(null, i2.next());
|
264
|
+
assertEquals(null, i2.next());
|
265
|
+
}
|
266
|
+
}
|
267
|
+
|
268
|
+
private void assertGeneratedTable(String table) throws Exception
|
269
|
+
{
|
270
|
+
assertGeneratedTable(table, TimeZone.getTimeZone("GMT"));
|
271
|
+
}
|
272
|
+
|
273
|
+
private void assertGeneratedTable(String table, TimeZone timeZone) throws Exception
|
274
|
+
{
|
275
|
+
List<List<Object>> rows = select(table);
|
276
|
+
|
277
|
+
/*
|
278
|
+
A001,ABCDE,0,123.45,2015/03/05,2015/03/05 12:34:56
|
279
|
+
A002,あいうえお,-9999,-99999999.99,2015/03/06,2015/03/06 23:59:59
|
280
|
+
A003,,,,,
|
281
|
+
*/
|
282
|
+
|
283
|
+
assertEquals(3, rows.size());
|
284
|
+
Iterator<List<Object>> i1 = rows.iterator();
|
285
|
+
{
|
286
|
+
Iterator<Object> i2 = i1.next().iterator();
|
287
|
+
assertEquals("A001", i2.next());
|
288
|
+
assertEquals("ABCDE", i2.next());
|
289
|
+
assertEquals(new BigDecimal("0"), i2.next());
|
290
|
+
assertEquals("123.45", i2.next());
|
291
|
+
assertEquals(toOracleTimestamp("2015/03/05 00:00:00", timeZone), i2.next());
|
292
|
+
assertEquals(toOracleTimestamp("2015/03/05 12:34:56", timeZone), i2.next());
|
293
|
+
}
|
294
|
+
{
|
295
|
+
Iterator<Object> i2 = i1.next().iterator();
|
296
|
+
assertEquals("A002", i2.next());
|
297
|
+
assertEquals("あいうえお", i2.next());
|
298
|
+
assertEquals(new BigDecimal("-9999"), i2.next());
|
299
|
+
assertEquals("-99999999.99", i2.next());
|
300
|
+
assertEquals(toOracleTimestamp("2015/03/06 00:00:00", timeZone), i2.next());
|
301
|
+
assertEquals(toOracleTimestamp("2015/03/06 23:59:59", timeZone), i2.next());
|
302
|
+
}
|
303
|
+
{
|
304
|
+
Iterator<Object> i2 = i1.next().iterator();
|
305
|
+
assertEquals("A003", i2.next());
|
306
|
+
assertEquals(null, i2.next());
|
307
|
+
assertEquals(null, i2.next());
|
308
|
+
assertEquals(null, i2.next());
|
309
|
+
assertEquals(null, i2.next());
|
310
|
+
assertEquals(null, i2.next());
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
|
315
|
+
private Timestamp toTimestamp(String s, TimeZone timeZone)
|
316
|
+
{
|
317
|
+
for (String formatString : new String[]{"yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd"}) {
|
318
|
+
DateFormat dateFormat = new SimpleDateFormat(formatString);
|
319
|
+
dateFormat.setTimeZone(timeZone);
|
320
|
+
try {
|
321
|
+
Date date = dateFormat.parse(s);
|
322
|
+
return new Timestamp(date.getTime());
|
323
|
+
} catch (ParseException e) {
|
324
|
+
// NOP
|
325
|
+
}
|
326
|
+
}
|
327
|
+
throw new IllegalArgumentException(s);
|
328
|
+
}
|
329
|
+
|
330
|
+
private Object toOracleTimestamp(String s, TimeZone timeZone) throws Exception
|
331
|
+
{
|
332
|
+
Class<?> timestampClass = Class.forName("oracle.sql.TIMESTAMP");
|
333
|
+
Constructor<?> constructor = timestampClass.getConstructor(Timestamp.class);
|
334
|
+
return constructor.newInstance(toTimestamp(s, timeZone));
|
335
|
+
}
|
336
|
+
|
337
|
+
|
338
|
+
private List<List<Object>> select(String table) throws SQLException
|
339
|
+
{
|
340
|
+
try (Connection connection = connect()) {
|
341
|
+
try (Statement statement = connection.createStatement()) {
|
342
|
+
List<List<Object>> rows = new ArrayList<List<Object>>();
|
343
|
+
String sql = "SELECT * FROM " + table;
|
344
|
+
System.out.println(sql);
|
345
|
+
try (ResultSet resultSet = statement.executeQuery(sql)) {
|
346
|
+
while (resultSet.next()) {
|
347
|
+
List<Object> row = new ArrayList<Object>();
|
348
|
+
for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
|
349
|
+
Object value = resultSet.getObject(i);
|
350
|
+
if (value != null && value.getClass().getName().equals("oracle.sql.CLOB")) {
|
351
|
+
value = resultSet.getString(i);
|
352
|
+
}
|
353
|
+
row.add(value);
|
354
|
+
}
|
355
|
+
rows.add(row);
|
356
|
+
}
|
357
|
+
}
|
358
|
+
// cannot sort by CLOB, so sort by Java
|
359
|
+
Collections.sort(rows, new Comparator<List<Object>>() {
|
360
|
+
@Override
|
361
|
+
public int compare(List<Object> o1, List<Object> o2) {
|
362
|
+
return o1.toString().compareTo(o2.toString());
|
363
|
+
}
|
364
|
+
});
|
365
|
+
return rows;
|
366
|
+
}
|
367
|
+
}
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
private void executeSQL(String sql) throws SQLException
|
373
|
+
{
|
374
|
+
executeSQL(sql, false);
|
375
|
+
}
|
376
|
+
|
377
|
+
private void executeSQL(String sql, boolean ignoreError) throws SQLException
|
378
|
+
{
|
379
|
+
try (Connection connection = connect()) {
|
380
|
+
try {
|
381
|
+
connection.setAutoCommit(true);
|
382
|
+
|
383
|
+
try (Statement statement = connection.createStatement()) {
|
384
|
+
System.out.println(String.format("Execute SQL : \"%s\".", sql));
|
385
|
+
statement.execute(sql);
|
386
|
+
}
|
387
|
+
|
388
|
+
} catch (SQLException e) {
|
389
|
+
if (!ignoreError) {
|
390
|
+
throw e;
|
391
|
+
}
|
392
|
+
}
|
393
|
+
}
|
394
|
+
}
|
395
|
+
|
396
|
+
private static Connection connect() throws SQLException
|
397
|
+
{
|
398
|
+
return DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:TESTDB", "TEST_USER", "test_pw");
|
399
|
+
}
|
400
|
+
|
401
|
+
private void run(String ymlName) throws Exception
|
402
|
+
{
|
403
|
+
tester.run(convertYml(ymlName));
|
404
|
+
}
|
405
|
+
|
406
|
+
private String convertYml(String ymlName)
|
407
|
+
{
|
408
|
+
try {
|
409
|
+
File ymlPath = convertPath(ymlName);
|
410
|
+
File tempYmlPath = new File(ymlPath.getParentFile(), "temp-" + ymlPath.getName());
|
411
|
+
Pattern pathPrefixPattern = Pattern.compile("^ *path(_prefix)?: '(.*)'$");
|
412
|
+
try (BufferedReader reader = new BufferedReader(new FileReader(ymlPath))) {
|
413
|
+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempYmlPath))) {
|
414
|
+
String line;
|
415
|
+
while ((line = reader.readLine()) != null) {
|
416
|
+
Matcher matcher = pathPrefixPattern.matcher(line);
|
417
|
+
if (matcher.matches()) {
|
418
|
+
int group = 2;
|
419
|
+
writer.write(line.substring(0, matcher.start(group)));
|
420
|
+
writer.write(convertPath(matcher.group(group)).getAbsolutePath());
|
421
|
+
writer.write(line.substring(matcher.end(group)));
|
422
|
+
} else {
|
423
|
+
writer.write(line);
|
424
|
+
}
|
425
|
+
writer.newLine();
|
426
|
+
}
|
427
|
+
}
|
428
|
+
}
|
429
|
+
return tempYmlPath.getAbsolutePath();
|
430
|
+
|
431
|
+
} catch (IOException e) {
|
432
|
+
throw new RuntimeException(e);
|
433
|
+
} catch (URISyntaxException e) {
|
434
|
+
throw new RuntimeException(e);
|
435
|
+
}
|
436
|
+
}
|
437
|
+
|
438
|
+
private File convertPath(String name) throws URISyntaxException
|
439
|
+
{
|
440
|
+
if (getClass().getResource(name) == null)
|
441
|
+
return new File(name);
|
442
|
+
return new File(getClass().getResource(name).toURI());
|
443
|
+
}
|
444
|
+
|
445
|
+
}
|