<commit_before>require 'active_record/connection_adapters/abstract_adapter'
require 'java'
require 'active_record/connection_adapters/jdbc_adapter_spec'
require 'jdbc_adapter/jdbc_adapter_internal'
require 'bigdecimal'

module ActiveRecord
  module ConnectionAdapters # :nodoc:
    module SchemaStatements
      # The original implementation of this had a bug, which modifies native_database_types.
      # This version allows us to cache that value.
      def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
        native = native_database_types[type]
        column_type_sql = native.is_a?(Hash) ? native[:name] : native
        if type == :decimal # ignore limit, use precison and scale
          precision ||= native[:precision]
          scale ||= native[:scale]
          if precision
            if scale
              column_type_sql += "(#{precision},#{scale})"
            else
              column_type_sql += "(#{precision})"
            end
          else
            raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale
          end
          column_type_sql
        else
          limit ||= native[:limit]
          column_type_sql += "(#{limit})" if limit
          column_type_sql
        end
      end
    end
  end
end

module JdbcSpec
  module ActiveRecordExtensions
    def jdbc_connection(config)
      connection = ::ActiveRecord::ConnectionAdapters::JdbcConnection.new(config)
      ::ActiveRecord::ConnectionAdapters::JdbcAdapter.new(connection, logger, config)
    end
    alias jndi_connection jdbc_connection

    def embedded_driver(config)
      config[:username] ||= "sa"
      config[:password] ||= ""
      jdbc_connection(config)
    end
  end
end

module ActiveRecord
  class Base
    extend JdbcSpec::ActiveRecordExtensions

    alias :attributes_with_quotes_pre_oracle :attributes_with_quotes
    def attributes_with_quotes(include_primary_key = true) #:nodoc:
      aq = attributes_with_quotes_pre_oracle(include_primary_key)
      if connection.class == ConnectionAdapters::JdbcAdapter && (connection.is_a?(JdbcSpec::Oracle) || connection.is_a?(JdbcSpec::Mimer))
        aq[self.class.primary_key] = "?" if include_primary_key && aq[self.class.primary_key].nil?
      end
      aq
    end
  end

  module ConnectionAdapters
    module Java
      Class = java.lang.Class
      URL = java.net.URL
      URLClassLoader = java.net.URLClassLoader
    end

    module Jdbc
      Mutex = java.lang.Object.new
      DriverManager = java.sql.DriverManager
      Statement = java.sql.Statement
      Types = java.sql.Types

      # some symbolic constants for the benefit of the JDBC-based
      # JdbcConnection#indexes method
      module IndexMetaData
        INDEX_NAME  = 6
        NON_UNIQUE  = 4
        TABLE_NAME  = 3
        COLUMN_NAME = 9
      end<commit_msg>Fix for JRUBY-1627<commit_after>require 'active_record/connection_adapters/abstract_adapter'
require 'java'
require 'active_record/connection_adapters/jdbc_adapter_spec'
require 'jdbc_adapter/jdbc_adapter_internal'
require 'bigdecimal'

module ActiveRecord
  module ConnectionAdapters # :nodoc:
    module SchemaStatements
      # The original implementation of this had a bug, which modifies native_database_types.
      # This version allows us to cache that value.
      def type_to_sql(type, limit = nil, precision = nil, scale = nil) #:nodoc:
        native = native_database_types[type]
        column_type_sql = native.is_a?(Hash) ? native[:name] : native
        if type == :decimal # ignore limit, use precison and scale
          precision ||= native[:precision]
          scale ||= native[:scale]
          if precision
            if scale
              column_type_sql += "(#{precision},#{scale})"
            else
              column_type_sql += "(#{precision})"
            end
          else
            raise ArgumentError, "Error adding decimal column: precision cannot be empty if scale if specified" if scale
          end
          column_type_sql
        else
          limit ||= native[:limit]
          column_type_sql += "(#{limit})" if limit
          column_type_sql
        end
      end
    end
  end
end

module JdbcSpec
  module ActiveRecordExtensions
    def jdbc_connection(config)
      connection = ::ActiveRecord::ConnectionAdapters::JdbcConnection.new(config)
      ::ActiveRecord::ConnectionAdapters::JdbcAdapter.new(connection, logger, config)
    end
    alias jndi_connection jdbc_connection

    def embedded_driver(config)
      config[:username] ||= "sa"
      config[:password] ||= ""
      jdbc_connection(config)
    end
  end
end

module ActiveRecord
  class Base
    extend JdbcSpec::ActiveRecordExtensions

    alias :attributes_with_quotes_pre_oracle :attributes_with_quotes
    def attributes_with_quotes(*args) #:nodoc:
      aq = attributes_with_quotes_pre_oracle(*args)
      if connection.class == ConnectionAdapters::JdbcAdapter && (connection.is_a?(JdbcSpec::Oracle) || connection.is_a?(JdbcSpec::Mimer))
        aq[self.class.primary_key] = "?" if args.first && aq[self.class.primary_key].nil?
      end
      aq
    end
  end

  module ConnectionAdapters
    module Java
      Class = java.lang.Class
      URL = java.net.URL
      URLClassLoader = java.net.URLClassLoader
    end

    module Jdbc
      Mutex = java.lang.Object.new
      DriverManager = java.sql.DriverManager
      Statement = java.sql.Statement
      Types = java.sql.Types

      # some symbolic constants for the benefit of the JDBC-based
      # JdbcConnection#indexes method
      module IndexMetaData
        INDEX_NAME  = 6
        NON_UNIQUE  = 4
        TABLE_NAME  = 3
        COLUMN_NAME = 9
      end
{'fraction_non_alphanumeric': 0.08195002621002971, 'fraction_numerical': 0.0020968023763760267, 'mean_word_length': 2.818545697131421, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1786341', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1615, 'n_words': 404}