embulk-output-oracle 0.4.1 → 0.4.2

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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +160 -160
  3. data/build.gradle +6 -6
  4. data/classpath/embulk-output-jdbc-0.4.2.jar +0 -0
  5. data/classpath/{embulk-output-oracle-0.4.1.jar → embulk-output-oracle-0.4.2.jar} +0 -0
  6. data/lib/embulk/output/oracle.rb +3 -3
  7. data/src/main/cpp/common/dir-path-load.cpp +424 -424
  8. data/src/main/cpp/common/dir-path-load.h +36 -36
  9. data/src/main/cpp/common/embulk-output-oracle.cpp +196 -196
  10. data/src/main/cpp/common/org_embulk_output_oracle_oci_OCI.h +77 -77
  11. data/src/main/cpp/linux/build.sh +21 -21
  12. data/src/main/cpp/win/build.bat +31 -31
  13. data/src/main/cpp/win/dllmain.cpp +25 -25
  14. data/src/main/cpp/win/embulk-output-oracle.sln +39 -39
  15. data/src/main/cpp/win/embulk-output-oracle.vcxproj +175 -175
  16. data/src/main/java/org/embulk/output/OracleOutputPlugin.java +151 -153
  17. data/src/main/java/org/embulk/output/oracle/DirectBatchInsert.java +290 -290
  18. data/src/main/java/org/embulk/output/oracle/InsertMethod.java +8 -8
  19. data/src/main/java/org/embulk/output/oracle/OracleCharset.java +32 -32
  20. data/src/main/java/org/embulk/output/oracle/OracleOutputConnection.java +179 -165
  21. data/src/main/java/org/embulk/output/oracle/OracleOutputConnector.java +49 -49
  22. data/src/main/java/org/embulk/output/oracle/TimestampFormat.java +37 -37
  23. data/src/main/java/org/embulk/output/oracle/oci/ColumnDefinition.java +26 -26
  24. data/src/main/java/org/embulk/output/oracle/oci/OCI.java +139 -139
  25. data/src/main/java/org/embulk/output/oracle/oci/OCIManager.java +64 -64
  26. data/src/main/java/org/embulk/output/oracle/oci/OCIWrapper.java +96 -96
  27. data/src/main/java/org/embulk/output/oracle/oci/RowBuffer.java +105 -105
  28. data/src/main/java/org/embulk/output/oracle/oci/TableDefinition.java +24 -24
  29. data/src/test/cpp/common/embulk-output-oracle-test.cpp +69 -69
  30. data/src/test/cpp/linux/build.sh +19 -19
  31. data/src/test/cpp/win/build.bat +28 -28
  32. data/src/test/cpp/win/embulk-output-oracle-test.vcxproj +154 -154
  33. data/src/test/java/org/embulk/input/filesplit/LocalFileSplitInputPlugin.java +185 -187
  34. data/src/test/java/org/embulk/input/filesplit/PartialFile.java +49 -49
  35. data/src/test/java/org/embulk/input/filesplit/PartialFileInputStream.java +154 -154
  36. data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTest.java +50 -25
  37. data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTestImpl.java +548 -540
  38. data/src/test/java/org/embulk/output/oracle/TimestampFormatTest.java +57 -57
  39. data/src/test/java/org/embulk/output/tester/EmbulkPluginTester.java +79 -0
  40. data/src/test/resources/data/test1/test1.csv +3 -3
  41. data/src/test/resources/dummy.txt +1 -0
  42. data/src/test/resources/yml/test-insert-direct-direct-method.yml +26 -26
  43. data/src/test/resources/yml/test-insert-direct-empty.yml +25 -25
  44. data/src/test/resources/yml/test-insert-direct-oci-method-split.yml +28 -28
  45. data/src/test/resources/yml/test-insert-direct-oci-method.yml +28 -28
  46. data/src/test/resources/yml/test-insert-direct.yml +25 -25
  47. data/src/test/resources/yml/test-insert-empty.yml +27 -27
  48. data/src/test/resources/yml/test-insert.yml +25 -27
  49. data/src/test/resources/yml/test-replace-empty.yml +31 -31
  50. data/src/test/resources/yml/test-replace-long-name-multibyte.yml +31 -31
  51. data/src/test/resources/yml/test-replace-long-name.yml +31 -31
  52. data/src/test/resources/yml/test-replace.yml +31 -31
  53. data/src/test/resources/yml/test-string-timestamp.yml +28 -28
  54. data/src/test/resources/yml/test-url.yml +24 -24
  55. metadata +6 -8
  56. data/classpath/embulk-output-jdbc-0.4.1.jar +0 -0
  57. data/lib/embulk/linux_x64/libembulk-output-oracle.so +0 -0
  58. data/src/test/java/org/embulk/output/oracle/ChildFirstClassLoader.java +0 -42
  59. data/src/test/java/org/embulk/output/oracle/EmbulkPluginTester.java +0 -124
  60. data/src/test/java/org/embulk/output/oracle/EmptyConfigSource.java +0 -105
