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