Sha256: 8a7e2afa91a0eb4376a89e47e6bd31cff89e0ff3f01fdba2c73b9b796a468112

Contents?: true

Size: 2 KB

Versions: 23

Compression:

Stored size: 2 KB

Contents

package org.embulk.output.oracle.oci;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.embulk.spi.Exec;
import org.slf4j.Logger;

public class OCIManager
{
    private static class OCIWrapperAndCounter {
        public OCIWrapper oci;
        public int counter;
    }


    private final Logger logger = Exec.getLogger(getClass());

    private Map<Object, OCIWrapperAndCounter> ociAndCounters = new HashMap<Object, OCIWrapperAndCounter>();


    public OCIWrapper open(Object key, String dbName, String userName, String password, TableDefinition tableDefinition, int bufferSize)
            throws SQLException
    {
        synchronized(ociAndCounters) {
            OCIWrapperAndCounter ociAndCounter;
            if (ociAndCounters.containsKey(key)) {
                ociAndCounter = ociAndCounters.get(key);
            } else {
                logger.info(String.format("OCI : open for %s.", key));
                ociAndCounter = new OCIWrapperAndCounter();
                ociAndCounter.oci = new OCIWrapper();
                ociAndCounter.oci.open(dbName, userName, password);
                ociAndCounter.oci.prepareLoad(tableDefinition, bufferSize);
                ociAndCounters.put(key, ociAndCounter);
            }
            ociAndCounter.counter++;
            return ociAndCounter.oci;
        }
    }

    public OCIWrapper get(Object key)
    {
        synchronized(ociAndCounters) {
            return ociAndCounters.get(key).oci;
        }
    }

    public void close(Object key) throws SQLException
    {
        synchronized(ociAndCounters) {
            OCIWrapperAndCounter ociAndCounter = ociAndCounters.get(key);
            if (ociAndCounter != null) {
                ociAndCounter.counter--;
                if (ociAndCounter.counter == 0) {
                    logger.info(String.format("OCI : close for %s.", key));
                    ociAndCounters.remove(key);
                    ociAndCounter.oci.close();
                }
            }
        }
    }

}

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
embulk-output-oracle-0.8.7 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.8.6 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.8.5 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.8.4 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.8.3 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.8.2 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.8.1 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.8.0 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.13 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.12 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.11 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.10 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.9 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.8 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.7 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.6 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.5 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.3 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.2 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.7.1 src/main/java/org/embulk/output/oracle/oci/OCIManager.java