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

org.usf.inspect.jdbc.ConnectionWrapper Maven / Gradle / Ivy

package org.usf.inspect.jdbc;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;

import lombok.RequiredArgsConstructor;
import lombok.experimental.Delegate;

/**
 * 
 * @author u$f
 *
 */
@RequiredArgsConstructor
public final class ConnectionWrapper implements Connection {
	
	@Delegate
	private final Connection cn;
	private final DatabaseStageTracker tracer;

	@Override
	public Statement createStatement() throws SQLException {
		return tracer.statement(cn::createStatement);
	}
	
	@Override
	public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
		return tracer.statement(()-> cn.createStatement(resultSetType, resultSetConcurrency));
	}
	
	@Override
	public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
		return tracer.statement(()-> cn.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability));
	}
	
	@Override
	public PreparedStatement prepareStatement(String sql) throws SQLException {
		return tracer.preparedStatement(sql, ()-> cn.prepareStatement(sql));
	}
	
	@Override
	public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
		return tracer.preparedStatement(sql, ()-> cn.prepareStatement(sql, resultSetType, resultSetConcurrency));
	}
	
	@Override
	public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
		return tracer.preparedStatement(sql, ()-> cn.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability));
	}
	
	@Override
	public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
		return tracer.preparedStatement(sql, ()-> cn.prepareStatement(sql, autoGeneratedKeys));
	}
	
	@Override
	public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
		return tracer.preparedStatement(sql, ()-> cn.prepareStatement(sql, columnIndexes));
	}
	
	@Override
	public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
		return tracer.preparedStatement(sql, ()-> cn.prepareStatement(sql, columnNames));
	}
	
	@Override
	public Savepoint setSavepoint() throws SQLException {
		return tracer.savePoint(cn::setSavepoint);
	}
	
	@Override
	public Savepoint setSavepoint(String name) throws SQLException {
		return tracer.savePoint(()-> cn.setSavepoint(name));
	}
	
	@Override
	public void commit() throws SQLException {
		tracer.commit(cn::commit);
	}
	
	@Override
	public void rollback() throws SQLException {
		tracer.rollback(cn::rollback);
	}
	
	@Override
	public void rollback(Savepoint savepoint) throws SQLException {
		tracer.rollback(()-> cn.rollback(savepoint));
	}
	
	@Override
	public DatabaseMetaData getMetaData() throws SQLException {
		return tracer.connectionMetadata(cn::getMetaData);
	}
	
	@Override
	public void close() throws SQLException {
		tracer.disconnection(cn::close);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy