Sha256: 4ab6fd5a357bd18256db225c65425a0289e2b8c40b641df765855362a89ba6b4

Contents?: true

Size: 1.48 KB

Versions: 8

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module ActiveRecord # :nodoc:
  module ConnectionAdapters # :nodoc:
    module OracleEnhanced # :nodoc:
      module Lob # :nodoc:
        extend ActiveSupport::Concern

        included do
          class_attribute :custom_create_method, :custom_update_method, :custom_delete_method

          # After setting large objects to empty, select the OCI8::LOB
          # and write back the data.
          before_update :record_changed_lobs
          after_update :enhanced_write_lobs
        end

        module ClassMethods
          def lob_columns
            columns.select do |column|
              column.sql_type_metadata.sql_type.end_with?("LOB")
            end
          end
        end

        private
          def enhanced_write_lobs
            if self.class.connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
                !(self.class.custom_create_method || self.class.custom_update_method)
              self.class.connection.write_lobs(self.class.table_name, self.class, attributes, @changed_lob_columns)
            end
          end
          def record_changed_lobs
            @changed_lob_columns = self.class.lob_columns.select do |col|
              self.will_save_change_to_attribute?(col.name) && !self.class.readonly_attributes.to_a.include?(col.name)
            end
          end
      end
    end
  end
end

ActiveSupport.on_load(:active_record) do
  ActiveRecord::Base.send(:include, ActiveRecord::ConnectionAdapters::OracleEnhanced::Lob)
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
activerecord-oracle_enhanced-adapter-7.1.0 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-7.1.0.beta2 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-7.1.0.beta1 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-7.0.3 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-7.0.2 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-7.0.1 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-7.0.0 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-7.0.0.rc1 lib/active_record/connection_adapters/oracle_enhanced/lob.rb