Sha256: ee58c4b72de146c7a66e9ea56d9b366a0a401dd38c00b0e4931ceb7c3d79c8ad

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

package org.embulk.input.mysql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.ResultSet;
import org.embulk.input.jdbc.JdbcInputConnection;

public class MySQLInputConnection
        extends JdbcInputConnection
{
    public MySQLInputConnection(Connection connection)
            throws SQLException
    {
        super(connection, null);
    }

    @Override
    protected BatchSelect newBatchSelect(String select, int fetchRows, int queryTimeout) throws SQLException
    {
        logger.info("SQL: " + select);
        PreparedStatement stmt = connection.prepareStatement(select, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);  // TYPE_FORWARD_ONLY and CONCUR_READ_ONLY are default
        if (fetchRows == 1) {
            // See MySQLInputPlugin.newConnection doesn't set useCursorFetch=true when fetchRows=1
            // MySQL Connector/J keeps the connection opened and process rows one by one with Integer.MIN_VALUE.
            stmt.setFetchSize(Integer.MIN_VALUE);
        } else if (fetchRows <= 0) {
            // uses the default behavior. MySQL Connector/J fetches the all rows in memory.
        } else {
            // useCursorFetch=true is enabled. MySQL creates temporary table and uses multiple select statements to fetch rows.
            stmt.setFetchSize(fetchRows);
        }
        // Because socketTimeout is set in Connection, don't need to set quertyTimeout.
        return new SingleSelect(stmt);
    }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
embulk-input-mysql-0.7.2 src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
embulk-input-mysql-0.7.1 src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
embulk-input-mysql-0.7.0 src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
embulk-input-mysql-0.6.4 src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
embulk-input-mysql-0.6.3 src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
embulk-input-mysql-0.6.2 src/main/java/org/embulk/input/mysql/MySQLInputConnection.java
embulk-input-mysql-0.6.1 src/main/java/org/embulk/input/mysql/MySQLInputConnection.java