<commit_before>package org.sql2o;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sql2o.converters.Convert;
import org.sql2o.converters.Converter;
import org.sql2o.converters.ConverterException;
import org.sql2o.data.Table;
import org.sql2o.data.TableFactory;
import org.sql2o.reflection.Pojo;
import org.sql2o.reflection.PojoMetadata;
import org.sql2o.tools.NamedParameterStatement;

import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.*;
import java.sql.Date;
import java.util.*;

/**
 * Represents a sql2o statement. With sql2o, all statements are instances of the Query class.
 */
public class Query {

    private final Logger logger = LoggerFactory.getLogger(Query.class);

    public Query(Connection connection, String queryText, String name, boolean returnGeneratedKeys) {
        this.connection = connection;
        this.name = name;
        this.returnGeneratedKeys = returnGeneratedKeys;

        try{
            statement = new NamedParameterStatement(connection.getJdbcConnection(), queryText, returnGeneratedKeys);
        }
        catch(Exception ex){
            throw new RuntimeException(ex);
        }

        this.setColumnMappings(connection.getSql2o().getDefaultColumnMappings());
        this.caseSensitive = connection.getSql2o().isDefaultCaseSensitive();
        this.methodsMap = new HashMap<String, Method>();
    }

    private Connection connection;

    private Map<String, String> caseSensitiveColumnMappings;
    private Map<String, String> columnMappings;
    private Map<String, Method> methodsMap;

    private NamedParameterStatement statement;

    private boolean caseSensitive;
    private boolean autoDeriveColumnNames;
    
    private final String name;
    private boolean returnGeneratedKeys;

    public Query addParameter(String name, Object value){
        try{
            statement.setObject(name, value);
        }
        catch(SQLException ex){
            throw new RuntimeException(ex);
        }
        return this;
    }

    public Query addParameter(String name, InputStream value){
        try{
            statement.setInputStream(name, value);
        }
        catch(SQLException ex){
            throw new RuntimeException(ex);
        }
        return this;
    }
    
    public Query addParameter(String name, int value){
        try{
            statement.setInt(name, value);
        }
        catch (SQLException ex){
            throw new Sql2oException(ex);
        }
        return this;
    }

    public Query addParameter(String name, Integer value){
        try{
            if (value == null){
                statement.setNull(name, Types.INTEGER);
            }else{
                statement.setInt(name, value);
            }
        }
        catch(SQLException ex){
            throw new RuntimeException(ex);
        }
        return this;
    }

    public Query addParameter(String name, long value){
        try{
            statement.setLong(name, value);
        }
        catch(SQLException ex){
            throw new RuntimeException(ex);
        }
        return this;
    }
    
    public Query addParameter(String name, Long value){
        try{
            if (value == null){
                statement.setNull(name, Types.INTEGER);
            } else {
                statement.setLong(name, value);
            }
        }
        catch (SQLException ex){
            throw new Sql2oException(ex);
        }
        return this;
    }

    public Query addParameter(String name, String value){
        try{
            if (value == null){
                statement.setNull(name, Types.VARCHAR);
            }else{
                statement.setString(name, value);
            }
        }
        catch(Exception ex){
            throw new RuntimeException(ex);
        }
        return this;
    }

    public Query addParameter(String name, Timestamp value){
        try{
            if (value == null){
                statement.setNull(name, Types.TIMESTAMP);
            } else {
                statement.setTimestamp(name, value);
            }
        }
        catch(Exception ex){
            throw new RuntimeException(ex);
        }
        return this;
    }

    public Query addParameter(String name, Date value){
        if (this.getConnection().getSql2o().quirksMode == QuirksMode.MSSqlServer){
            Timestamp timestamp = value == null ? null : new Timestamp(value.getTime());
            return addParameter(name, timestamp);
        }

        try{
            if (value == null) {
                statement.setNull(name, Types.DATE);
            } else {
                statement.setDate(name, value);
            }
        } catch (Exception ex) {
            throw new Sql2oException("Error setting parameter '" + name + "'", ex);
        }

        return this;
    }

    public Query addParameter(String name, java.util.Date value){
        Timestamp timestamp = value == null ? null : new Timestamp(value.getTime());
        return addParameter(name, timestamp);
    }

