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,154 +1,154 @@
|
|
1
|
-
package org.embulk.input.filesplit;
|
2
|
-
|
3
|
-
import java.io.BufferedInputStream;
|
4
|
-
import java.io.IOException;
|
5
|
-
import java.io.InputStream;
|
6
|
-
import java.io.PushbackInputStream;
|
7
|
-
|
8
|
-
|
9
|
-
public class PartialFileInputStream extends InputStream
|
10
|
-
{
|
11
|
-
private final PushbackInputStream original;
|
12
|
-
private long start;
|
13
|
-
private long end;
|
14
|
-
private long current;
|
15
|
-
private boolean eof;
|
16
|
-
|
17
|
-
public PartialFileInputStream(InputStream original, long start, long end)
|
18
|
-
{
|
19
|
-
this.original = new PushbackInputStream(new BufferedInputStream(original));
|
20
|
-
this.start = start;
|
21
|
-
this.end = end;
|
22
|
-
current = -1;
|
23
|
-
}
|
24
|
-
|
25
|
-
@Override
|
26
|
-
public int read(byte[] b) throws IOException
|
27
|
-
{
|
28
|
-
return read(b, 0, b.length);
|
29
|
-
}
|
30
|
-
|
31
|
-
@Override
|
32
|
-
public int read(byte[] b, int off, int len) throws IOException
|
33
|
-
{
|
34
|
-
initializeIfNeeded();
|
35
|
-
|
36
|
-
if (eof) {
|
37
|
-
return -1;
|
38
|
-
}
|
39
|
-
|
40
|
-
int read = original.read(b, off, len);
|
41
|
-
if (read < 0) {
|
42
|
-
eof = true;
|
43
|
-
return -1;
|
44
|
-
}
|
45
|
-
|
46
|
-
current += read;
|
47
|
-
if (current >= end) {
|
48
|
-
for (int i = Math.max((int)(end - 1 - current + read), 0); i < read; i++) {
|
49
|
-
if (b[off + i] == '\n') {
|
50
|
-
eof = true;
|
51
|
-
return i + 1;
|
52
|
-
}
|
53
|
-
|
54
|
-
if (b[off + i] == '\r') {
|
55
|
-
int next = (i < read ? b[off + i + 1] : prefetch());
|
56
|
-
if (next != '\n') {
|
57
|
-
eof = true;
|
58
|
-
return i + 1;
|
59
|
-
}
|
60
|
-
}
|
61
|
-
}
|
62
|
-
}
|
63
|
-
|
64
|
-
return read;
|
65
|
-
}
|
66
|
-
|
67
|
-
@Override
|
68
|
-
public int read() throws IOException
|
69
|
-
{
|
70
|
-
initializeIfNeeded();
|
71
|
-
|
72
|
-
if (eof) {
|
73
|
-
return -1;
|
74
|
-
}
|
75
|
-
|
76
|
-
int read = original.read();
|
77
|
-
current++;
|
78
|
-
|
79
|
-
if (read < 0) {
|
80
|
-
eof = true;
|
81
|
-
return -1;
|
82
|
-
}
|
83
|
-
|
84
|
-
if (current >= end) {
|
85
|
-
if (read == '\n' || read == '\r' && prefetch() != '\n') {
|
86
|
-
eof = true;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
return read;
|
91
|
-
}
|
92
|
-
|
93
|
-
@Override
|
94
|
-
public long skip(long n) throws IOException
|
95
|
-
{
|
96
|
-
throw new IOException("Skip not supported.");
|
97
|
-
/*
|
98
|
-
long skip = original.skip(n);
|
99
|
-
current += skip;
|
100
|
-
return skip;
|
101
|
-
*/
|
102
|
-
}
|
103
|
-
|
104
|
-
@Override
|
105
|
-
public int available() throws IOException
|
106
|
-
{
|
107
|
-
return 0;
|
108
|
-
}
|
109
|
-
|
110
|
-
@Override
|
111
|
-
public void close() throws IOException
|
112
|
-
{
|
113
|
-
original.close();
|
114
|
-
}
|
115
|
-
|
116
|
-
private void initializeIfNeeded() throws IOException
|
117
|
-
{
|
118
|
-
if (current >= start) {
|
119
|
-
return;
|
120
|
-
|
121
|
-
}
|
122
|
-
if (start == 0) {
|
123
|
-
current = 0;
|
124
|
-
} else {
|
125
|
-
current = original.skip(--start);
|
126
|
-
if (current != start) {
|
127
|
-
throw new IOException("Cannot skip.");
|
128
|
-
}
|
129
|
-
|
130
|
-
int c;
|
131
|
-
while ((c = original.read()) >= 0) {
|
132
|
-
start++;
|
133
|
-
current++;
|
134
|
-
|
135
|
-
if (c == '\n' || c == '\r' && prefetch() != '\n') {
|
136
|
-
break;
|
137
|
-
}
|
138
|
-
}
|
139
|
-
}
|
140
|
-
|
141
|
-
if (start >= end) {
|
142
|
-
eof = true;
|
143
|
-
}
|
144
|
-
}
|
145
|
-
|
146
|
-
private int prefetch() throws IOException
|
147
|
-
{
|
148
|
-
int c = original.read();
|
149
|
-
if (c >= 0) {
|
150
|
-
original.unread(c);
|
151
|
-
}
|
152
|
-
return c;
|
153
|
-
}
|
154
|
-
}
|
1
|
+
package org.embulk.input.filesplit;
|
2
|
+
|
3
|
+
import java.io.BufferedInputStream;
|
4
|
+
import java.io.IOException;
|
5
|
+
import java.io.InputStream;
|
6
|
+
import java.io.PushbackInputStream;
|
7
|
+
|
8
|
+
|
9
|
+
public class PartialFileInputStream extends InputStream
|
10
|
+
{
|
11
|
+
private final PushbackInputStream original;
|
12
|
+
private long start;
|
13
|
+
private long end;
|
14
|
+
private long current;
|
15
|
+
private boolean eof;
|
16
|
+
|
17
|
+
public PartialFileInputStream(InputStream original, long start, long end)
|
18
|
+
{
|
19
|
+
this.original = new PushbackInputStream(new BufferedInputStream(original));
|
20
|
+
this.start = start;
|
21
|
+
this.end = end;
|
22
|
+
current = -1;
|
23
|
+
}
|
24
|
+
|
25
|
+
@Override
|
26
|
+
public int read(byte[] b) throws IOException
|
27
|
+
{
|
28
|
+
return read(b, 0, b.length);
|
29
|
+
}
|
30
|
+
|
31
|
+
@Override
|
32
|
+
public int read(byte[] b, int off, int len) throws IOException
|
33
|
+
{
|
34
|
+
initializeIfNeeded();
|
35
|
+
|
36
|
+
if (eof) {
|
37
|
+
return -1;
|
38
|
+
}
|
39
|
+
|
40
|
+
int read = original.read(b, off, len);
|
41
|
+
if (read < 0) {
|
42
|
+
eof = true;
|
43
|
+
return -1;
|
44
|
+
}
|
45
|
+
|
46
|
+
current += read;
|
47
|
+
if (current >= end) {
|
48
|
+
for (int i = Math.max((int)(end - 1 - current + read), 0); i < read; i++) {
|
49
|
+
if (b[off + i] == '\n') {
|
50
|
+
eof = true;
|
51
|
+
return i + 1;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (b[off + i] == '\r') {
|
55
|
+
int next = (i < read ? b[off + i + 1] : prefetch());
|
56
|
+
if (next != '\n') {
|
57
|
+
eof = true;
|
58
|
+
return i + 1;
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
return read;
|
65
|
+
}
|
66
|
+
|
67
|
+
@Override
|
68
|
+
public int read() throws IOException
|
69
|
+
{
|
70
|
+
initializeIfNeeded();
|
71
|
+
|
72
|
+
if (eof) {
|
73
|
+
return -1;
|
74
|
+
}
|
75
|
+
|
76
|
+
int read = original.read();
|
77
|
+
current++;
|
78
|
+
|
79
|
+
if (read < 0) {
|
80
|
+
eof = true;
|
81
|
+
return -1;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (current >= end) {
|
85
|
+
if (read == '\n' || read == '\r' && prefetch() != '\n') {
|
86
|
+
eof = true;
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
return read;
|
91
|
+
}
|
92
|
+
|
93
|
+
@Override
|
94
|
+
public long skip(long n) throws IOException
|
95
|
+
{
|
96
|
+
throw new IOException("Skip not supported.");
|
97
|
+
/*
|
98
|
+
long skip = original.skip(n);
|
99
|
+
current += skip;
|
100
|
+
return skip;
|
101
|
+
*/
|
102
|
+
}
|
103
|
+
|
104
|
+
@Override
|
105
|
+
public int available() throws IOException
|
106
|
+
{
|
107
|
+
return 0;
|
108
|
+
}
|
109
|
+
|
110
|
+
@Override
|
111
|
+
public void close() throws IOException
|
112
|
+
{
|
113
|
+
original.close();
|
114
|
+
}
|
115
|
+
|
116
|
+
private void initializeIfNeeded() throws IOException
|
117
|
+
{
|
118
|
+
if (current >= start) {
|
119
|
+
return;
|
120
|
+
|
121
|
+
}
|
122
|
+
if (start == 0) {
|
123
|
+
current = 0;
|
124
|
+
} else {
|
125
|
+
current = original.skip(--start);
|
126
|
+
if (current != start) {
|
127
|
+
throw new IOException("Cannot skip.");
|
128
|
+
}
|
129
|
+
|
130
|
+
int c;
|
131
|
+
while ((c = original.read()) >= 0) {
|
132
|
+
start++;
|
133
|
+
current++;
|
134
|
+
|
135
|
+
if (c == '\n' || c == '\r' && prefetch() != '\n') {
|
136
|
+
break;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
if (start >= end) {
|
142
|
+
eof = true;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
private int prefetch() throws IOException
|
147
|
+
{
|
148
|
+
int c = original.read();
|
149
|
+
if (c >= 0) {
|
150
|
+
original.unread(c);
|
151
|
+
}
|
152
|
+
return c;
|
153
|
+
}
|
154
|
+
}
|
@@ -1,42 +1,42 @@
|
|
1
|
-
package org.embulk.output.oracle;
|
2
|
-
|
3
|
-
import java.net.URL;
|
4
|
-
import java.net.URLClassLoader;
|
5
|
-
import java.util.List;
|
6
|
-
|
7
|
-
public class ChildFirstClassLoader
|
8
|
-
extends URLClassLoader
|
9
|
-
{
|
10
|
-
public ChildFirstClassLoader(List<URL> urls, ClassLoader parent)
|
11
|
-
{
|
12
|
-
super(urls.toArray(new URL[urls.size()]), parent);
|
13
|
-
}
|
14
|
-
|
15
|
-
@Override
|
16
|
-
protected Class<?> loadClass(String name, boolean resolve)
|
17
|
-
throws ClassNotFoundException
|
18
|
-
{
|
19
|
-
synchronized (getClassLoadingLock(name)) {
|
20
|
-
Class<?> loadedClass = findLoadedClass(name);
|
21
|
-
if (loadedClass != null) {
|
22
|
-
return resolveClass(loadedClass, resolve);
|
23
|
-
}
|
24
|
-
|
25
|
-
try {
|
26
|
-
return resolveClass(findClass(name), resolve);
|
27
|
-
} catch (ClassNotFoundException ignored) {
|
28
|
-
}
|
29
|
-
|
30
|
-
return super.loadClass(name, resolve);
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
private Class<?> resolveClass(Class<?> clazz, boolean resolve)
|
35
|
-
{
|
36
|
-
if (resolve) {
|
37
|
-
resolveClass(clazz);
|
38
|
-
}
|
39
|
-
return clazz;
|
40
|
-
}
|
41
|
-
|
42
|
-
}
|
1
|
+
package org.embulk.output.oracle;
|
2
|
+
|
3
|
+
import java.net.URL;
|
4
|
+
import java.net.URLClassLoader;
|
5
|
+
import java.util.List;
|
6
|
+
|
7
|
+
public class ChildFirstClassLoader
|
8
|
+
extends URLClassLoader
|
9
|
+
{
|
10
|
+
public ChildFirstClassLoader(List<URL> urls, ClassLoader parent)
|
11
|
+
{
|
12
|
+
super(urls.toArray(new URL[urls.size()]), parent);
|
13
|
+
}
|
14
|
+
|
15
|
+
@Override
|
16
|
+
protected Class<?> loadClass(String name, boolean resolve)
|
17
|
+
throws ClassNotFoundException
|
18
|
+
{
|
19
|
+
synchronized (getClassLoadingLock(name)) {
|
20
|
+
Class<?> loadedClass = findLoadedClass(name);
|
21
|
+
if (loadedClass != null) {
|
22
|
+
return resolveClass(loadedClass, resolve);
|
23
|
+
}
|
24
|
+
|
25
|
+
try {
|
26
|
+
return resolveClass(findClass(name), resolve);
|
27
|
+
} catch (ClassNotFoundException ignored) {
|
28
|
+
}
|
29
|
+
|
30
|
+
return super.loadClass(name, resolve);
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
private Class<?> resolveClass(Class<?> clazz, boolean resolve)
|
35
|
+
{
|
36
|
+
if (resolve) {
|
37
|
+
resolveClass(clazz);
|
38
|
+
}
|
39
|
+
return clazz;
|
40
|
+
}
|
41
|
+
|
42
|
+
}
|
@@ -1,120 +1,120 @@
|
|
1
|
-
package org.embulk.output.oracle;
|
2
|
-
|
3
|
-
import java.io.BufferedReader;
|
4
|
-
import java.io.BufferedWriter;
|
5
|
-
import java.io.File;
|
6
|
-
import java.io.FileReader;
|
7
|
-
import java.io.FileWriter;
|
8
|
-
import java.io.IOException;
|
9
|
-
import java.net.URISyntaxException;
|
10
|
-
import java.util.ArrayList;
|
11
|
-
import java.util.Arrays;
|
12
|
-
import java.util.List;
|
13
|
-
import java.util.regex.Matcher;
|
14
|
-
import java.util.regex.Pattern;
|
15
|
-
|
16
|
-
import org.embulk.EmbulkService;
|
17
|
-
import org.embulk.config.ConfigLoader;
|
18
|
-
import org.embulk.config.ConfigSource;
|
19
|
-
import org.embulk.exec.ExecutionResult;
|
20
|
-
import org.embulk.exec.
|
21
|
-
import org.embulk.plugin.InjectedPluginSource;
|
22
|
-
import org.embulk.spi.ExecSession;
|
23
|
-
|
24
|
-
import com.google.inject.Binder;
|
25
|
-
import com.google.inject.Injector;
|
26
|
-
import com.google.inject.Module;
|
27
|
-
|
28
|
-
public class EmbulkPluginTester
|
29
|
-
{
|
30
|
-
private static class PluginDefinition
|
31
|
-
{
|
32
|
-
public final Class<?> iface;
|
33
|
-
public final String name;
|
34
|
-
public final Class<?> impl;
|
35
|
-
|
36
|
-
|
37
|
-
public PluginDefinition(Class<?> iface, String name, Class<?> impl)
|
38
|
-
{
|
39
|
-
this.iface = iface;
|
40
|
-
this.name = name;
|
41
|
-
this.impl = impl;
|
42
|
-
}
|
43
|
-
|
44
|
-
}
|
45
|
-
|
46
|
-
private final List<PluginDefinition> plugins = new ArrayList<PluginDefinition>();
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
public EmbulkPluginTester()
|
51
|
-
{
|
52
|
-
}
|
53
|
-
|
54
|
-
public EmbulkPluginTester(Class<?> iface, String name, Class<?> impl)
|
55
|
-
{
|
56
|
-
addPlugin(iface, name, impl);
|
57
|
-
}
|
58
|
-
|
59
|
-
public void addPlugin(Class<?> iface, String name, Class<?> impl)
|
60
|
-
{
|
61
|
-
plugins.add(new PluginDefinition(iface, name, impl));
|
62
|
-
}
|
63
|
-
|
64
|
-
public void run(String ymlPath) throws Exception
|
65
|
-
{
|
66
|
-
EmbulkService service = new EmbulkService(new EmptyConfigSource()) {
|
67
|
-
protected Iterable<? extends Module> getAdditionalModules(ConfigSource systemConfig)
|
68
|
-
{
|
69
|
-
return Arrays.asList(new Module()
|
70
|
-
{
|
71
|
-
@Override
|
72
|
-
public void configure(Binder binder)
|
73
|
-
{
|
74
|
-
for (PluginDefinition plugin : plugins) {
|
75
|
-
InjectedPluginSource.registerPluginTo(binder, plugin.iface, plugin.name, plugin.impl);
|
76
|
-
}
|
77
|
-
}
|
78
|
-
});
|
79
|
-
}
|
80
|
-
};
|
81
|
-
Injector injector = service.getInjector();
|
82
|
-
ConfigSource config = injector.getInstance(ConfigLoader.class).fromYamlFile(new File(ymlPath));
|
83
|
-
ExecSession session = new ExecSession(injector, config);
|
84
|
-
|
85
|
-
ExecutionResult result =
|
86
|
-
}
|
87
|
-
|
88
|
-
private File convert(String yml) {
|
89
|
-
try {
|
90
|
-
File rootPath = new File(EmbulkPluginTester.class.getResource("/resource.txt").toURI()).getParentFile();
|
91
|
-
File ymlPath = new File(EmbulkPluginTester.class.getResource(yml).toURI());
|
92
|
-
File tempYmlPath = new File(ymlPath.getParentFile(), "temp-" + ymlPath.getName());
|
93
|
-
Pattern pathPrefixPattern = Pattern.compile("^ *path(_prefix)?: '(.*)'$");
|
94
|
-
try (BufferedReader reader = new BufferedReader(new FileReader(ymlPath))) {
|
95
|
-
try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempYmlPath))) {
|
96
|
-
String line;
|
97
|
-
while ((line = reader.readLine()) != null) {
|
98
|
-
Matcher matcher = pathPrefixPattern.matcher(line);
|
99
|
-
if (matcher.matches()) {
|
100
|
-
int group = 2;
|
101
|
-
writer.write(line.substring(0, matcher.start(group)));
|
102
|
-
writer.write(new File(rootPath, matcher.group(group)).getAbsolutePath());
|
103
|
-
writer.write(line.substring(matcher.end(group)));
|
104
|
-
} else {
|
105
|
-
writer.write(line);
|
106
|
-
}
|
107
|
-
writer.newLine();
|
108
|
-
}
|
109
|
-
}
|
110
|
-
}
|
111
|
-
return tempYmlPath.getAbsoluteFile();
|
112
|
-
|
113
|
-
} catch (IOException e) {
|
114
|
-
throw new RuntimeException(e);
|
115
|
-
} catch (URISyntaxException e) {
|
116
|
-
throw new RuntimeException(e);
|
117
|
-
}
|
118
|
-
}
|
119
|
-
|
120
|
-
}
|
1
|
+
package org.embulk.output.oracle;
|
2
|
+
|
3
|
+
import java.io.BufferedReader;
|
4
|
+
import java.io.BufferedWriter;
|
5
|
+
import java.io.File;
|
6
|
+
import java.io.FileReader;
|
7
|
+
import java.io.FileWriter;
|
8
|
+
import java.io.IOException;
|
9
|
+
import java.net.URISyntaxException;
|
10
|
+
import java.util.ArrayList;
|
11
|
+
import java.util.Arrays;
|
12
|
+
import java.util.List;
|
13
|
+
import java.util.regex.Matcher;
|
14
|
+
import java.util.regex.Pattern;
|
15
|
+
|
16
|
+
import org.embulk.EmbulkService;
|
17
|
+
import org.embulk.config.ConfigLoader;
|
18
|
+
import org.embulk.config.ConfigSource;
|
19
|
+
import org.embulk.exec.ExecutionResult;
|
20
|
+
import org.embulk.exec.BulkLoader;
|
21
|
+
import org.embulk.plugin.InjectedPluginSource;
|
22
|
+
import org.embulk.spi.ExecSession;
|
23
|
+
|
24
|
+
import com.google.inject.Binder;
|
25
|
+
import com.google.inject.Injector;
|
26
|
+
import com.google.inject.Module;
|
27
|
+
|
28
|
+
public class EmbulkPluginTester
|
29
|
+
{
|
30
|
+
private static class PluginDefinition
|
31
|
+
{
|
32
|
+
public final Class<?> iface;
|
33
|
+
public final String name;
|
34
|
+
public final Class<?> impl;
|
35
|
+
|
36
|
+
|
37
|
+
public PluginDefinition(Class<?> iface, String name, Class<?> impl)
|
38
|
+
{
|
39
|
+
this.iface = iface;
|
40
|
+
this.name = name;
|
41
|
+
this.impl = impl;
|
42
|
+
}
|
43
|
+
|
44
|
+
}
|
45
|
+
|
46
|
+
private final List<PluginDefinition> plugins = new ArrayList<PluginDefinition>();
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
public EmbulkPluginTester()
|
51
|
+
{
|
52
|
+
}
|
53
|
+
|
54
|
+
public EmbulkPluginTester(Class<?> iface, String name, Class<?> impl)
|
55
|
+
{
|
56
|
+
addPlugin(iface, name, impl);
|
57
|
+
}
|
58
|
+
|
59
|
+
public void addPlugin(Class<?> iface, String name, Class<?> impl)
|
60
|
+
{
|
61
|
+
plugins.add(new PluginDefinition(iface, name, impl));
|
62
|
+
}
|
63
|
+
|
64
|
+
public void run(String ymlPath) throws Exception
|
65
|
+
{
|
66
|
+
EmbulkService service = new EmbulkService(new EmptyConfigSource()) {
|
67
|
+
protected Iterable<? extends Module> getAdditionalModules(ConfigSource systemConfig)
|
68
|
+
{
|
69
|
+
return Arrays.asList(new Module()
|
70
|
+
{
|
71
|
+
@Override
|
72
|
+
public void configure(Binder binder)
|
73
|
+
{
|
74
|
+
for (PluginDefinition plugin : plugins) {
|
75
|
+
InjectedPluginSource.registerPluginTo(binder, plugin.iface, plugin.name, plugin.impl);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
});
|
79
|
+
}
|
80
|
+
};
|
81
|
+
Injector injector = service.getInjector();
|
82
|
+
ConfigSource config = injector.getInstance(ConfigLoader.class).fromYamlFile(new File(ymlPath));
|
83
|
+
ExecSession session = new ExecSession(injector, config);
|
84
|
+
BulkLoader loader = injector.getInstance(BulkLoader.class);
|
85
|
+
ExecutionResult result = loader.run(session, config);
|
86
|
+
}
|
87
|
+
|
88
|
+
private File convert(String yml) {
|
89
|
+
try {
|
90
|
+
File rootPath = new File(EmbulkPluginTester.class.getResource("/resource.txt").toURI()).getParentFile();
|
91
|
+
File ymlPath = new File(EmbulkPluginTester.class.getResource(yml).toURI());
|
92
|
+
File tempYmlPath = new File(ymlPath.getParentFile(), "temp-" + ymlPath.getName());
|
93
|
+
Pattern pathPrefixPattern = Pattern.compile("^ *path(_prefix)?: '(.*)'$");
|
94
|
+
try (BufferedReader reader = new BufferedReader(new FileReader(ymlPath))) {
|
95
|
+
try (BufferedWriter writer = new BufferedWriter(new FileWriter(tempYmlPath))) {
|
96
|
+
String line;
|
97
|
+
while ((line = reader.readLine()) != null) {
|
98
|
+
Matcher matcher = pathPrefixPattern.matcher(line);
|
99
|
+
if (matcher.matches()) {
|
100
|
+
int group = 2;
|
101
|
+
writer.write(line.substring(0, matcher.start(group)));
|
102
|
+
writer.write(new File(rootPath, matcher.group(group)).getAbsolutePath());
|
103
|
+
writer.write(line.substring(matcher.end(group)));
|
104
|
+
} else {
|
105
|
+
writer.write(line);
|
106
|
+
}
|
107
|
+
writer.newLine();
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
111
|
+
return tempYmlPath.getAbsoluteFile();
|
112
|
+
|
113
|
+
} catch (IOException e) {
|
114
|
+
throw new RuntimeException(e);
|
115
|
+
} catch (URISyntaxException e) {
|
116
|
+
throw new RuntimeException(e);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
}
|