@@ -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
+ }
@@ -4,8 +4,14 @@ import java.io.File;
4
4
  import java.lang.reflect.Method;
5
5
  import java.net.URL;
6
6
  import java.util.ArrayList;
7
+ import java.util.Arrays;
7
8
  import java.util.List;
8
9
 
10
+ import org.embulk.input.filesplit.LocalFileSplitInputPlugin;
11
+ import org.embulk.output.tester.EmbulkPluginTester;
12
+ import org.embulk.plugin.PluginClassLoader;
13
+ import org.embulk.spi.InputPlugin;
14
+ import org.embulk.spi.OutputPlugin;
9
15
  import org.junit.BeforeClass;
10
16
  import org.junit.Test;
11
17
 
@@ -26,6 +32,8 @@ public class OracleOutputPluginTest
26
32
  private static List<NamedObject> testObjects = new ArrayList<NamedObject>();
27
33
  private static NamedObject test12c;
28
34
  private static NamedObject test11g;
35
+ private static EmbulkPluginTester tester = new EmbulkPluginTester();
36
+
29
37
 
30
38
  @BeforeClass
31
39
  public static void beforeClass() throws Exception
@@ -35,14 +43,16 @@ public class OracleOutputPluginTest
35
43
  System.setProperty("file.encoding", "MS932");
36
44
  }
37
45
 
38
- test12c = createTest("/driver/12c/ojdbc7.jar");
46
+ tester.addPlugin(InputPlugin.class, "filesplit", LocalFileSplitInputPlugin.class);
47
+
48
+ test12c = createTest("oracle12", "/driver/12c/ojdbc7.jar");
39
49
  if (test12c == null) {
40
50
  System.out.println("Warning: you should put ojdbc7.jar (version 12c) on 'test/resources/driver/12c' directory.");
41
51
  } else {
42
52
  testObjects.add(test12c);
43
53
  }
44
54
 
45
- test11g = createTest("/driver/11g/ojdbc6.jar");
55
+ test11g = createTest("oracle11", "/driver/11g/ojdbc6.jar");
46
56
  if (test11g == null) {
47
57
  System.out.println("Warning: you should put ojdbc6.jar (version 11g Release 2) on 'test/resources/driver/11g' directory.");
48
58
  } else {
@@ -50,25 +60,37 @@ public class OracleOutputPluginTest
50
60
  }
51
61
  }
52
62
 
