Sha256: 08d8a466271ceeb86b2f80fccd51166b32cfc217eb2fe488fded288dc38741dd

Contents?: true

Size: 1.96 KB

Versions: 3

Compression:

Stored size: 1.96 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) 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);
                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

3 entries across 3 versions & 1 rubygems

Version Path
embulk-output-oracle-0.6.3 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.6.2 src/main/java/org/embulk/output/oracle/oci/OCIManager.java
embulk-output-oracle-0.6.1 src/main/java/org/embulk/output/oracle/oci/OCIManager.java