Permalink
Browse files

Initial support for ActiveRecord 4. Dropping support for older versions.

  • Loading branch information...
1 parent c06c90b commit 9369d15b77da24c6fd06928d90cbe755a1f6982b @ebeigarts ebeigarts committed Apr 12, 2012
View
@@ -1,7 +1,7 @@
source 'http://rubygems.org'
group :development do
- gem 'jeweler', '~> 1.5.1'
+ # gem 'jeweler', '~> 1.5.1'
gem 'rspec', '~> 2.4'
gem 'rdoc'
@@ -41,6 +41,8 @@ group :development do
else
gem "journey", :git => "git://github.com/rails/journey"
end
+
+ gem "active_record_deprecated_finders", :git => "git://github.com/rails/active_record_deprecated_finders"
end
gem 'ruby-plsql', '>=0.4.4'
@@ -1,41 +0,0 @@
-# ActiveRecord 2.3 patches
-if ActiveRecord::VERSION::MAJOR == 2 && ActiveRecord::VERSION::MINOR == 3
- require "active_record/associations"
-
- ActiveRecord::Associations::ClassMethods.module_eval do
- private
- def tables_in_string(string)
- return [] if string.blank?
- if self.connection.adapter_name == "OracleEnhanced"
- # always convert table names to downcase as in Oracle quoted table names are in uppercase
- # ignore raw_sql_ that is used by Oracle adapter as alias for limit/offset subqueries
- string.scan(/([a-zA-Z_][\.\w]+).?\./).flatten.map(&:downcase).uniq - ['raw_sql_']
- else
- string.scan(/([\.a-zA-Z_]+).?\./).flatten
- end
- end
- end
-
- ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation.class_eval do
- protected
- def aliased_table_name_for(name, suffix = nil)
- # always downcase quoted table name as Oracle quoted table names are in uppercase
- if !parent.table_joins.blank? && parent.table_joins.to_s.downcase =~ %r{join(\s+\w+)?\s+#{active_record.connection.quote_table_name(name).downcase}\son}
- @join_dependency.table_aliases[name] += 1
- end
-
- unless @join_dependency.table_aliases[name].zero?
- # if the table name has been used, then use an alias
- name = active_record.connection.table_alias_for "#{pluralize(reflection.name)}_#{parent_table_name}#{suffix}"
- table_index = @join_dependency.table_aliases[name]
- @join_dependency.table_aliases[name] += 1
- name = name[0..active_record.connection.table_alias_length-3] + "_#{table_index+1}" if table_index > 0
- else
- @join_dependency.table_aliases[name] += 1
- end
-
- name
- end
- end
-
-end
@@ -29,18 +29,30 @@
# contribution.
# portions Copyright 2005 Graham Jenkins
-# ActiveRecord 2.2 does not load version file automatically
-require 'active_record/version' unless defined?(ActiveRecord::VERSION)
-
require 'active_record/connection_adapters/abstract_adapter'
require 'active_record/connection_adapters/oracle_enhanced_connection'
-require 'active_record/connection_adapters/oracle_enhanced_base_ext'
require 'active_record/connection_adapters/oracle_enhanced_column'
require 'digest/sha1'
module ActiveRecord
+ module ConnectionHandling #:nodoc:
+ # Establishes a connection to the database that's used by all Active Record objects.
+ def oracle_enhanced_connection(config) #:nodoc:
+ if config[:emulate_oracle_adapter] == true
+ # allows the enhanced adapter to look like the OracleAdapter. Useful to pick up
+ # conditionals in the rails activerecord test suite
+ require 'active_record/connection_adapters/emulation/oracle_adapter'
+ ConnectionAdapters::OracleAdapter.new(
+ ConnectionAdapters::OracleEnhancedConnection.create(config), logger, config)
+ else
+ ConnectionAdapters::OracleEnhancedAdapter.new(
+ ConnectionAdapters::OracleEnhancedConnection.create(config), logger, config)
+ end
+ end
+ end
+
module ConnectionAdapters #:nodoc:
# Oracle enhanced adapter will work with both
@@ -852,9 +864,9 @@ def insert_fixture(fixture, table_name) #:nodoc:
super
if ActiveRecord::Base.pluralize_table_names
- klass = table_name.singularize.camelize
+ klass = table_name.to_s.singularize.camelize
else
- klass = table_name.camelize
+ klass = table_name.to_s.camelize
end
klass = klass.constantize rescue nil
@@ -1337,18 +1349,7 @@ def log_dbms_output
end
end
-# Added LOB writing callback for sessions stored in database
-# Otherwise it is not working as Session class is defined before OracleAdapter is loaded in Rails 2.0
-if defined?(CGI::Session::ActiveRecordStore::Session)
- if !CGI::Session::ActiveRecordStore::Session.respond_to?(:after_save_callback_chain) ||
- CGI::Session::ActiveRecordStore::Session.after_save_callback_chain.detect{|cb| cb.method == :enhanced_write_lobs}.nil?
- #:stopdoc:
- class CGI::Session::ActiveRecordStore::Session
- after_save :enhanced_write_lobs
- end
- #:startdoc:
- end
-end
+require 'active_record/connection_adapters/oracle_enhanced_model'
# Implementation of standard schema definition statements and extensions for schema definition
require 'active_record/connection_adapters/oracle_enhanced_schema_statements'
@@ -1360,21 +1361,12 @@ class CGI::Session::ActiveRecordStore::Session
# Extensions for context index definition
require 'active_record/connection_adapters/oracle_enhanced_context_index'
-# Load custom create, update, delete methods functionality
-require 'active_record/connection_adapters/oracle_enhanced_procedures'
-
# Load additional methods for composite_primary_keys support
require 'active_record/connection_adapters/oracle_enhanced_cpk'
# Load patch for dirty tracking methods
require 'active_record/connection_adapters/oracle_enhanced_dirty'
-# Load rake tasks definitions
-begin
- require 'active_record/connection_adapters/oracle_enhanced_tasks'
-rescue LoadError
-end if defined?(Rails) || defined?(RAILS_ROOT)
-
# Patches and enhancements for schema dumper
require 'active_record/connection_adapters/oracle_enhanced_schema_dumper'
@@ -1384,6 +1376,18 @@ class CGI::Session::ActiveRecordStore::Session
# Add BigDecimal#to_d, Fixnum#to_d and Bignum#to_d methods if not already present
require 'active_record/connection_adapters/oracle_enhanced_core_ext'
-require 'active_record/connection_adapters/oracle_enhanced_activerecord_patches'
-
require 'active_record/connection_adapters/oracle_enhanced_version'
+
+module ActiveRecord
+ autoload :OracleEnhancedProcedures, 'active_record/connection_adapters/oracle_enhanced_procedures'
+
+ module Model
+ include OracleEnhancedModel
+ end
+
+ class Base
+ # Include ActiveRecord::OracleEnhancedModel also in ActiveRecord::Base, since we are too late -
+ # the ActiveRecord::Model has already been loaded into ActiveRecord::Base.
+ include OracleEnhancedModel
+ end
+end
@@ -1,106 +0,0 @@
-module ActiveRecord
- class Base
- # Establishes a connection to the database that's used by all Active Record objects.
- def self.oracle_enhanced_connection(config) #:nodoc:
- if config[:emulate_oracle_adapter] == true
- # allows the enhanced adapter to look like the OracleAdapter. Useful to pick up
- # conditionals in the rails activerecord test suite
- require 'active_record/connection_adapters/emulation/oracle_adapter'
- ConnectionAdapters::OracleAdapter.new(
- ConnectionAdapters::OracleEnhancedConnection.create(config), logger, config)
- else
- ConnectionAdapters::OracleEnhancedAdapter.new(
- ConnectionAdapters::OracleEnhancedConnection.create(config), logger, config)
- end
- end
-
- # Specify table columns which should be ignored by ActiveRecord, e.g.:
- #
- # ignore_table_columns :attribute1, :attribute2
- def self.ignore_table_columns(*args)
- connection.ignore_table_columns(table_name,*args)
- end
-
- # Specify which table columns should be typecasted to Date (without time), e.g.:
- #
- # set_date_columns :created_on, :updated_on
- def self.set_date_columns(*args)
- connection.set_type_for_columns(table_name,:date,*args)
- end
-
- # Specify which table columns should be typecasted to Time (or DateTime), e.g.:
- #
- # set_datetime_columns :created_date, :updated_date
- def self.set_datetime_columns(*args)
- connection.set_type_for_columns(table_name,:datetime,*args)
- end
-
- # Specify which table columns should be typecasted to boolean values +true+ or +false+, e.g.:
- #
- # set_boolean_columns :is_valid, :is_completed
- def self.set_boolean_columns(*args)
- connection.set_type_for_columns(table_name,:boolean,*args)
- end
-
- # Specify which table columns should be typecasted to integer values.
- # Might be useful to force NUMBER(1) column to be integer and not boolean, or force NUMBER column without
- # scale to be retrieved as integer and not decimal. Example:
- #
- # set_integer_columns :version_number, :object_identifier
- def self.set_integer_columns(*args)
- connection.set_type_for_columns(table_name,:integer,*args)
- end
-
- # Specify which table columns should be typecasted to string values.
- # Might be useful to specify that columns should be string even if its name matches boolean column criteria.
- #
- # set_string_columns :active_flag
- def self.set_string_columns(*args)
- connection.set_type_for_columns(table_name,:string,*args)
- end
-
- # After setting large objects to empty, select the OCI8::LOB
- # and write back the data.
- if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 1
- after_update :enhanced_write_lobs
- else
- after_save :enhanced_write_lobs
- end
- def enhanced_write_lobs #:nodoc:
- if connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
- !(self.class.custom_create_method || self.class.custom_update_method)
- connection.write_lobs(self.class.table_name, self.class, attributes)
- end
- end
- private :enhanced_write_lobs
-
- # Get table comment from schema definition.
- def self.table_comment
- connection.table_comment(self.table_name)
- end
-
- def self.virtual_columns
- columns.select do |column|
- column.respond_to?(:virtual?) && column.virtual?
- end
- end
-
- if ActiveRecord::VERSION::MAJOR < 3
- def attributes_with_quotes_with_virtual_columns(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
- virtual_column_names = self.class.virtual_columns.map(&:name)
- attributes_with_quotes_without_virtual_columns(include_primary_key, include_readonly_attributes, attribute_names - virtual_column_names)
- end
-
- alias_method_chain :attributes_with_quotes, :virtual_columns
- else
- def arel_attributes_values_with_virtual_columns(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
- virtual_column_names = self.class.virtual_columns.map(&:name)
- arel_attributes_values_without_virtual_columns(include_primary_key, include_readonly_attributes, attribute_names - virtual_column_names)
- end
-
- alias_method_chain :arel_attributes_values, :virtual_columns
- end
-
- end
-
-end
@@ -298,19 +298,10 @@ def has_context_index
module ContextIndexClassMethods
# Add context index condition.
- case ::ActiveRecord::VERSION::MAJOR
- when 3
- def contains(column, query, options ={})
- score_label = options[:label].to_i || 1
- where("CONTAINS(#{connection.quote_column_name(column)}, ?, #{score_label}) > 0", query).
- order("SCORE(#{score_label}) DESC")
- end
- when 2
- def contains(column, query, options ={})
- score_label = options[:label].to_i || 1
- scoped(:conditions => ["CONTAINS(#{connection.quote_column_name(column)}, ?, #{score_label}) > 0", query],
- :order => "SCORE(#{score_label}) DESC")
- end
+ def contains(column, query, options ={})
+ score_label = options[:label].to_i || 1
+ where("CONTAINS(#{connection.quote_column_name(column)}, ?, #{score_label}) > 0", query).
+ order("SCORE(#{score_label}) DESC")
end
end
@@ -0,0 +1,97 @@
+module ActiveRecord
+ module OracleEnhancedModel
+ module ClassMethods
+ # TODO REMOVE THIS AND PATCH #5267 commit 2fdb521
+ def sequence_name
+ if base_class == self
+ reset_sequence_name
+ @sequence_name
+ else
+ (@sequence_name ||= nil) || base_class.sequence_name
+ end
+ end
+
+ # Specify table columns which should be ignored by ActiveRecord, e.g.:
+ #
+ # ignore_table_columns :attribute1, :attribute2
+ def ignore_table_columns(*args)
+ connection.ignore_table_columns(table_name,*args)
+ end
+
+ # Specify which table columns should be typecasted to Date (without time), e.g.:
+ #
+ # set_date_columns :created_on, :updated_on
+ def set_date_columns(*args)
+ connection.set_type_for_columns(table_name,:date,*args)
+ end
+
+ # Specify which table columns should be typecasted to Time (or DateTime), e.g.:
+ #
+ # set_datetime_columns :created_date, :updated_date
+ def set_datetime_columns(*args)
+ connection.set_type_for_columns(table_name,:datetime,*args)
+ end
+
+ # Specify which table columns should be typecasted to boolean values +true+ or +false+, e.g.:
+ #
+ # set_boolean_columns :is_valid, :is_completed
+ def set_boolean_columns(*args)
+ connection.set_type_for_columns(table_name,:boolean,*args)
+ end
+
+ # Specify which table columns should be typecasted to integer values.
+ # Might be useful to force NUMBER(1) column to be integer and not boolean, or force NUMBER column without
+ # scale to be retrieved as integer and not decimal. Example:
+ #
+ # set_integer_columns :version_number, :object_identifier
+ def set_integer_columns(*args)
+ connection.set_type_for_columns(table_name,:integer,*args)
+ end
+
+ # Specify which table columns should be typecasted to string values.
+ # Might be useful to specify that columns should be string even if its name matches boolean column criteria.
+ #
+ # set_string_columns :active_flag
+ def set_string_columns(*args)
+ connection.set_type_for_columns(table_name,:string,*args)
+ end
+
+ # Get table comment from schema definition.
+ def table_comment
+ connection.table_comment(self.table_name)
+ end
+
+ def virtual_columns
+ columns.select do |column|
+ column.respond_to?(:virtual?) && column.virtual?
+ end
+ end
+ end
+
+ def self.included(base)
+ base.class_eval do
+ extend ClassMethods
+ end
+ end
+
+ def arel_attributes_with_values(attribute_names)
+ virtual_column_names = self.class.virtual_columns.map(&:name)
+ super(attribute_names - virtual_column_names)
+ end
+
+ private
+
+ # After setting large objects to empty, select the OCI8::LOB
+ # and write back the data.
+ def update
+ super
+ if connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
+ !(
+ (self.class.respond_to?(:custom_create_method) && self.class.custom_create_method) ||
+ (self.class.respond_to?(:custom_update_method) && self.class.custom_update_method)
+ )
+ connection.write_lobs(self.class.table_name, self.class, attributes)
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 9369d15

Please sign in to comment.