// Path: rxjava2-jdbc/src/main/java/org/davidmoten/rx/jdbc/exceptions/CannotForkTransactedConnection.java
// public final class CannotForkTransactedConnection extends SQLRuntimeException {
// 
//     private static final long serialVersionUID = -5632849589133364479L;
// 
//     public CannotForkTransactedConnection(String message) {
//         super(message);
//     }
// 
// }


import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import org.davidmoten.rx.jdbc.exceptions.CannotForkTransactedConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package org.davidmoten.rx.jdbc;



final class TransactedConnection implements Connection {

    private static final Logger log = LoggerFactory.getLogger(TransactedConnection.class);

    private final Connection con;
    private final AtomicInteger counter;

    TransactedConnection(Connection con, AtomicInteger counter) {
        log.debug("constructing TransactedConnection from {}, {}", con, counter);
        this.con = con;
        this.counter = counter;
    }

    public TransactedConnection(Connection con) {
        this(con, new AtomicInteger(1));
    }

    public int counter() {
        return counter.get();
    }

    @Override
    public void abort(Executor executor) throws SQLException {
        con.abort(executor);
    }

    @Override
    public void clearWarnings() throws SQLException {
        con.clearWarnings();
    }

    public TransactedConnection fork() {
        log.debug("forking connection");
        if (counter.getAndIncrement() > 0) {
            return new TransactedConnection(con, counter);
        } else {

// Path: rxjava2-jdbc/src/main/java/org/davidmoten/rx/jdbc/exceptions/CannotForkTransactedConnection.java
// public final class CannotForkTransactedConnection extends SQLRuntimeException {
// 
//     private static final long serialVersionUID = -5632849589133364479L;
// 
//     public CannotForkTransactedConnection(String message) {
//         super(message);
//     }
// 
// }


// Path: rxjava2-jdbc/src/main/java/org/davidmoten/rx/jdbc/TransactedConnection.java
import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.NClob;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
import org.davidmoten.rx.jdbc.exceptions.CannotForkTransactedConnection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package org.davidmoten.rx.jdbc;



final class TransactedConnection implements Connection {

    private static final Logger log = LoggerFactory.getLogger(TransactedConnection.class);

    private final Connection con;
    private final AtomicInteger counter;

    TransactedConnection(Connection con, AtomicInteger counter) {
        log.debug("constructing TransactedConnection from {}, {}", con, counter);
        this.con = con;
        this.counter = counter;
    }

    public TransactedConnection(Connection con) {
        this(con, new AtomicInteger(1));
    }

    public int counter() {
        return counter.get();
    }

    @Override
    public void abort(Executor executor) throws SQLException {
        con.abort(executor);
    }

    @Override
    public void clearWarnings() throws SQLException {
        con.clearWarnings();
    }

    public TransactedConnection fork() {
        log.debug("forking connection");
        if (counter.getAndIncrement() > 0) {
            return new TransactedConnection(con, counter);
        } else {

            throw new CannotForkTransactedConnection(
