Sha256: a2d19e40bcbc2b31a2807d4be0b5aa9942ca7ed1402e07036b797f1856e37b47

Contents?: true

Size: 1.47 KB

Versions: 20

Compression:

Stored size: 1.47 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 =~ /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

20 entries across 20 versions & 1 rubygems

Version Path
activerecord-oracle_enhanced-adapter-6.0.6 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.5 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.4 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.3 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.8 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.2 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.0 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.0.rc3 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.0.rc2 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.6 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.0.rc1 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-6.0.0.beta1 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.5 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.4 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.3 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.2 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.1 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.0 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.0.rc1 lib/active_record/connection_adapters/oracle_enhanced/lob.rb
activerecord-oracle_enhanced-adapter-5.2.0.beta1 lib/active_record/connection_adapters/oracle_enhanced/lob.rb