3 # Establishes a connection to the database that's used by all Active Record objects.
4 def self.oracle_enhanced_connection(config) #:nodoc:
5 if config[:emulate_oracle_adapter] == true
6 # allows the enhanced adapter to look like the OracleAdapter. Useful to pick up
7 # conditionals in the rails activerecord test suite
8 require 'active_record/connection_adapters/emulation/oracle_adapter'
9 ConnectionAdapters::OracleAdapter.new(
10 ConnectionAdapters::OracleEnhancedConnection.create(config), logger)
12 ConnectionAdapters::OracleEnhancedAdapter.new(
13 ConnectionAdapters::OracleEnhancedConnection.create(config), logger)
17 # Specify table columns which should be ignored by ActiveRecord, e.g.:
19 # ignore_table_columns :attribute1, :attribute2
20 def self.ignore_table_columns(*args)
21 connection.ignore_table_columns(table_name,*args)
24 # Specify which table columns should be typecasted to Date (without time), e.g.:
26 # set_date_columns :created_on, :updated_on
27 def self.set_date_columns(*args)
28 connection.set_type_for_columns(table_name,:date,*args)
31 # Specify which table columns should be typecasted to Time (or DateTime), e.g.:
33 # set_datetime_columns :created_date, :updated_date
34 def self.set_datetime_columns(*args)
35 connection.set_type_for_columns(table_name,:datetime,*args)
38 # Specify which table columns should be typecasted to boolean values +true+ or +false+, e.g.:
40 # set_boolean_columns :is_valid, :is_completed
41 def self.set_boolean_columns(*args)
42 connection.set_type_for_columns(table_name,:boolean,*args)
45 # Specify which table columns should be typecasted to integer values.
46 # Might be useful to force NUMBER(1) column to be integer and not boolean, or force NUMBER column without
47 # scale to be retrieved as integer and not decimal. Example:
49 # set_integer_columns :version_number, :object_identifier
50 def self.set_integer_columns(*args)
51 connection.set_type_for_columns(table_name,:integer,*args)
54 # Specify which table columns should be typecasted to string values.
55 # Might be useful to specify that columns should be string even if its name matches boolean column criteria.
57 # set_string_columns :active_flag
58 def self.set_string_columns(*args)
59 connection.set_type_for_columns(table_name,:string,*args)
62 # After setting large objects to empty, select the OCI8::LOB
63 # and write back the data.
64 if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 1
65 after_update :enhanced_write_lobs
67 after_save :enhanced_write_lobs
69 def enhanced_write_lobs #:nodoc:
70 if connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
71 !(self.class.custom_create_method || self.class.custom_update_method)
72 connection.write_lobs(self.class.table_name, self.class, attributes)
75 private :enhanced_write_lobs
77 # Get table comment from schema definition.
78 def self.table_comment
79 connection.table_comment(self.table_name)
82 if ActiveRecord::VERSION::MAJOR < 3
83 def attributes_with_quotes_with_virtual_columns(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
84 virtual_columns = self.class.columns.select(& :virtual?).map(&:name)
85 attributes_with_quotes_without_virtual_columns(include_primary_key, include_readonly_attributes, attribute_names - virtual_columns)
88 alias_method_chain :attributes_with_quotes, :virtual_columns
90 def arel_attributes_values_with_virtual_columns(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
91 virtual_columns = self.class.columns.select(& :virtual?).map(&:name)
92 arel_attributes_values_without_virtual_columns(include_primary_key, include_readonly_attributes, attribute_names - virtual_columns)
95 alias_method_chain :arel_attributes_values, :virtual_columns