embulk-output-oracle 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +160 -160
- data/build.gradle +6 -6
- data/classpath/embulk-output-jdbc-0.4.2.jar +0 -0
- data/classpath/{embulk-output-oracle-0.4.1.jar → embulk-output-oracle-0.4.2.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 +151 -153
- data/src/main/java/org/embulk/output/oracle/DirectBatchInsert.java +290 -290
- data/src/main/java/org/embulk/output/oracle/InsertMethod.java +8 -8
- data/src/main/java/org/embulk/output/oracle/OracleCharset.java +32 -32
- data/src/main/java/org/embulk/output/oracle/OracleOutputConnection.java +179 -165
- 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 +105 -105
- 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 +185 -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/OracleOutputPluginTest.java +50 -25
- data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTestImpl.java +548 -540
- data/src/test/java/org/embulk/output/oracle/TimestampFormatTest.java +57 -57
- data/src/test/java/org/embulk/output/tester/EmbulkPluginTester.java +79 -0
- data/src/test/resources/data/test1/test1.csv +3 -3
- data/src/test/resources/dummy.txt +1 -0
- data/src/test/resources/yml/test-insert-direct-direct-method.yml +26 -26
- data/src/test/resources/yml/test-insert-direct-empty.yml +25 -25
- data/src/test/resources/yml/test-insert-direct-oci-method-split.yml +28 -28
- data/src/test/resources/yml/test-insert-direct-oci-method.yml +28 -28
- data/src/test/resources/yml/test-insert-direct.yml +25 -25
- data/src/test/resources/yml/test-insert-empty.yml +27 -27
- data/src/test/resources/yml/test-insert.yml +25 -27
- data/src/test/resources/yml/test-replace-empty.yml +31 -31
- data/src/test/resources/yml/test-replace-long-name-multibyte.yml +31 -31
- data/src/test/resources/yml/test-replace-long-name.yml +31 -31
- data/src/test/resources/yml/test-replace.yml +31 -31
- data/src/test/resources/yml/test-string-timestamp.yml +28 -28
- data/src/test/resources/yml/test-url.yml +24 -24
- metadata +6 -8
- data/classpath/embulk-output-jdbc-0.4.1.jar +0 -0
- data/lib/embulk/linux_x64/libembulk-output-oracle.so +0 -0
- data/src/test/java/org/embulk/output/oracle/ChildFirstClassLoader.java +0 -42
- data/src/test/java/org/embulk/output/oracle/EmbulkPluginTester.java +0 -124
- data/src/test/java/org/embulk/output/oracle/EmptyConfigSource.java +0 -105
@@ -1,540 +1,548 @@
|
|
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.
|
35
|
-
import org.embulk.spi.InputPlugin;
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
private
|
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
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
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
|
-
assertEquals("
|
297
|
-
assertEquals("
|
298
|
-
assertEquals(
|
299
|
-
assertEquals(
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
assertEquals("
|
306
|
-
assertEquals(
|
307
|
-
assertEquals(
|
308
|
-
assertEquals(
|
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
|
-
assertEquals("
|
347
|
-
assertEquals("
|
348
|
-
assertEquals(
|
349
|
-
assertEquals("
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
assertEquals("
|
356
|
-
assertEquals(
|
357
|
-
assertEquals(
|
358
|
-
assertEquals(
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
assertEquals("
|
391
|
-
assertEquals("
|
392
|
-
assertEquals(
|
393
|
-
assertEquals(
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
assertEquals("
|
400
|
-
assertEquals(
|
401
|
-
assertEquals(
|
402
|
-
assertEquals(
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
}
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
}
|
458
|
-
}
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
}
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
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.tester.EmbulkPluginTester;
|
35
|
+
import org.embulk.spi.InputPlugin;
|
36
|
+
|
37
|
+
|
38
|
+
public class OracleOutputPluginTestImpl
|
39
|
+
{
|
40
|
+
private EmbulkPluginTester tester;
|
41
|
+
private String pluginName;
|
42
|
+
|
43
|
+
public void setTester(EmbulkPluginTester tester) {
|
44
|
+
this.tester = tester;
|
45
|
+
}
|
46
|
+
|
47
|
+
public void setPluginName(String pluginName) {
|
48
|
+
this.pluginName = pluginName;
|
49
|
+
}
|
50
|
+
|
51
|
+
public String beforeClass()
|
52
|
+
{
|
53
|
+
try {
|
54
|
+
Class.forName("oracle.jdbc.OracleDriver");
|
55
|
+
|
56
|
+
try (Connection connection = connect()) {
|
57
|
+
String version = connection.getMetaData().getDriverVersion();
|
58
|
+
System.out.println("Driver version = " + version);
|
59
|
+
return version;
|
60
|
+
}
|
61
|
+
|
62
|
+
} catch (ClassNotFoundException | NoClassDefFoundError e) {
|
63
|
+
//throw new RuntimeException("You should put Oracle JDBC driver on 'driver' directory.");
|
64
|
+
System.err.println("Warning: put Oracle JDBC driver on 'driver' directory in order to test embulk-output-oracle plugin.");
|
65
|
+
|
66
|
+
} catch (SQLException e) {
|
67
|
+
System.err.println(e);
|
68
|
+
//throw new RuntimeException("You should prepare a schema on Oracle (database = 'TESTDB', user = 'TEST_USER', password = 'test_pw').");
|
69
|
+
System.err.println("Warning: prepare a schema on Oracle (database = 'TESTDB', user = 'TEST_USER', password = 'test_pw').");
|
70
|
+
// for example
|
71
|
+
// CREATE USER EMBULK_USER IDENTIFIED BY "embulk_pw";
|
72
|
+
// GRANT DBA TO EMBULK_USER;
|
73
|
+
}
|
74
|
+
|
75
|
+
convertPath("/data/test2/").mkdirs();
|
76
|
+
|
77
|
+
return null;
|
78
|
+
}
|
79
|
+
|
80
|
+
public void testInsert() throws Exception
|
81
|
+
{
|
82
|
+
String table = "TEST1";
|
83
|
+
|
84
|
+
dropTable(table);
|
85
|
+
createTable(table);
|
86
|
+
|
87
|
+
run("/yml/test-insert.yml");
|
88
|
+
|
89
|
+
assertTable(table);
|
90
|
+
}
|
91
|
+
|
92
|
+
public void testInsertEmpty() throws Exception
|
93
|
+
{
|
94
|
+
String table = "TEST1";
|
95
|
+
|
96
|
+
dropTable(table);
|
97
|
+
createTable(table);
|
98
|
+
|
99
|
+
run("/yml/test-insert-empty.yml");
|
100
|
+
|
101
|
+
assertTableEmpty(table);
|
102
|
+
}
|
103
|
+
|
104
|
+
public void testInsertDirect() throws Exception
|
105
|
+
{
|
106
|
+
String table = "TEST1";
|
107
|
+
|
108
|
+
dropTable(table);
|
109
|
+
createTable(table);
|
110
|
+
|
111
|
+
run("/yml/test-insert-direct.yml");
|
112
|
+
|
113
|
+
assertTable(table);
|
114
|
+
}
|
115
|
+
|
116
|
+
public void testInsertDirectEmpty() throws Exception
|
117
|
+
{
|
118
|
+
String table = "TEST1";
|
119
|
+
|
120
|
+
dropTable(table);
|
121
|
+
createTable(table);
|
122
|
+
|
123
|
+
run("/yml/test-insert-direct-empty.yml");
|
124
|
+
|
125
|
+
assertTableEmpty(table);
|
126
|
+
}
|
127
|
+
|
128
|
+
public void testInsertDirectCreate() throws Exception
|
129
|
+
{
|
130
|
+
String table = "TEST1";
|
131
|
+
|
132
|
+
dropTable(table);
|
133
|
+
|
134
|
+
run("/yml/test-insert-direct.yml");
|
135
|
+
|
136
|
+
assertGeneratedTable1(table);
|
137
|
+
}
|
138
|
+
|
139
|
+
public void testInsertDirectDirectMethod() throws Exception
|
140
|
+
{
|
141
|
+
String table = "TEST1";
|
142
|
+
|
143
|
+
dropTable(table);
|
144
|
+
createTable(table);
|
145
|
+
|
146
|
+
run("/yml/test-insert-direct-direct-method.yml");
|
147
|
+
|
148
|
+
assertTable(table);
|
149
|
+
}
|
150
|
+
|
151
|
+
public void testInsertDirectOCIMethod() throws Exception
|
152
|
+
{
|
153
|
+
String table = "TEST1";
|
154
|
+
|
155
|
+
dropTable(table);
|
156
|
+
createTable(table);
|
157
|
+
|
158
|
+
run("/yml/test-insert-direct-oci-method.yml");
|
159
|
+
|
160
|
+
assertTable(table);
|
161
|
+
}
|
162
|
+
|
163
|
+
public void testInsertDirectOCIMethodSplit() throws Exception
|
164
|
+
{
|
165
|
+
tester.addPlugin(InputPlugin.class, "filesplit", LocalFileSplitInputPlugin.class);
|
166
|
+
|
167
|
+
String table = "TEST1";
|
168
|
+
|
169
|
+
dropTable(table);
|
170
|
+
createTable(table);
|
171
|
+
|
172
|
+
run("/yml/test-insert-direct-oci-method-split.yml");
|
173
|
+
|
174
|
+
assertTable(table);
|
175
|
+
}
|
176
|
+
|
177
|
+
public void testUrl() throws Exception
|
178
|
+
{
|
179
|
+
String table = "TEST1";
|
180
|
+
|
181
|
+
dropTable(table);
|
182
|
+
createTable(table);
|
183
|
+
|
184
|
+
run("/yml/test-url.yml");
|
185
|
+
|
186
|
+
assertTable(table);
|
187
|
+
}
|
188
|
+
|
189
|
+
public void testReplace() throws Exception
|
190
|
+
{
|
191
|
+
String table = "TEST1";
|
192
|
+
|
193
|
+
dropTable(table);
|
194
|
+
createTable(table);
|
195
|
+
|
196
|
+
run("/yml/test-replace.yml");
|
197
|
+
|
198
|
+
assertGeneratedTable2(table);
|
199
|
+
}
|
200
|
+
|
201
|
+
public void testReplaceEmpty() throws Exception
|
202
|
+
{
|
203
|
+
String table = "TEST1";
|
204
|
+
|
205
|
+
dropTable(table);
|
206
|
+
createTable(table);
|
207
|
+
|
208
|
+
run("/yml/test-replace-empty.yml");
|
209
|
+
|
210
|
+
assertTableEmpty(table);
|
211
|
+
}
|
212
|
+
|
213
|
+
public void testReplaceCreate() throws Exception
|
214
|
+
{
|
215
|
+
String table = "TEST1";
|
216
|
+
|
217
|
+
dropTable(table);
|
218
|
+
|
219
|
+
run("/yml/test-replace.yml");
|
220
|
+
|
221
|
+
assertGeneratedTable2(table);
|
222
|
+
}
|
223
|
+
|
224
|
+
|
225
|
+
public void testReplaceLongName() throws Exception
|
226
|
+
{
|
227
|
+
String table = "TEST12345678901234567890123456";
|
228
|
+
|
229
|
+
dropTable(table);
|
230
|
+
createTable(table);
|
231
|
+
|
232
|
+
run("/yml/test-replace-long-name.yml");
|
233
|
+
|
234
|
+
assertGeneratedTable2(table);
|
235
|
+
}
|
236
|
+
|
237
|
+
public void testReplaceLongNameMultibyte() throws Exception
|
238
|
+
{
|
239
|
+
String table = "TEST12345678901234567890";
|
240
|
+
|
241
|
+
run("/yml/test-replace-long-name-multibyte.yml");
|
242
|
+
|
243
|
+
assertGeneratedTable2(table);
|
244
|
+
}
|
245
|
+
|
246
|
+
public void testStringTimestamp() throws Exception
|
247
|
+
{
|
248
|
+
String table = "TEST1";
|
249
|
+
|
250
|
+
dropTable(table);
|
251
|
+
createTable(table);
|
252
|
+
|
253
|
+
run("/yml/test-string-timestamp.yml");
|
254
|
+
|
255
|
+
assertTable(table);
|
256
|
+
}
|
257
|
+
|
258
|
+
private void dropTable(String table) throws SQLException
|
259
|
+
{
|
260
|
+
String sql = String.format("DROP TABLE %s", table);
|
261
|
+
executeSQL(sql, true);
|
262
|
+
}
|
263
|
+
|
264
|
+
private void createTable(String table) throws SQLException
|
265
|
+
{
|
266
|
+
String sql = String.format("CREATE TABLE %s ("
|
267
|
+
+ "ID CHAR(4),"
|
268
|
+
+ "VARCHAR2_ITEM VARCHAR2(40),"
|
269
|
+
+ "INTEGER_ITEM NUMBER(4,0),"
|
270
|
+
+ "NUMBER_ITEM NUMBER(10,2),"
|
271
|
+
+ "DATE_ITEM DATE,"
|
272
|
+
+ "TIMESTAMP_ITEM TIMESTAMP,"
|
273
|
+
+ "PRIMARY KEY (ID))", table);
|
274
|
+
executeSQL(sql);
|
275
|
+
}
|
276
|
+
|
277
|
+
private void assertTable(String table) throws Exception
|
278
|
+
{
|
279
|
+
// datetime of UTC will be inserted by embulk.
|
280
|
+
// datetime of default timezone will be selected by JDBC.
|
281
|
+
TimeZone timeZone = TimeZone.getDefault();
|
282
|
+
List<List<Object>> rows = select(table);
|
283
|
+
|
284
|
+
/*
|
285
|
+
A001,ABCDE,0,123.45,2015/03/05,2015/03/05 12:34:56
|
286
|
+
A002,あいうえお,-9999,-99999999.99,2015/03/06,2015/03/06 23:59:59
|
287
|
+
A003,,,,,
|
288
|
+
*/
|
289
|
+
|
290
|
+
assertEquals(3, rows.size());
|
291
|
+
Iterator<List<Object>> i1 = rows.iterator();
|
292
|
+
{
|
293
|
+
Iterator<Object> i2 = i1.next().iterator();
|
294
|
+
assertEquals("A001", i2.next());
|
295
|
+
assertEquals("ABCDE", i2.next());
|
296
|
+
assertEquals(new BigDecimal("0"), i2.next());
|
297
|
+
assertEquals(new BigDecimal("123.45"), i2.next());
|
298
|
+
assertEquals(toTimestamp("2015/03/05 00:00:00", timeZone), i2.next());
|
299
|
+
assertEquals(toOracleTimestamp("2015/03/05 12:34:56", timeZone), i2.next());
|
300
|
+
}
|
301
|
+
{
|
302
|
+
Iterator<Object> i2 = i1.next().iterator();
|
303
|
+
assertEquals("A002", i2.next());
|
304
|
+
assertEquals("あいうえお", i2.next());
|
305
|
+
assertEquals(new BigDecimal("-9999"), i2.next());
|
306
|
+
assertEquals(new BigDecimal("-99999999.99"), i2.next());
|
307
|
+
assertEquals(toTimestamp("2015/03/06 00:00:00", timeZone), i2.next());
|
308
|
+
assertEquals(toOracleTimestamp("2015/03/06 23:59:59", timeZone), i2.next());
|
309
|
+
}
|
310
|
+
{
|
311
|
+
Iterator<Object> i2 = i1.next().iterator();
|
312
|
+
assertEquals("A003", i2.next());
|
313
|
+
assertEquals(null, i2.next());
|
314
|
+
assertEquals(null, i2.next());
|
315
|
+
assertEquals(null, i2.next());
|
316
|
+
assertEquals(null, i2.next());
|
317
|
+
assertEquals(null, i2.next());
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
private void assertTableEmpty(String table) throws Exception
|
322
|
+
{
|
323
|
+
List<List<Object>> rows = select(table);
|
324
|
+
assertEquals(0, rows.size());
|
325
|
+
}
|
326
|
+
|
327
|
+
private void assertGeneratedTable1(String table) throws Exception
|
328
|
+
{
|
329
|
+
// datetime of UTC will be inserted by embulk.
|
330
|
+
// datetime of default timezone will be selected by JDBC.
|
331
|
+
TimeZone timeZone = TimeZone.getDefault();
|
332
|
+
List<List<Object>> rows = select(table);
|
333
|
+
|
334
|
+
/*
|
335
|
+
A001,ABCDE,0,123.45,2015/03/05,2015/03/05 12:34:56
|
336
|
+
A002,あいうえお,-9999,-99999999.99,2015/03/06,2015/03/06 23:59:59
|
337
|
+
A003,,,,,
|
338
|
+
*/
|
339
|
+
|
340
|
+
assertEquals(3, rows.size());
|
341
|
+
Iterator<List<Object>> i1 = rows.iterator();
|
342
|
+
{
|
343
|
+
Iterator<Object> i2 = i1.next().iterator();
|
344
|
+
assertEquals("A001", i2.next());
|
345
|
+
assertEquals("ABCDE", i2.next());
|
346
|
+
assertEquals(new BigDecimal("0"), i2.next());
|
347
|
+
assertEquals("123.45", i2.next());
|
348
|
+
assertEquals(toOracleTimestamp("2015/03/05 00:00:00", timeZone), i2.next());
|
349
|
+
assertEquals(toOracleTimestamp("2015/03/05 12:34:56", timeZone), i2.next());
|
350
|
+
}
|
351
|
+
{
|
352
|
+
Iterator<Object> i2 = i1.next().iterator();
|
353
|
+
assertEquals("A002", i2.next());
|
354
|
+
assertEquals("あいうえお", i2.next());
|
355
|
+
assertEquals(new BigDecimal("-9999"), i2.next());
|
356
|
+
assertEquals("-99999999.99", i2.next());
|
357
|
+
assertEquals(toOracleTimestamp("2015/03/06 00:00:00", timeZone), i2.next());
|
358
|
+
assertEquals(toOracleTimestamp("2015/03/06 23:59:59", timeZone), i2.next());
|
359
|
+
}
|
360
|
+
{
|
361
|
+
Iterator<Object> i2 = i1.next().iterator();
|
362
|
+
assertEquals("A003", i2.next());
|
363
|
+
assertEquals(null, i2.next());
|
364
|
+
assertEquals(null, i2.next());
|
365
|
+
assertEquals(null, i2.next());
|
366
|
+
assertEquals(null, i2.next());
|
367
|
+
assertEquals(null, i2.next());
|
368
|
+
}
|
369
|
+
}
|
370
|
+
|
371
|
+
private void assertGeneratedTable2(String table) throws Exception
|
372
|
+
{
|
373
|
+
// datetime of UTC will be inserted by embulk.
|
374
|
+
// datetime of default timezone will be selected by JDBC.
|
375
|
+
TimeZone timeZone = TimeZone.getDefault();
|
376
|
+
List<List<Object>> rows = select(table);
|
377
|
+
|
378
|
+
/*
|
379
|
+
A001,ABCDE,0,123.45,2015/03/05,2015/03/05 12:34:56
|
380
|
+
A002,あいうえお,-9999,-99999999.99,2015/03/06,2015/03/06 23:59:59
|
381
|
+
A003,,,,,
|
382
|
+
*/
|
383
|
+
|
384
|
+
assertEquals(3, rows.size());
|
385
|
+
Iterator<List<Object>> i1 = rows.iterator();
|
386
|
+
{
|
387
|
+
Iterator<Object> i2 = i1.next().iterator();
|
388
|
+
assertEquals("A001", i2.next());
|
389
|
+
assertEquals("ABCDE", i2.next());
|
390
|
+
assertEquals(new BigDecimal("0"), i2.next());
|
391
|
+
assertEquals(new BigDecimal("123.45"), i2.next());
|
392
|
+
assertEquals(toTimestamp("2015/03/05 00:00:00", timeZone), i2.next());
|
393
|
+
assertEquals(toOracleTimestamp("2015/03/05 12:34:56", timeZone), i2.next());
|
394
|
+
}
|
395
|
+
{
|
396
|
+
Iterator<Object> i2 = i1.next().iterator();
|
397
|
+
assertEquals("A002", i2.next());
|
398
|
+
assertEquals("あいうえお", i2.next());
|
399
|
+
assertEquals(new BigDecimal("-9999"), i2.next());
|
400
|
+
assertEquals(new BigDecimal("-99999999.99"), i2.next());
|
401
|
+
assertEquals(toTimestamp("2015/03/06 00:00:00", timeZone), i2.next());
|
402
|
+
assertEquals(toOracleTimestamp("2015/03/06 23:59:59", timeZone), i2.next());
|
403
|
+
}
|
404
|
+
{
|
405
|
+
Iterator<Object> i2 = i1.next().iterator();
|
406
|
+
assertEquals("A003", i2.next());
|
407
|
+
assertEquals(null, i2.next());
|
408
|
+
assertEquals(null, i2.next());
|
409
|
+
assertEquals(null, i2.next());
|
410
|
+
assertEquals(null, i2.next());
|
411
|
+
assertEquals(null, i2.next());
|
412
|
+
}
|
413
|
+
}
|
414
|
+
|
415
|
+
|
416
|
+
private Timestamp toTimestamp(String s, TimeZone timeZone)
|
417
|
+
{
|
418
|
+
for (String formatString : new String[]{"yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd"}) {
|
419
|
+
DateFormat dateFormat = new SimpleDateFormat(formatString);
|
420
|
+
dateFormat.setTimeZone(timeZone);
|
421
|
+
try {
|
422
|
+
Date date = dateFormat.parse(s);
|
423
|
+
return new Timestamp(date.getTime());
|
424
|
+
} catch (ParseException e) {
|
425
|
+
// NOP
|
426
|
+
}
|
427
|
+
}
|
428
|
+
throw new IllegalArgumentException(s);
|
429
|
+
}
|
430
|
+
|
431
|
+
private Object toOracleTimestamp(String s, TimeZone timeZone) throws Exception
|
432
|
+
{
|
433
|
+
Class<?> timestampClass = Class.forName("oracle.sql.TIMESTAMP");
|
434
|
+
Constructor<?> constructor = timestampClass.getConstructor(Timestamp.class);
|
435
|
+
return constructor.newInstance(toTimestamp(s, timeZone));
|
436
|
+
}
|
437
|
+
|
438
|
+
|
439
|
+
private List<List<Object>> select(String table) throws SQLException
|
440
|
+
{
|
441
|
+
try (Connection connection = connect()) {
|
442
|
+
try (Statement statement = connection.createStatement()) {
|
443
|
+
List<List<Object>> rows = new ArrayList<List<Object>>();
|
444
|
+
String sql = "SELECT * FROM " + table;
|
445
|
+
System.out.println(sql);
|
446
|
+
try (ResultSet resultSet = statement.executeQuery(sql)) {
|
447
|
+
while (resultSet.next()) {
|
448
|
+
List<Object> row = new ArrayList<Object>();
|
449
|
+
for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) {
|
450
|
+
Object value = resultSet.getObject(i);
|
451
|
+
if (value != null && value.getClass().getName().equals("oracle.sql.CLOB")) {
|
452
|
+
value = resultSet.getString(i);
|
453
|
+
}
|
454
|
+
row.add(value);
|
455
|
+
}
|
456
|
+
rows.add(row);
|
457
|
+
}
|
458
|
+
}
|
459
|
+
// cannot sort by CLOB, so sort by Java
|
460
|
+
Collections.sort(rows, new Comparator<List<Object>>() {
|
461
|
+
@Override
|
462
|
+
public int compare(List<Object> o1, List<Object> o2) {
|
463
|
+
return o1.toString().compareTo(o2.toString());
|
464
|
+
}
|
465
|
+
});
|
466
|
+
return rows;
|
467
|
+
}
|
468
|
+
}
|
469
|
+
|
470
|
+
}
|
471
|
+
|
472
|
+
|
473
|
+
private void executeSQL(String sql) throws SQLException
|
474
|
+
{
|
475
|
+
executeSQL(sql, false);
|
476
|
+
}
|
477
|
+
|
478
|
+
private void executeSQL(String sql, boolean ignoreError) throws SQLException
|
479
|
+
{
|
480
|
+
try (Connection connection = connect()) {
|
481
|
+
try {
|
482
|
+
connection.setAutoCommit(true);
|
483
|
+
|
484
|
+
try (Statement statement = connection.createStatement()) {
|
485
|
+
System.out.println(String.format("Execute SQL : \"%s\".", sql));
|
486
|
+
statement.execute(sql);
|
487
|
+
}
|
488
|
+
|
489
|
+
} catch (SQLException e) {
|
490
|
+
if (!ignoreError) {
|
491
|
+
throw e;
|
492
|
+
}
|
493
|
+
}
|
494
|
+
}
|
495
|
+
}
|
496
|
+
|
497
|
+
private static Connection connect() throws SQLException
|
498
|
+
{
|
499
|
+
return DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:TESTDB", "TEST_USER", "test_pw");
|
500
|
+
}
|
501
|
+
|
502
|
+
private void run(String ymlName) throws Exception
|
503
|
+
{
|
504
|
+
tester.run(convertYml(ymlName));
|
505
|
+
}
|
506
|
+
|
507
|
+
private String convertYml(String ymlName)
|
508
|
+
{
|
509
|
+
try {
|
510
|
+
File ymlPath = convertPath(ymlName);
|
511
|
+
File tempYmlPath = new File(ymlPath.getParentFile(), "temp-" + ymlPath.getName());
|
512
|
+
Pattern pathPrefixPattern = Pattern.compile("^ *path(_prefix)?: '(.*)'$");
|
513
|
+
try (BufferedReader reader = new BufferedReader(new FileReader(ymlPath))) {
|
514
|
+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempYmlPath))) {
|
515
|
+
String line;
|
516
|
+
while ((line = reader.readLine()) != null) {
|
517
|
+
line = line.replaceAll("type: oracle", "type: " + pluginName);
|
518
|
+
Matcher matcher = pathPrefixPattern.matcher(line);
|
519
|
+
if (matcher.matches()) {
|
520
|
+
int group = 2;
|
521
|
+
writer.write(line.substring(0, matcher.start(group)));
|
522
|
+
writer.write(convertPath(matcher.group(group)).getAbsolutePath());
|
523
|
+
writer.write(line.substring(matcher.end(group)));
|
524
|
+
} else {
|
525
|
+
writer.write(line);
|
526
|
+
}
|
527
|
+
writer.newLine();
|
528
|
+
}
|
529
|
+
}
|
530
|
+
}
|
531
|
+
return tempYmlPath.getAbsolutePath();
|
532
|
+
|
533
|
+
} catch (IOException e) {
|
534
|
+
throw new RuntimeException(e);
|
535
|
+
}
|
536
|
+
}
|
537
|
+
|
538
|
+
private File convertPath(String name)
|
539
|
+
{
|
540
|
+
try {
|
541
|
+
File root = new File(getClass().getResource("/dummy.txt").toURI()).getParentFile();
|
542
|
+
return new File(root, name);
|
543
|
+
} catch (URISyntaxException e) {
|
544
|
+
throw new RuntimeException(e);
|
545
|
+
}
|
546
|
+
}
|
547
|
+
|
548
|
+
}
|