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.
Files changed (56) 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.0.jar → embulk-output-jdbc-0.4.1.jar} +0 -0
  5. data/classpath/{embulk-output-oracle-0.4.0.jar → embulk-output-oracle-0.4.1.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 +153 -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 +165 -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 +187 -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/ChildFirstClassLoader.java +42 -42
  37. data/src/test/java/org/embulk/output/oracle/EmbulkPluginTester.java +124 -120
  38. data/src/test/java/org/embulk/output/oracle/EmptyConfigSource.java +105 -100
  39. data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTest.java +38 -14
  40. data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTestImpl.java +540 -484
  41. data/src/test/java/org/embulk/output/oracle/TimestampFormatTest.java +57 -57
  42. data/src/test/resources/data/test1/test1.csv +3 -3
  43. data/src/test/resources/yml/test-insert-direct-direct-method.yml +26 -0
  44. data/src/test/resources/yml/test-insert-direct-empty.yml +25 -0
  45. data/src/test/resources/yml/{test-insert-oci-split.yml → test-insert-direct-oci-method-split.yml} +28 -28
  46. data/src/test/resources/yml/{test-insert-oci.yml → test-insert-direct-oci-method.yml} +28 -28
  47. data/src/test/resources/yml/test-insert-direct.yml +25 -26
  48. data/src/test/resources/yml/test-insert-empty.yml +27 -0
  49. data/src/test/resources/yml/test-insert.yml +27 -25
  50. data/src/test/resources/yml/test-replace-empty.yml +31 -0
  51. data/src/test/resources/yml/test-replace-long-name-multibyte.yml +31 -31
  52. data/src/test/resources/yml/test-replace-long-name.yml +31 -31
  53. data/src/test/resources/yml/test-replace.yml +31 -31
  54. data/src/test/resources/yml/test-string-timestamp.yml +28 -28
  55. data/src/test/resources/yml/test-url.yml +24 -24
  56. metadata +10 -6
@@ -1,96 +1,96 @@
1
- package org.embulk.output.oracle.oci;
2
-
3
- import java.nio.charset.Charset;
4
- import java.sql.SQLException;
5
-
6
- import org.embulk.spi.Exec;
7
- import org.slf4j.Logger;
8
-
9
-
10
- public class OCIWrapper implements AutoCloseable
11
- {
12
- private final Logger logger = Exec.getLogger(getClass());
13
-
14
- private final OCI oci = new OCI();
15
- // used for messages
16
- private final Charset defaultCharset;
17
- private byte[] context;
18
- private boolean errorOccured;
19
- private boolean committedOrRollbacked;
20
-
21
-
22
- public OCIWrapper()
23
- {
24
- // enable to change default encoding for test
25
- defaultCharset = Charset.forName(System.getProperty("file.encoding"));
26
- context = oci.createContext();
27
- }
28
-
29
- public void open(String dbName, String userName, String password) throws SQLException
30
- {
31
- if (!oci.open(context, dbName, userName, password)) {
32
- throwException();
33
- }
34
- }
35
-
36
- public void prepareLoad(TableDefinition tableDefinition) throws SQLException
37
- {
38
- if (!oci.prepareLoad(context, tableDefinition)) {
39
- throwException();
40
- }
41
- }
42
-
43
- public void loadBuffer(byte[] buffer, int rowCount) throws SQLException
44
- {
45
- if (!oci.loadBuffer(context, buffer, rowCount)) {
46
- throwException();
47
- }
48
- }
49
-
50
- public void commit() throws SQLException
51
- {
52
- committedOrRollbacked = true;
53
- logger.info("OCI : start to commit.");
54
- if (!oci.commit(context)) {
55
- throwException();
56
- }
57
- }
58
-
59
- public void rollback() throws SQLException
60
- {
61
- committedOrRollbacked = true;
62
- logger.info("OCI : start to rollback.");
63
- if (!oci.rollback(context)) {
64
- throwException();
65
- }
66
- }
67
-
68
- private void throwException() throws SQLException
69
- {
70
- errorOccured = true;
71
- String message = new String(oci.getLasetMessage(context), defaultCharset);
72
- logger.error(message);
73
- throw new SQLException(message);
74
- }
75
-
76
-
77
- @Override
78
- public void close() throws SQLException
79
- {
80
- if (context != null) {
81
- try {
82
- if (!committedOrRollbacked) {
83
- if (errorOccured) {
84
- rollback();
85
- } else {
86
- commit();
87
- }
88
- }
89
- } finally {
90
- oci.close(context);
91
- context = null;
92
- }
93
- }
94
- }
95
-
96
- }
1
+ package org.embulk.output.oracle.oci;
2
+
3
+ import java.nio.charset.Charset;
4
+ import java.sql.SQLException;
5
+
6
+ import org.embulk.spi.Exec;
7
+ import org.slf4j.Logger;
8
+
9
+
10
+ public class OCIWrapper implements AutoCloseable
11
+ {
12
+ private final Logger logger = Exec.getLogger(getClass());
13
+
14
+ private final OCI oci = new OCI();
15
+ // used for messages
16
+ private final Charset defaultCharset;
17
+ private byte[] context;
18
+ private boolean errorOccured;
19
+ private boolean committedOrRollbacked;
20
+
21
+
22
+ public OCIWrapper()
23
+ {
24
+ // enable to change default encoding for test
25
+ defaultCharset = Charset.forName(System.getProperty("file.encoding"));
26
+ context = oci.createContext();
27
+ }
28
+
29
+ public void open(String dbName, String userName, String password) throws SQLException
30
+ {
31
+ if (!oci.open(context, dbName, userName, password)) {
32
+ throwException();
33
+ }
34
+ }
35
+
36
+ public void prepareLoad(TableDefinition tableDefinition) throws SQLException
37
+ {
38
+ if (!oci.prepareLoad(context, tableDefinition)) {
39
+ throwException();
40
+ }
41
+ }
42
+
43
+ public void loadBuffer(byte[] buffer, int rowCount) throws SQLException
44
+ {
45
+ if (!oci.loadBuffer(context, buffer, rowCount)) {
46
+ throwException();
47
+ }
48
+ }
49
+
50
+ public void commit() throws SQLException
51
+ {
52
+ committedOrRollbacked = true;
53
+ logger.info("OCI : start to commit.");
54
+ if (!oci.commit(context)) {
55
+ throwException();
56
+ }
57
+ }
58
+
59
+ public void rollback() throws SQLException
60
+ {
61
+ committedOrRollbacked = true;
62
+ logger.info("OCI : start to rollback.");
63
+ if (!oci.rollback(context)) {
64
+ throwException();
65
+ }
66
+ }
67
+
68
+ private void throwException() throws SQLException
69
+ {
70
+ errorOccured = true;
71
+ String message = new String(oci.getLasetMessage(context), defaultCharset);
72
+ logger.error(message);
73
+ throw new SQLException(message);
74
+ }
75
+
76
+
77
+ @Override
78
+ public void close() throws SQLException
79
+ {
80
+ if (context != null) {
81
+ try {
82
+ if (!committedOrRollbacked) {
83
+ if (errorOccured) {
84
+ rollback();
85
+ } else {
86
+ commit();
87
+ }
88
+ }
89
+ } finally {
90
+ oci.close(context);
91
+ context = null;
92
+ }
93
+ }
94
+ }
95
+
96
+ }
@@ -1,105 +1,105 @@
1
- package org.embulk.output.oracle.oci;
2
-
3
- import java.math.BigDecimal;
4
- import java.nio.ByteBuffer;
5
- import java.nio.charset.Charset;
6
-
7
-
8
- public class RowBuffer
9
- {
10
- private final TableDefinition table;
11
- private final int rowCount;
12
- private final byte[] buffer;
13
- private int currentRow = 0;
14
- private int currentColumn = 0;
15
- private int currentPosition = 0;
16
- private final Charset charset;
17
-
18
- public RowBuffer(TableDefinition table, int rowCount, Charset charset)
19
- {
20
- this.table = table;
21
- this.rowCount = rowCount;
22
- this.charset = charset;
23
-
24
- int rowSize = 0;
25
- for (ColumnDefinition column : table.columns) {
26
- rowSize += column.columnSize;
27
- }
28
-
29
- buffer = new byte[rowSize * rowCount];
30
- }
31
-
32
- public void addValue(int value)
33
- {
34
- if (isFull()) {
35
- throw new IllegalStateException();
36
- }
37
-
38
- buffer[currentPosition] = (byte)value;
39
- buffer[currentPosition + 1] = (byte)(value >> 8);
40
- buffer[currentPosition + 2] = (byte)(value >> 16);
41
- buffer[currentPosition + 3] = (byte)(value >> 24);
42
-
43
- next();
44
- }
45
-
46
- public void addValue(String value)
47
- {
48
- if (isFull()) {
49
- throw new IllegalStateException();
50
- }
51
-
52
- ByteBuffer bytes = charset.encode(value);
53
- int length = bytes.remaining();
54
- // TODO:warning or error if truncated
55
- bytes.get(buffer, currentPosition, length);
56
- if (length < table.columns[currentColumn].columnSize) {
57
- buffer[currentPosition + length] = 0;
58
- }
59
-
60
- next();
61
- }
62
-
63
- public void addValue(BigDecimal value)
64
- {
65
- addValue(value.toPlainString());
66
- }
67
-
68
- private void next()
69
- {
70
- currentPosition += table.columns[currentColumn].columnSize;
71
- currentColumn++;
72
- if (currentColumn == table.columns.length) {
73
- currentColumn = 0;
74
- currentRow++;
75
- }
76
- }
77
-
78
- public byte[] getBuffer()
79
- {
80
- return buffer;
81
- }
82
-
83
- public int getCurrentColumn()
84
- {
85
- return currentColumn;
86
- }
87
-
88
- public int getRowCount()
89
- {
90
- return currentRow;
91
- }
92
-
93
- public boolean isFull()
94
- {
95
- return currentRow >= rowCount;
96
- }
97
-
98
- public void clear()
99
- {
100
- currentPosition = 0;
101
- currentRow = 0;
102
- currentColumn = 0;
103
- }
104
-
105
- }
1
+ package org.embulk.output.oracle.oci;
2
+
3
+ import java.math.BigDecimal;
4
+ import java.nio.ByteBuffer;
5
+ import java.nio.charset.Charset;
6
+
7
+
8
+ public class RowBuffer
9
+ {
10
+ private final TableDefinition table;
11
+ private final int rowCount;
12
+ private final byte[] buffer;
13
+ private int currentRow = 0;
14
+ private int currentColumn = 0;
15
+ private int currentPosition = 0;
16
+ private final Charset charset;
17
+
18
+ public RowBuffer(TableDefinition table, int rowCount, Charset charset)
19
+ {
20
+ this.table = table;
21
+ this.rowCount = rowCount;
22
+ this.charset = charset;
23
+
24
+ int rowSize = 0;
25
+ for (ColumnDefinition column : table.columns) {
26
+ rowSize += column.columnSize;
27
+ }
28
+
29
+ buffer = new byte[rowSize * rowCount];
30
+ }
31
+
32
+ public void addValue(int value)
33
+ {
34
+ if (isFull()) {
35
+ throw new IllegalStateException();
36
+ }
37
+
38
+ buffer[currentPosition] = (byte)value;
39
+ buffer[currentPosition + 1] = (byte)(value >> 8);
40
+ buffer[currentPosition + 2] = (byte)(value >> 16);
41
+ buffer[currentPosition + 3] = (byte)(value >> 24);
42
+
43
+ next();
44
+ }
45
+
46
+ public void addValue(String value)
47
+ {
48
+ if (isFull()) {
49
+ throw new IllegalStateException();
50
+ }
51
+
52
+ ByteBuffer bytes = charset.encode(value);
53
+ int length = bytes.remaining();
54
+ // TODO:warning or error if truncated
55
+ bytes.get(buffer, currentPosition, length);
56
+ if (length < table.columns[currentColumn].columnSize) {
57
+ buffer[currentPosition + length] = 0;
58
+ }
59
+
60
+ next();
61
+ }
62
+
63
+ public void addValue(BigDecimal value)
64
+ {
65
+ addValue(value.toPlainString());
66
+ }
67
+
68
+ private void next()
69
+ {
70
+ currentPosition += table.columns[currentColumn].columnSize;
71
+ currentColumn++;
72
+ if (currentColumn == table.columns.length) {
73
+ currentColumn = 0;
74
+ currentRow++;
75
+ }
76
+ }
77
+
78
+ public byte[] getBuffer()
79
+ {
80
+ return buffer;
81
+ }
82
+
83
+ public int getCurrentColumn()
84
+ {
85
+ return currentColumn;
86
+ }
87
+
88
+ public int getRowCount()
89
+ {
90
+ return currentRow;
91
+ }
92
+
93
+ public boolean isFull()
94
+ {
95
+ return currentRow >= rowCount;
96
+ }
97
+
98
+ public void clear()
99
+ {
100
+ currentPosition = 0;
101
+ currentRow = 0;
102
+ currentColumn = 0;
103
+ }
104
+
105
+ }
@@ -1,24 +1,24 @@
1
- package org.embulk.output.oracle.oci;
2
-
3
- import java.util.List;
4
-
5
- public class TableDefinition
6
- {
7
-
8
- public final String tableName;
9
- public final short charsetId;
10
- public final ColumnDefinition[] columns;
11
-
12
-
13
- public TableDefinition(String tableName, short charsetId, ColumnDefinition... columns)
14
- {
15
- this.tableName = tableName;
16
- this.charsetId = charsetId;
17
- this.columns = columns;
18
- }
19
-
20
- public TableDefinition(String tableName, short charsetId, List<ColumnDefinition> columns)
21
- {
22
- this(tableName, charsetId, columns.toArray(new ColumnDefinition[columns.size()]));
23
- }
24
- }
1
+ package org.embulk.output.oracle.oci;
2
+
3
+ import java.util.List;
4
+
5
+ public class TableDefinition
6
+ {
7
+
8
+ public final String tableName;
9
+ public final short charsetId;
10
+ public final ColumnDefinition[] columns;
11
+
12
+
13
+ public TableDefinition(String tableName, short charsetId, ColumnDefinition... columns)
14
+ {
15
+ this.tableName = tableName;
16
+ this.charsetId = charsetId;
17
+ this.columns = columns;
18
+ }
19
+
20
+ public TableDefinition(String tableName, short charsetId, List<ColumnDefinition> columns)
21
+ {
22
+ this(tableName, charsetId, columns.toArray(new ColumnDefinition[columns.size()]));
23
+ }
24
+ }