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

com.github.alittlehuang.data.jdbc.operations.JdbcOperationsInConnection Maven / Gradle / Ivy

The newest version!
package com.github.alittlehuang.data.jdbc.operations;

import lombok.Getter;
import lombok.Setter;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Operating the database in Connection requires manual management of transactions.
 */
public class JdbcOperationsInConnection extends AbstractJdbcOperations {

    @Getter
    @Setter
    private Connection connection;

    public JdbcOperationsInConnection(Connection connection) {
        this.connection = connection;
    }

    @Override
    protected  R execute(ConnectionCallback action, boolean commit) {
        try {
            R result = action.doInConnection(getConnection());
            if ( commit && !connection.getAutoCommit() ) {
                connection.commit();
            }
            return result;
        } catch ( SQLException ex ) {
            throw new RuntimeException(ex);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy