<commit_before>class Upsert
  class Connection
    # @private
    module Jdbc
      # /Users/seamusabshere/.rvm/gems/jruby-head/gems/activerecord-jdbc-adapter-1.2.2.1/src/java/arjdbc/jdbc/RubyJdbcConnection.java
      GETTER = {
        java.sql.Types::VARCHAR     => 'getString',
        java.sql.Types::OTHER       => 'getString', # ?! i guess unicode text?
        java.sql.Types::BINARY      => 'getBlob',
        java.sql.Types::LONGVARCHAR => 'getString',
      }
      java.sql.Types.constants.each do |type_name|
        i = java.sql.Types.const_get type_name
        unless GETTER.has_key?(i)
          GETTER[i] = 'get' + type_name[0].upcase + type_name[1..-1].downcase
        end
      end
      SETTER = Hash.new do |hash, k|
        hash[k] = 'set' + k
      end.merge(
        'TrueClass'  => 'setBoolean',
        'FalseClass' => 'setBoolean',
        'Fixnum'     => 'setInt',
      )

      def binary(v)
        v.value.to_java_bytes.java_object
      end

      def execute(sql, params = nil)
        has_result = if params
          Upsert.logger.debug { %{[upsert] #{sql} with #{params.inspect}} }
          setters = self.class.const_get(:SETTER)
          statement = metal.prepareStatement sql
          params.each_with_index do |v, i|
            case v
            when Upsert::Binary
              statement.setBytes i+1, binary(v)
            when BigDecimal
              statement.setBigDecimal i+1, java.math.BigDecimal.new(v.to_s)
            when NilClass
              # http://stackoverflow.com/questions/4243513/why-does-preparedstatement-setnull-requires-sqltype
              statement.setObject i+1, nil
            else
              setter = setters[v.class.name]
              statement.send setter, i+1, v
            end
          end
          statement.execute
        else
          Upsert.logger.debug { %{[upsert] #{sql}} }
          statement = metal.createStatement
          statement.execute sql
        end
        if not has_result
          statement.close<commit_msg>Convert `Symbol` to `String` by default. If a parameter is a `Symbol`, it will raise `undefined method setSymbol`<commit_after>class Upsert
  class Connection
    # @private
    module Jdbc
      # /Users/seamusabshere/.rvm/gems/jruby-head/gems/activerecord-jdbc-adapter-1.2.2.1/src/java/arjdbc/jdbc/RubyJdbcConnection.java
      GETTER = {
        java.sql.Types::VARCHAR     => 'getString',
        java.sql.Types::OTHER       => 'getString', # ?! i guess unicode text?
        java.sql.Types::BINARY      => 'getBlob',
        java.sql.Types::LONGVARCHAR => 'getString',
      }
      java.sql.Types.constants.each do |type_name|
        i = java.sql.Types.const_get type_name
        unless GETTER.has_key?(i)
          GETTER[i] = 'get' + type_name[0].upcase + type_name[1..-1].downcase
        end
      end
      SETTER = Hash.new do |hash, k|
        hash[k] = 'set' + k
      end.merge(
        'TrueClass'  => 'setBoolean',
        'FalseClass' => 'setBoolean',
        'Fixnum'     => 'setInt',
      )

      def binary(v)
        v.value.to_java_bytes.java_object
      end

      def execute(sql, params = nil)
        has_result = if params
          Upsert.logger.debug { %{[upsert] #{sql} with #{params.inspect}} }
          setters = self.class.const_get(:SETTER)
          statement = metal.prepareStatement sql
          params.each_with_index do |v, i|
            case v
            when Upsert::Binary
              statement.setBytes i+1, binary(v)
            when BigDecimal
              statement.setBigDecimal i+1, java.math.BigDecimal.new(v.to_s)
            when NilClass
              # http://stackoverflow.com/questions/4243513/why-does-preparedstatement-setnull-requires-sqltype
              statement.setObject i+1, nil
            else
              v = v.to_s if v.is_a? Symbol
              setter = setters[v.class.name]
              statement.send setter, i+1, v
            end
          end
          statement.execute
        else
          Upsert.logger.debug { %{[upsert] #{sql}} }
          statement = metal.createStatement
          statement.execute sql
        end
        if not has_result
          statement.close
{'fraction_non_alphanumeric': 0.1134684147794994, 'fraction_numerical': 0.008581644815256258, 'mean_word_length': 1.8293998651382333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7032501', 'n_tokens_mistral': 1317, 'n_tokens_neox': 1276, 'n_words': 253}