    public Query addParameter(String name, Time value){
        try {
            if (value == null){
                statement.setNull(name, Types.TIME);
            } else {
                statement.setTime(name,value);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return this;
    }

    public Query addParameter(String name, DateTime value){<commit_msg>ref #41, forgot to do the same for the addParameter(String, java.util.Date) overload<commit_after>package org.sql2o;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sql2o.converters.Convert;
import org.sql2o.converters.Converter;
import org.sql2o.converters.ConverterException;
import org.sql2o.data.Table;
import org.sql2o.data.TableFactory;
import org.sql2o.reflection.Pojo;
import org.sql2o.reflection.PojoMetadata;
import org.sql2o.tools.NamedParameterStatement;

import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.*;
import java.sql.Date;
import java.util.*;

/**
 * Represents a sql2o statement. With sql2o, all statements are instances of the Query class.
 */
public class Query {

    private final Logger logger = LoggerFactory.getLogger(Query.class);

    public Query(Connection connection, String queryText, String name, boolean returnGeneratedKeys) {
        this.connection = connection;
        this.name = name;
        this.returnGeneratedKeys = returnGeneratedKeys;

        try{
            statement = new NamedParameterStatement(connection.getJdbcConnection(), queryText, returnGeneratedKeys);
        }
        catch(Exception ex){
            throw new RuntimeException(ex);
        }

        this.setColumnMappings(connection.getSql2o().getDefaultColumnMappings());
        this.caseSensitive = connection.getSql2o().isDefaultCaseSensitive();
        this.methodsMap = new HashMap<String, Method>();
    }

    private Connection connection;

    private Map<String, String> caseSensitiveColumnMappings;
    private Map<String, String> columnMappings;
    private Map<String, Method> methodsMap;

    private NamedParameterStatement statement;

    private boolean caseSensitive;
    private boolean autoDeriveColumnNames;
    
    private final String name;
    private boolean returnGeneratedKeys;

    public Query addParameter(String name, Object value){
        try{
            statement.setObject(name, value);
        }
        catch(SQLException ex){
            throw new RuntimeException(ex);
        }
        return this;
    }

    public Query addParameter(String name, InputStream value){
        try{
            statement.setInputStream(name, value);
        }
        catch(SQLException ex){
            throw new RuntimeException(ex);
        }
        return this;
    }
    
    public Query addParameter(String name, int value){
        try{
            statement.setInt(name, value);
        }
        catch (SQLException ex){
            throw new Sql2oException(ex);
        }
        return this;
    }

    public Query addParameter(String name, Integer value){
        try{
            if (value == null){
                statement.setNull(name, Types.INTEGER);
            }else{
                statement.setInt(name, value);
            }
        }
        catch(SQLException ex){
            throw new RuntimeException(ex);
        }
        return this;
    }

    public Query addParameter(String name, long value){
        try{
            statement.setLong(name, value);
        }
        catch(SQLException ex){
            throw new RuntimeException(ex);
        }
        return this;
    }
    
    public Query addParameter(String name, Long value){
        try{
            if (value == null){
                statement.setNull(name, Types.INTEGER);
            } else {
                statement.setLong(name, value);
            }
        }
        catch (SQLException ex){
            throw new Sql2oException(ex);
        }
        return this;
    }

    public Query addParameter(String name, String value){
        try{
            if (value == null){
                statement.setNull(name, Types.VARCHAR);
            }else{
                statement.setString(name, value);
            }
        }
        catch(Exception ex){
            throw new RuntimeException(ex);
        }
        return this;
    }

    public Query addParameter(String name, Timestamp value){
        try{
            if (value == null){
                statement.setNull(name, Types.TIMESTAMP);
            } else {
                statement.setTimestamp(name, value);
            }
        }
        catch(Exception ex){
            throw new RuntimeException(ex);
        }
        return this;
    }

    public Query addParameter(String name, Date value){
        if (this.getConnection().getSql2o().quirksMode == QuirksMode.MSSqlServer){
            Timestamp timestamp = value == null ? null : new Timestamp(value.getTime());
            return addParameter(name, timestamp);
        }

        if (value != null && this.connection.getSql2o().quirksMode == QuirksMode.DB2){
            // With the DB2 driver you can get an error if trying to put a date value into a timestamp column,
            // but of some reason it works if using setObject().
            return addParameter(name, (Object)value);
        }

        try{
            if (value == null) {
                statement.setNull(name, Types.DATE);
            } else {
                statement.setDate(name, value);
            }
        } catch (Exception ex) {
            throw new Sql2oException("Error setting parameter '" + name + "'", ex);
        }

        return this;
    }

    public Query addParameter(String name, java.util.Date value){
        Date sqlDate = value == null ? null : new Date(value.getTime());
        return addParameter(name, sqlDate);

    }

    public Query addParameter(String name, Time value){
        try {
            if (value == null){
                statement.setNull(name, Types.TIME);
            } else {
                statement.setTime(name,value);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return this;
    }

    public Query addParameter(String name, DateTime value){
{'fraction_non_alphanumeric': 0.09218071242397916, 'fraction_numerical': 0.003735881841876629, 'mean_word_length': 2.035601265822785, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7538572', 'n_tokens_mistral': 3025, 'n_tokens_neox': 2956, 'n_words': 767}