53
- private static NamedObject createTest(String jdbcDriverPath) throws Exception
63
+ private static NamedObject createTest(String pluginName, String jdbcDriverPath) throws Exception
54
64
  {
55
- String[] classPaths = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
65
+ // Load OracleOutputPluginTestImpl, Oracle JDBC Driver, embulk-output-oracle by another ClassLoader
66
+ // in order to test for different driver versions.
67
+
56
68
  List<URL> urls = new ArrayList<URL>();
57
- for (String classPath : classPaths) {
58
- urls.add(new File(classPath).toURI().toURL());
59
- }
60
- // load Oracle JDBC driver dynamically, in order to enable to build without the driver.
61
- URL url = OracleOutputPluginTest.class.getResource(jdbcDriverPath);
62
- if (url == null) {
69
+
70
+ File testRoot = new File(OracleOutputPluginTest.class.getResource("/dummy.txt").toURI()).getParentFile();
71
+ String pluginClassName = "org.embulk.output.OracleOutputPlugin";
72
+ URL pluginClassUrl = OracleOutputPluginTest.class.getResource("/" +pluginClassName.replace('.', '/') + ".class");
73
+ File root = new File(pluginClassUrl.toURI()).getParentFile().getParentFile().getParentFile().getParentFile();
74
+
75
+ urls.add(root.toURI().toURL());
76
+ urls.add(testRoot.toURI().toURL());
77
+
78
+ URL jdbcDriverUrl = OracleOutputPluginTest.class.getResource(jdbcDriverPath);
79
+ if (jdbcDriverUrl == null) {
63
80
  return null;
64
81
  }
65
82
 
66
- urls.add(url);
67
- ClassLoader classLoader = new ChildFirstClassLoader(urls, OracleOutputPluginTest.class.getClassLoader());
83
+ urls.add(jdbcDriverUrl);
84
+ ClassLoader classLoader = new PluginClassLoader(urls, OracleOutputPluginTest.class.getClassLoader(),
85
+ Arrays.asList(EmbulkPluginTester.class.getPackage().getName()), new ArrayList<String>());
68
86
  Thread.currentThread().setContextClassLoader(classLoader);
87
+ tester.addPlugin(OutputPlugin.class, pluginName, classLoader.loadClass(pluginClassName));
69
88
 
70
89
  Class<?> testClass = classLoader.loadClass(OracleOutputPluginTest.class.getName() + "Impl");
71
90
  final Object testObject = testClass.newInstance();
91
+ invoke(testObject, "setTester", tester);
92
+ invoke(testObject, "setPluginName", pluginName);
93
+
72
94
  final String version = (String)invoke(testObject, "beforeClass");
73
95
  if (version == null) {
74
96
  return null;
@@ -78,7 +100,6 @@ public class OracleOutputPluginTest
78
100
 
79
101
  private static void invoke(String methodName) throws Exception
80
102
  {
81
- //invoke(test12c, methodName);
82
103
  for (NamedObject testObject : testObjects) {
83
104
  invoke(testObject, methodName);
84
105
  }
@@ -93,59 +114,63 @@ public class OracleOutputPluginTest
93
114
  return null;
94
115
  }
95
116
 
96
- private static Object invoke(Object testObject, String methodName) throws Exception
117
+ private static Object invoke(Object testObject, String methodName, Object... arguments) throws Exception
97
118
  {
98
119
  if (testObject != null) {
99
120
  Thread.currentThread().setContextClassLoader(testObject.getClass().getClassLoader());
100
- Method method = testObject.getClass().getMethod(methodName);
101
- return method.invoke(testObject);
121
+ Class<?>[] parameterTypes = new Class<?>[arguments.length];
122
+ for (int i = 0; i < arguments.length; i++) {
123
+ parameterTypes[i] = arguments[i].getClass();
124
+ }
125
+ Method method = testObject.getClass().getMethod(methodName, parameterTypes);
126
+ return method.invoke(testObject, arguments);
102
127
  }
103
128
  return null;
104
129
  }
105
- /*
130
+
106
131
  @Test
107
132
  public void testInsert() throws Exception
108
133
  {
109
134
  invoke("testInsert");
110
135
  }
111
- */
136
+
112
137
  @Test
113
138
  public void testInsertEmpty() throws Exception
114
139
  {
115
140
  invoke("testInsertEmpty");
116
141
  }
117
- /*
142
+
118
143
  @Test
119
144
  public void testInsertDirect() throws Exception
120
145
  {
121
146
  invoke("testInsertDirect");
122
147
  }
123
- /*
148
+
124
149
  @Test
125
150
  public void testInsertDirectCreate() throws Exception
126
151
  {
127
152
  invoke("testInsertDirectCreate");
128
153
  }
129
- */
154
+
130
155
  @Test
131
156
  public void testInsertDirectEmpty() throws Exception
132
157
  {
133
158
  invoke("testInsertDirectEmpty");
134
159
  }
135
- /*
160
+
136
161
  @Test
137
162
  public void testInsertDirectDirectMethod() throws Exception
138
163
  {
139
164
  // ArrayIndexOutOfBoundsException thrown if using 12c driver.
140
165
  invoke(test11g, "testInsertDirectDirectMethod");
141
166
  }
142
- *//*
167
+
143
168
  @Test
144
169
  public void testInsertDirectOCIMethod() throws Exception
145
170
  {
146
171
  invoke("testInsertDirectOCIMethod");
147
172
  }
148
- /*
173
+
149
174
  @Test
150
175
  public void testInsertDirectOCIMethodSplit() throws Exception
151
176
  {
@@ -192,5 +217,5 @@ public class OracleOutputPluginTest
192
217
  public void testStringTimestamp() throws Exception
193
218
  {
194
219
  invoke("testStringTimestamp");
195
- }*/
220
+ }
196
221
  }