<commit_before>require __DIR__ + 'abstract_adapter'
require 'fastthread'
require 'data_objects'

module DataMapper

  module Adapters

    # You must inherit from the DoAdapter, and implement the
    # required methods to adapt a database library for use with the DataMapper.
    #
    # NOTE: By inheriting from DataObjectsAdapter, you get a copy of all the
    # standard sub-modules (Quoting, Coersion and Queries) in your own Adapter.
    # You can extend and overwrite these copies without affecting the originals.
    class DataObjectsAdapter < AbstractAdapter

      def self.inherited(target)
        target.const_set('TYPES', TYPES.dup)
      end

      TYPES = {
        Fixnum  => 'int'.freeze,
        String   => 'varchar'.freeze,
        Text     => 'text'.freeze,
        Class    => 'varchar'.freeze,
        BigDecimal  => 'decimal'.freeze,
        Float    => 'float'.freeze,
        DateTime => 'datetime'.freeze,
        Date     => 'date'.freeze,
        TrueClass  => 'boolean'.freeze,
        Object   => 'text'.freeze
      }

      def begin_transaction
        raise NotImplementedError.new
      end

      def commit_transaction
        raise NotImplementedError.new
      end

      def rollback_transaction
        raise NotImplementedError.new
      end

      def within_transaction?
        !Thread::current["doa_#{@uri.scheme}_transaction"].nil?
      end

      def create_connection
        if within_transaction?
          Thread::current["doa_#{@uri.scheme}_transaction"]
        else
          # DataObjects::Connection.new(uri) will give you back the right
          # driver based on the Uri#scheme.
          DataObjects::Connection.new(@uri)
        end
      end

      def close_connection(connection)
        connection.close unless within_transaction?
      end

      # all of our CRUD
      # Methods dealing with a single instance object
      def create(repository, instance)
        dirty_attributes = instance.dirty_attributes
        properties = instance.class.properties(name).select { |property| dirty_attributes.key?(property.name) }

        connection = create_connection
        sql = create_statement(instance.class, properties)
        values = properties.map { |property| dirty_attributes[property.name] }

        DataMapper.logger.debug { "CREATE: #{sql}  PARAMETERS: #{values.inspect}" }
        command = connection.create_command(sql)

        result = command.execute_non_query(*values)

        close_connection(connection)<commit_msg>Added simple switch to use returning syntax.<commit_after>require __DIR__ + 'abstract_adapter'
require 'fastthread'
require 'data_objects'

module DataMapper

  module Adapters

    # You must inherit from the DoAdapter, and implement the
    # required methods to adapt a database library for use with the DataMapper.
    #
    # NOTE: By inheriting from DataObjectsAdapter, you get a copy of all the
    # standard sub-modules (Quoting, Coersion and Queries) in your own Adapter.
    # You can extend and overwrite these copies without affecting the originals.
    class DataObjectsAdapter < AbstractAdapter

      def self.inherited(target)
        target.const_set('TYPES', TYPES.dup)
      end

      TYPES = {
        Fixnum  => 'int'.freeze,
        String   => 'varchar'.freeze,
        Text     => 'text'.freeze,
        Class    => 'varchar'.freeze,
        BigDecimal  => 'decimal'.freeze,
        Float    => 'float'.freeze,
        DateTime => 'datetime'.freeze,
        Date     => 'date'.freeze,
        TrueClass  => 'boolean'.freeze,
        Object   => 'text'.freeze
      }

      def begin_transaction
        raise NotImplementedError.new
      end

      def commit_transaction
        raise NotImplementedError.new
      end

      def rollback_transaction
        raise NotImplementedError.new
      end

      def within_transaction?
        !Thread::current["doa_#{@uri.scheme}_transaction"].nil?
      end

      def create_connection
        if within_transaction?
          Thread::current["doa_#{@uri.scheme}_transaction"]
        else
          # DataObjects::Connection.new(uri) will give you back the right
          # driver based on the Uri#scheme.
          DataObjects::Connection.new(@uri)
        end
      end

      def close_connection(connection)
        connection.close unless within_transaction?
      end
      
      def create_with_returning?
        false
      end
      
      # all of our CRUD
      # Methods dealing with a single instance object
      def create(repository, instance)
        dirty_attributes = instance.dirty_attributes
        properties = instance.class.properties(name).select { |property| dirty_attributes.key?(property.name) }

        connection = create_connection
        sql = send(create_with_returning? ? :create_statement_with_returning : :create_statement, instance.class, properties)
        values = properties.map { |property| dirty_attributes[property.name] }

        DataMapper.logger.debug { "CREATE: #{sql}  PARAMETERS: #{values.inspect}" }
        command = connection.create_command(sql)

        result = command.execute_non_query(*values)

        close_connection(connection)
{'fraction_non_alphanumeric': 0.08301158301158301, 'fraction_numerical': 0.0, 'mean_word_length': 2.558379120879121, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '7313430', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1360, 'n_words': 370}