src/main/java/org/embulk/output/oracle/oci/OCIWrapper.java in embulk-output-oracle-0.6.0 vs src/main/java/org/embulk/output/oracle/oci/OCIWrapper.java in embulk-output-oracle-0.6.1

- old
+ new

@@ -22,11 +22,10 @@ private final Logger logger = Exec.getLogger(getClass()); private final Charset systemCharset; private Pointer envHandle; private Pointer errHandle; - private Pointer svcHandlePointer; private Pointer svcHandle; private Pointer dpHandle; private Pointer dpcaHandle; private Pointer dpstrHandle; @@ -93,11 +92,11 @@ 0, null)); errHandle = errHandlePointer.getPointer(0); // service context - svcHandlePointer = createPointerPointer(); + Pointer svcHandlePointer = createPointerPointer(); check("OCIHandleAlloc(OCI_HTYPE_SVCCTX)", oci.OCIHandleAlloc( envHandle, svcHandlePointer, OCI.OCI_HTYPE_SVCCTX, 0, @@ -140,27 +139,36 @@ (int)schemaName.size() , OCI.OCI_ATTR_SCHEMA_NAME, errHandle)); } - // load table name - Pointer tableName = createPointer(tableDefinition.getTableName()); + Pointer cols = createPointer((short)tableDefinition.getColumnCount()); + check("OCIAttrSet(OCI_ATTR_NUM_COLS)", oci.OCIAttrSet( + dpHandle, + OCI.OCI_HTYPE_DIRPATH_CTX, + cols, + (int)cols.size(), + OCI.OCI_ATTR_NUM_COLS, + errHandle)); + + // load table name (case sensitive) + Pointer tableName = createPointer("\"" + tableDefinition.getTableName() + "\""); check("OCIAttrSet(OCI_ATTR_NAME)", oci.OCIAttrSet( dpHandle, OCI.OCI_HTYPE_DIRPATH_CTX, tableName, (int)tableName.size() , OCI.OCI_ATTR_NAME, errHandle)); - Pointer cols = createPointer((short)tableDefinition.getColumnCount()); - check("OCIAttrSet(OCI_ATTR_NUM_COLS)", oci.OCIAttrSet( + Pointer noIndexErrors = createPointer((byte)1); + check("OCIAttrSet(OCI_ATTR_DIRPATH_NO_INDEX_ERRORS)", oci.OCIAttrSet( dpHandle, OCI.OCI_HTYPE_DIRPATH_CTX, - cols, - (int)cols.size(), - OCI.OCI_ATTR_NUM_COLS, + noIndexErrors, + (int)noIndexErrors.size(), + OCI.OCI_ATTR_DIRPATH_NO_INDEX_ERRORS, errHandle)); Pointer columnsPointer = createPointerPointer(); check("OCIAttrGet(OCI_ATTR_LIST_COLUMNS)", oci.OCIAttrGet( dpHandle, @@ -350,25 +358,29 @@ public void commit() throws SQLException { committedOrRollbacked = true; logger.info("OCI : start to commit."); - check("OCIDirPathFinish", oci.OCIDirPathFinish(dpHandle, errHandle)); - - check("OCILogoff", oci.OCILogoff(svcHandle, errHandle)); - svcHandle = null; + try { + check("OCIDirPathFinish", oci.OCIDirPathFinish(dpHandle, errHandle)); + } finally { + check("OCILogoff", oci.OCILogoff(svcHandle, errHandle)); + svcHandle = null; + } } public void rollback() throws SQLException { committedOrRollbacked = true; logger.info("OCI : start to rollback."); - check("OCIDirPathAbort", oci.OCIDirPathAbort(dpHandle, errHandle)); - - check("OCILogoff", oci.OCILogoff(svcHandle, errHandle)); - svcHandle = null; + try { + check("OCIDirPathAbort", oci.OCIDirPathAbort(dpHandle, errHandle)); + } finally { + check("OCILogoff", oci.OCILogoff(svcHandle, errHandle)); + svcHandle = null; + } } public void close() throws SQLException { if (dpHandle != null) { @@ -409,9 +421,16 @@ private Pointer createPointer(String s) { // not database charset, but system charset of client return Pointer.wrap(Runtime.getSystemRuntime(), ByteBuffer.wrap(s.getBytes(systemCharset))); + } + + private Pointer createPointer(byte n) + { + Pointer pointer = new ArrayMemoryIO(Runtime.getSystemRuntime(), 1); + pointer.putByte(0, n); + return pointer; } private Pointer createPointer(short n) { Pointer pointer = new ArrayMemoryIO(Runtime.getSystemRuntime(), 2);