All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sqlg3.runtime.JdbcInterface Maven / Gradle / Ivy

Go to download

SQLG is a preprocessor and a library that uses code generation to simplify writing JDBC code

There is a newer version: 3.1
Show newest version
package sqlg3.runtime;

import sqlg3.core.IDBCommon;
import sqlg3.core.ISimpleTransaction;

import java.sql.Connection;

/**
 * This class can be used to call SQLG code from JDBC code. If you have {@link Connection} instance then
 * you can retrieve business interface ITest in the following way:
 * 
 * Connection conn = ...;
 * ISimpleTransaction trans = new JdbcInterface(global, conn, false);
 * ITest iface = trans.getInterface(ITest.class);
 * 
*/ public final class JdbcInterface implements ISimpleTransaction { private final TransactionContext transaction; private final boolean commitCalls; public JdbcInterface(GlobalContext global, Connection connection, boolean commitCalls, Object userObject, PreCallCheck beforeCall) { SessionContext session = new SessionContext(new SingleConnectionManager(connection), userObject, beforeCall); this.transaction = new TransactionContext(global, session); this.commitCalls = commitCalls; } public T getInterface(Class iface) { return transaction.getInterface(iface, commitCalls, true); } public static Builder builder() { return new Builder(); } public static final class Builder { private boolean commitCalls = false; private Object userObject = null; private PreCallCheck beforeCall = null; public Builder setCommitCalls(boolean commitCalls) { this.commitCalls = commitCalls; return this; } public Builder setUserObject(Object userObject) { this.userObject = userObject; return this; } public Builder setBeforeCall(PreCallCheck beforeCall) { this.beforeCall = beforeCall; return this; } public JdbcInterface build(GlobalContext global, Connection connection) { return new JdbcInterface(global, connection, commitCalls, userObject, beforeCall); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy