embulk-output-oracle 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +110 -110
  3. data/build.gradle +6 -6
  4. data/classpath/{embulk-output-jdbc-0.2.3.jar → embulk-output-jdbc-0.2.4.jar} +0 -0
  5. data/classpath/{embulk-output-oracle-0.2.3.jar → embulk-output-oracle-0.2.4.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/oracle/DirectBatchInsert.java +289 -289
  17. data/src/main/java/org/embulk/output/oracle/InsertMethod.java +8 -8
  18. data/src/main/java/org/embulk/output/oracle/OracleCharset.java +19 -19
  19. data/src/main/java/org/embulk/output/oracle/OracleOutputConnection.java +134 -134
  20. data/src/main/java/org/embulk/output/oracle/OracleOutputConnector.java +49 -49
  21. data/src/main/java/org/embulk/output/oracle/TimestampFormat.java +37 -37
  22. data/src/main/java/org/embulk/output/oracle/oci/ColumnDefinition.java +26 -26
  23. data/src/main/java/org/embulk/output/oracle/oci/OCI.java +139 -139
  24. data/src/main/java/org/embulk/output/oracle/oci/OCIManager.java +64 -64
  25. data/src/main/java/org/embulk/output/oracle/oci/OCIWrapper.java +96 -96
  26. data/src/main/java/org/embulk/output/oracle/oci/RowBuffer.java +99 -99
  27. data/src/main/java/org/embulk/output/oracle/oci/TableDefinition.java +24 -24
  28. data/src/main/java/org/embulk/output/oracle/setter/OracleColumnSetterFactory.java +31 -31
  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 +120 -120
  38. data/src/test/java/org/embulk/output/oracle/EmptyConfigSource.java +100 -100
  39. data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTest.java +161 -161
  40. data/src/test/java/org/embulk/output/oracle/OracleOutputPluginTestImpl.java +413 -413
  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.yml +26 -26
  44. data/src/test/resources/yml/test-insert-oci-split.yml +26 -26
  45. data/src/test/resources/yml/test-insert-oci.yml +26 -26
  46. data/src/test/resources/yml/test-insert.yml +25 -25
  47. data/src/test/resources/yml/test-replace-long-name.yml +25 -25
  48. data/src/test/resources/yml/test-replace.yml +25 -25
  49. data/src/test/resources/yml/test-url.yml +24 -24
  50. metadata +4 -4
@@ -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,99 +1,99 @@
1
- package org.embulk.output.oracle.oci;
2
-
3
- import java.nio.ByteBuffer;
4
- import java.nio.charset.Charset;
5
-
6
- public class RowBuffer
7
- {
8
- private final TableDefinition table;
9
- private final int rowCount;
10
- private final byte[] buffer;
11
- private int currentRow = 0;
12
- private int currentColumn = 0;
13
- private int currentPosition = 0;
14
- private final Charset charset;
15
-
16
-
17
- public RowBuffer(TableDefinition table, int rowCount, Charset charset)
18
- {
19
- this.table = table;
20
- this.rowCount = rowCount;
21
- this.charset = charset;
22
-
23
- int rowSize = 0;
24
- for (ColumnDefinition column : table.columns) {
25
- rowSize += column.columnSize;
26
- }
27
-
28
- buffer = new byte[rowSize * rowCount];
29
- }
30
-
31
- public void addValue(int value)
32
- {
33
- if (isFull()) {
34
- throw new IllegalStateException();
35
- }
36
-
37
- buffer[currentPosition] = (byte)value;
38
- buffer[currentPosition + 1] = (byte)(value >> 8);
39
- buffer[currentPosition + 2] = (byte)(value >> 16);
40
- buffer[currentPosition + 3] = (byte)(value >> 24);
41
-
42
- next();
43
- }
44
-
45
- public void addValue(String value)
46
- {
47
- if (isFull()) {
48
- throw new IllegalStateException();
49
- }
50
-
51
- ByteBuffer bytes = charset.encode(value);
52
- int length = bytes.remaining();
53
- // TODO:warning or error if truncated
54
- bytes.get(buffer, currentPosition, length);
55
- if (length < table.columns[currentColumn].columnSize) {
56
- buffer[currentPosition + length] = 0;
57
- }
58
-
59
- next();
60
- }
61
-
62
- private void next()
63
- {
64
- currentPosition += table.columns[currentColumn].columnSize;
65
- currentColumn++;
66
- if (currentColumn == table.columns.length) {
67
- currentColumn = 0;
68
- currentRow++;
69
- }
70
- }
71
-
72
- public byte[] getBuffer()
73
- {
74
- return buffer;
75
- }
76
-
77
- public int getCurrentColumn()
78
- {
79
- return currentColumn;
80
- }
81
-
82
- public int getRowCount()
83
- {
84
- return currentRow;
85
- }
86
-
87
- public boolean isFull()
88
- {
89
- return currentRow >= rowCount;
90
- }
91
-
92
- public void clear()
93
- {
94
- currentPosition = 0;
95
- currentRow = 0;
96
- currentColumn = 0;
97
- }
98
-
99
- }
1
+ package org.embulk.output.oracle.oci;
2
+
3
+ import java.nio.ByteBuffer;
4
+ import java.nio.charset.Charset;
5
+
6
+ public class RowBuffer
7
+ {
8
+ private final TableDefinition table;
9
+ private final int rowCount;
10
+ private final byte[] buffer;
11
+ private int currentRow = 0;
12
+ private int currentColumn = 0;
13
+ private int currentPosition = 0;
14
+ private final Charset charset;
15
+
16
+
17
+ public RowBuffer(TableDefinition table, int rowCount, Charset charset)
18
+ {
19
+ this.table = table;
20
+ this.rowCount = rowCount;
21
+ this.charset = charset;
22
+
23
+ int rowSize = 0;
24
+ for (ColumnDefinition column : table.columns) {
25
+ rowSize += column.columnSize;
26
+ }
27
+
28
+ buffer = new byte[rowSize * rowCount];
29
+ }
30
+
31
+ public void addValue(int value)
32
+ {
33
+ if (isFull()) {
34
+ throw new IllegalStateException();
35
+ }
36
+
37
+ buffer[currentPosition] = (byte)value;
38
+ buffer[currentPosition + 1] = (byte)(value >> 8);
39
+ buffer[currentPosition + 2] = (byte)(value >> 16);
40
+ buffer[currentPosition + 3] = (byte)(value >> 24);
41
+
42
+ next();
43
+ }
44
+
45
+ public void addValue(String value)
46
+ {
47
+ if (isFull()) {
48
+ throw new IllegalStateException();
49
+ }
50
+
51
+ ByteBuffer bytes = charset.encode(value);
52
+ int length = bytes.remaining();
53
+ // TODO:warning or error if truncated
54
+ bytes.get(buffer, currentPosition, length);
55
+ if (length < table.columns[currentColumn].columnSize) {
56
+ buffer[currentPosition + length] = 0;
57
+ }
58
+
59
+ next();
60
+ }
61
+
62
+ private void next()
63
+ {
64
+ currentPosition += table.columns[currentColumn].columnSize;
65
+ currentColumn++;
66
+ if (currentColumn == table.columns.length) {
67
+ currentColumn = 0;
68
+ currentRow++;
69
+ }
70
+ }
71
+
72
+ public byte[] getBuffer()
73
+ {
74
+ return buffer;
75
+ }
76
+
77
+ public int getCurrentColumn()
78
+ {
79
+ return currentColumn;
80
+ }
81
+
82
+ public int getRowCount()
83
+ {
84
+ return currentRow;
85
+ }
86
+
87
+ public boolean isFull()
88
+ {
89
+ return currentRow >= rowCount;
90
+ }
91
+
92
+ public void clear()
93
+ {
94
+ currentPosition = 0;
95
+ currentRow = 0;
96
+ currentColumn = 0;
97
+ }
98
+
99
+ }
@@ -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
+ }
@@ -1,31 +1,31 @@
1
- package org.embulk.output.oracle.setter;
2
-
3
- import java.sql.Types;
4
-
5
- import org.embulk.output.jdbc.BatchInsert;
6
- import org.embulk.output.jdbc.JdbcColumn;
7
- import org.embulk.output.jdbc.setter.ColumnSetter;
8
- import org.embulk.output.jdbc.setter.ColumnSetterFactory;
9
- import org.embulk.output.jdbc.setter.StringColumnSetter;
10
- import org.embulk.spi.PageReader;
11
- import org.embulk.spi.time.TimestampFormatter;
12
-
13
- public class OracleColumnSetterFactory extends ColumnSetterFactory
14
- {
15
- public OracleColumnSetterFactory(BatchInsert batch, PageReader pageReader,
16
- TimestampFormatter timestampFormatter)
17
- {
18
- super(batch, pageReader, timestampFormatter);
19
- }
20
-
21
- @Override
22
- public ColumnSetter newColumnSetter(JdbcColumn column)
23
- {
24
- switch (column.getSqlType()) {
25
- case Types.DECIMAL:
26
- return new StringColumnSetter(batch, pageReader, column, timestampFormatter);
27
- default:
28
- return super.newColumnSetter(column);
29
- }
30
- }
31
- }
1
+ package org.embulk.output.oracle.setter;
2
+
3
+ import java.sql.Types;
4
+
5
+ import org.embulk.output.jdbc.BatchInsert;
6
+ import org.embulk.output.jdbc.JdbcColumn;
7
+ import org.embulk.output.jdbc.setter.ColumnSetter;
8
+ import org.embulk.output.jdbc.setter.ColumnSetterFactory;
9
+ import org.embulk.output.jdbc.setter.StringColumnSetter;
10
+ import org.embulk.spi.PageReader;
11
+ import org.embulk.spi.time.TimestampFormatter;
12
+
13
+ public class OracleColumnSetterFactory extends ColumnSetterFactory
14
+ {
15
+ public OracleColumnSetterFactory(BatchInsert batch, PageReader pageReader,
16
+ TimestampFormatter timestampFormatter)
17
+ {
18
+ super(batch, pageReader, timestampFormatter);
19
+ }
20
+
21
+ @Override
22
+ public ColumnSetter newColumnSetter(JdbcColumn column)
23
+ {
24
+ switch (column.getSqlType()) {
25
+ case Types.DECIMAL:
26
+ return new StringColumnSetter(batch, pageReader, column, timestampFormatter);
27
+ default:
28
+ return super.newColumnSetter(column);
29
+ }
30
+ }
31
+ }