activerecord-oracle_enhanced-adapter 1.4.3 → 1.5.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -14
  3. data/History.md +51 -0
  4. data/README.md +32 -1
  5. data/VERSION +1 -1
  6. data/activerecord-oracle_enhanced-adapter.gemspec +2 -4
  7. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +315 -57
  8. data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +55 -0
  9. data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +4 -13
  10. data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +5 -6
  11. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +19 -11
  12. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +163 -232
  13. data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +18 -10
  14. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +20 -32
  15. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +54 -35
  16. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +5 -74
  17. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +3 -2
  18. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +98 -98
  19. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +5 -1
  20. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -3
  21. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +11 -5
  22. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +56 -55
  23. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +15 -8
  24. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +4 -3
  25. data/spec/spec_helper.rb +25 -54
  26. metadata +32 -20
  27. data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +0 -41
  28. data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +0 -121
  29. data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +0 -17
@@ -0,0 +1,55 @@
1
+ module ActiveRecord #:nodoc:
2
+ module ConnectionAdapters #:nodoc:
3
+ module OracleEnhancedColumnDumper #:nodoc:
4
+
5
+ def self.included(base) #:nodoc:
6
+ base.class_eval do
7
+ private
8
+ alias_method_chain :column_spec, :oracle_enhanced
9
+ alias_method_chain :prepare_column_options, :oracle_enhanced
10
+ alias_method_chain :migration_keys, :oracle_enhanced
11
+ end
12
+ end
13
+
14
+ def column_spec_with_oracle_enhanced(column, types)
15
+ # return original method if not using 'OracleEnhanced'
16
+ if (rails_env = defined?(Rails.env) ? Rails.env : (defined?(RAILS_ENV) ? RAILS_ENV : nil)) &&
17
+ ActiveRecord::Base.configurations[rails_env] &&
18
+ ActiveRecord::Base.configurations[rails_env]['adapter'] != 'oracle_enhanced'
19
+ return column_spec_with_oracle_enhanced(column, types)
20
+ end
21
+
22
+ spec = prepare_column_options(column, types)
23
+ (spec.keys - [:name, :type]).each do |k|
24
+ key_s = (k == :virtual_type ? "type: " : "#{k.to_s}: ")
25
+ spec[k] = key_s + spec[k]
26
+ end
27
+ spec
28
+ end
29
+
30
+ def prepare_column_options_with_oracle_enhanced(column, types)
31
+ spec = {}
32
+ spec[:name] = column.name.inspect
33
+ spec[:type] = column.virtual? ? 'virtual' : column.type.to_s
34
+ spec[:virtual_type] = column.type.inspect if column.virtual? && column.sql_type != 'NUMBER'
35
+ spec[:limit] = column.limit.inspect if column.limit != types[column.type][:limit] && column.type != :decimal
36
+ spec[:precision] = column.precision.inspect if !column.precision.nil?
37
+ spec[:scale] = column.scale.inspect if !column.scale.nil?
38
+ spec[:null] = 'false' if !column.null
39
+ spec[:as] = column.virtual_column_data_default if column.virtual?
40
+ spec[:default] = default_string(column.default) if column.has_default? && !column.virtual?
41
+ spec
42
+ end
43
+
44
+ def migration_keys_with_oracle_enhanced
45
+ # TODO `& column_specs.map(&:keys).flatten` should be exetuted here
46
+ [:name, :limit, :precision, :scale, :default, :null, :as, :virtual_type]
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+
53
+ ActiveRecord::ConnectionAdapters::ColumnDumper.class_eval do
54
+ include ActiveRecord::ConnectionAdapters::OracleEnhancedColumnDumper
55
+ end
@@ -329,19 +329,10 @@ module ActiveRecord
329
329
 
330
330
  module ContextIndexClassMethods
331
331
  # Add context index condition.
332
- case ::ActiveRecord::VERSION::MAJOR
333
- when 3
334
- def contains(column, query, options ={})
335
- score_label = options[:label].to_i || 1
336
- where("CONTAINS(#{connection.quote_column_name(column)}, ?, #{score_label}) > 0", query).
337
- order("SCORE(#{score_label}) DESC")
338
- end
339
- when 2
340
- def contains(column, query, options ={})
341
- score_label = options[:label].to_i || 1
342
- scoped(:conditions => ["CONTAINS(#{connection.quote_column_name(column)}, ?, #{score_label}) > 0", query],
343
- :order => "SCORE(#{score_label}) DESC")
344
- end
332
+ def contains(column, query, options ={})
333
+ score_label = options[:label].to_i || 1
334
+ where("CONTAINS(#{connection.quote_column_name(column)}, ?, #{score_label}) > 0", query).
335
+ order("SCORE(#{score_label}) DESC")
345
336
  end
346
337
  end
347
338
 
@@ -18,7 +18,7 @@ module ActiveRecord #:nodoc:
18
18
  # therefore need to convert empty string value to nil if old value is nil
19
19
  elsif column.type == :string && column.null && old.nil?
20
20
  value = nil if value == ''
21
- elsif old == 0 && value.is_a?(String) && value.present? && value != '0'
21
+ elsif old == 0 && value.is_a?(String) && value.present? && non_zero?(value)
22
22
  value = nil
23
23
  else
24
24
  value = column.type_cast(value)
@@ -27,6 +27,10 @@ module ActiveRecord #:nodoc:
27
27
 
28
28
  old != value
29
29
  end
30
+
31
+ def non_zero?(value)
32
+ value !~ /\A0+(\.0+)?\z/
33
+ end
30
34
 
31
35
  end
32
36
 
@@ -37,10 +41,5 @@ end
37
41
  if ActiveRecord::Base.method_defined?(:changed?)
38
42
  ActiveRecord::Base.class_eval do
39
43
  include ActiveRecord::ConnectionAdapters::OracleEnhancedDirty::InstanceMethods
40
- # Starting with rails 3.2.9 the method #field_changed?
41
- # was renamed to #_field_changed?
42
- if private_method_defined?(:field_changed?)
43
- alias_method :field_changed?, :_field_changed?
44
- end
45
44
  end
46
45
  end
@@ -2,26 +2,34 @@ begin
2
2
  require "java"
3
3
  require "jruby"
4
4
 
5
- # ojdbc6.jar or ojdbc5.jar file should be in JRUBY_HOME/lib or should be in ENV['PATH'] or load path
5
+ # ojdbc7.jar, ojdbc6.jar or ojdbc5.jar file should be in application ./lib directory or in load path or in ENV['PATH']
6
6
 
7
7
  java_version = java.lang.System.getProperty("java.version")
8
- ojdbc_jar = if java_version =~ /^1.5/
9
- "ojdbc5.jar"
8
+ ojdbc_jars = if java_version =~ /^1.5/
9
+ %w(ojdbc5.jar)
10
10
  elsif java_version =~ /^1.6/
11
- "ojdbc6.jar"
11
+ %w(ojdbc6.jar)
12
12
  elsif java_version =~ /^1.7/
13
- "ojdbc7.jar"
13
+ # Oracle 11g client ojdbc6.jar is also compatible with Java 1.7
14
+ # Oracle 12c client provides new ojdbc7.jar
15
+ %w(ojdbc7.jar ojdbc6.jar)
14
16
  else
15
17
  nil
16
18
  end
17
19
 
18
- unless ojdbc_jar.nil? || ENV_JAVA['java.class.path'] =~ Regexp.new(ojdbc_jar)
20
+ if ojdbc_jars && ENV_JAVA['java.class.path'] !~ Regexp.new(ojdbc_jars.join('|'))
19
21
  # On Unix environment variable should be PATH, on Windows it is sometimes Path
20
22
  env_path = (ENV["PATH"] || ENV["Path"] || '').split(File::PATH_SEPARATOR)
21
23
  # Look for JDBC driver at first in lib subdirectory (application specific JDBC file version)
22
24
  # then in Ruby load path and finally in environment PATH
23
- if ojdbc_jar_path = ['./lib'].concat($LOAD_PATH).concat(env_path).find{|d| File.exists?(File.join(d,ojdbc_jar))}
24
- require File.join(ojdbc_jar_path,ojdbc_jar)
25
+ ['./lib'].concat($LOAD_PATH).concat(env_path).detect do |dir|
26
+ # check any compatible JDBC driver in the priority order
27
+ ojdbc_jars.any? do |ojdbc_jar|
28
+ if File.exists?(file_path = File.join(dir, ojdbc_jar))
29
+ require file_path
30
+ true
31
+ end
32
+ end
25
33
  end
26
34
  end
27
35
 
@@ -35,7 +43,7 @@ begin
35
43
 
36
44
  rescue LoadError, NameError
37
45
  # JDBC driver is unavailable.
38
- raise LoadError, "ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install #{ojdbc_jar || "Oracle JDBC"} library."
46
+ raise LoadError, "ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install #{ojdbc_jars.join(' or ') || "Oracle JDBC"} library."
39
47
  end
40
48
 
41
49
 
@@ -88,7 +96,7 @@ module ActiveRecord
88
96
  @raw_connection = @raw_connection.innermost_delegate
89
97
  elsif @raw_connection.respond_to?(:getUnderlyingConnection)
90
98
  @pooled_connection = @raw_connection
91
- @raw_connection = @raw_connection.underlying_connection
99
+ @raw_connection = @raw_connection.underlying_connection
92
100
  end
93
101
 
94
102
  config[:driver] ||= @raw_connection.meta_data.connection.java_class.name
@@ -287,7 +295,7 @@ module ActiveRecord
287
295
  # else
288
296
  # nil
289
297
  # end
290
-
298
+
291
299
  # Workaround with CallableStatement
292
300
  s = @raw_connection.prepareCall("BEGIN #{sql}; END;")
293
301
  s.registerOutParameter(1, java.sql.Types::BIGINT)
@@ -1,260 +1,191 @@
1
- # define accessors before requiring ruby-plsql as these accessors are used in clob writing callback and should be
2
- # available also if ruby-plsql could not be loaded
3
- ActiveRecord::Base.class_eval do
4
- if respond_to? :class_attribute
5
- class_attribute :custom_create_method, :custom_update_method, :custom_delete_method
6
- elsif respond_to? :class_inheritable_accessor
7
- class_inheritable_accessor :custom_create_method, :custom_update_method, :custom_delete_method
8
- end
9
- end
10
-
11
1
  require 'active_support'
12
2
 
13
3
  module ActiveRecord #:nodoc:
14
- module ConnectionAdapters #:nodoc:
15
- module OracleEnhancedProcedures #:nodoc:
16
-
17
- module ClassMethods
18
- # Specify custom create method which should be used instead of Rails generated INSERT statement.
19
- # Provided block should return ID of new record.
20
- # Example:
21
- # set_create_method do
22
- # plsql.employees_pkg.create_employee(
23
- # :p_first_name => first_name,
24
- # :p_last_name => last_name,
25
- # :p_employee_id => nil
26
- # )[:p_employee_id]
27
- # end
28
- def set_create_method(&block)
29
- include_with_custom_methods
30
- self.custom_create_method = block
31
- end
32
-
33
- # Specify custom update method which should be used instead of Rails generated UPDATE statement.
34
- # Example:
35
- # set_update_method do
36
- # plsql.employees_pkg.update_employee(
37
- # :p_employee_id => id,
38
- # :p_first_name => first_name,
39
- # :p_last_name => last_name
40
- # )
41
- # end
42
- def set_update_method(&block)
43
- include_with_custom_methods
44
- self.custom_update_method = block
45
- end
46
-
47
- # Specify custom delete method which should be used instead of Rails generated DELETE statement.
48
- # Example:
49
- # set_delete_method do
50
- # plsql.employees_pkg.delete_employee(
51
- # :p_employee_id => id
52
- # )
53
- # end
54
- def set_delete_method(&block)
55
- include_with_custom_methods
56
- self.custom_delete_method = block
57
- end
58
-
59
- if ActiveRecord::VERSION::MAJOR < 3
60
- def create_method_name_before_custom_methods #:nodoc:
61
- if private_method_defined?(:create_without_timestamps) && defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::STRING.to_f >= 2.3
62
- :create_without_timestamps
63
- elsif private_method_defined?(:create_without_callbacks)
64
- :create_without_callbacks
65
- else
66
- :create
67
- end
68
- end
69
-
70
- def update_method_name_before_custom_methods #:nodoc:
71
- if private_method_defined?(:update_without_dirty)
72
- :update_without_dirty
73
- elsif private_method_defined?(:update_without_timestamps) && defined?(ActiveRecord::VERSION) && ActiveRecord::VERSION::STRING.to_f >= 2.3
74
- :update_without_timestamps
75
- elsif private_method_defined?(:update_without_callbacks)
76
- :update_without_callbacks
77
- else
78
- :update
79
- end
80
- end
4
+ # Custom create, update, delete methods functionality.
5
+ #
6
+ # Example:
7
+ #
8
+ # class Employee < ActiveRecord::Base
9
+ # include ActiveRecord::OracleEnhancedProcedures
10
+ #
11
+ # set_create_method do
12
+ # plsql.employees_pkg.create_employee(
13
+ # :p_first_name => first_name,
14
+ # :p_last_name => last_name,
15
+ # :p_employee_id => nil
16
+ # )[:p_employee_id]
17
+ # end
18
+ #
19
+ # set_update_method do
20
+ # plsql.employees_pkg.update_employee(
21
+ # :p_employee_id => id,
22
+ # :p_first_name => first_name,
23
+ # :p_last_name => last_name
24
+ # )
25
+ # end
26
+ #
27
+ # set_delete_method do
28
+ # plsql.employees_pkg.delete_employee(
29
+ # :p_employee_id => id
30
+ # )
31
+ # end
32
+ # end
33
+ #
34
+ module OracleEnhancedProcedures #:nodoc:
35
+ module ClassMethods
36
+ # Specify custom create method which should be used instead of Rails generated INSERT statement.
37
+ # Provided block should return ID of new record.
38
+ # Example:
39
+ # set_create_method do
40
+ # plsql.employees_pkg.create_employee(
41
+ # :p_first_name => first_name,
42
+ # :p_last_name => last_name,
43
+ # :p_employee_id => nil
44
+ # )[:p_employee_id]
45
+ # end
46
+ def set_create_method(&block)
47
+ self.custom_create_method = block
48
+ end
81
49
 
82
- def destroy_method_name_before_custom_methods #:nodoc:
83
- if public_method_defined?(:destroy_without_callbacks)
84
- :destroy_without_callbacks
85
- else
86
- :destroy
87
- end
88
- end
89
- end
50
+ # Specify custom update method which should be used instead of Rails generated UPDATE statement.
51
+ # Example:
52
+ # set_update_method do
53
+ # plsql.employees_pkg.update_employee(
54
+ # :p_employee_id => id,
55
+ # :p_first_name => first_name,
56
+ # :p_last_name => last_name
57
+ # )
58
+ # end
59
+ def set_update_method(&block)
60
+ self.custom_update_method = block
61
+ end
90
62
 
91
- private
63
+ # Specify custom delete method which should be used instead of Rails generated DELETE statement.
64
+ # Example:
65
+ # set_delete_method do
66
+ # plsql.employees_pkg.delete_employee(
67
+ # :p_employee_id => id
68
+ # )
69
+ # end
70
+ def set_delete_method(&block)
71
+ self.custom_delete_method = block
72
+ end
73
+ end
92
74
 
93
- def include_with_custom_methods
94
- unless included_modules.include? InstanceMethods
95
- include InstanceMethods
96
- end
97
- end
75
+ def self.included(base)
76
+ base.class_eval do
77
+ extend ClassMethods
78
+ class_attribute :custom_create_method
79
+ class_attribute :custom_update_method
80
+ class_attribute :custom_delete_method
98
81
  end
82
+ end
99
83
 
100
- module InstanceMethods #:nodoc:
101
- def self.included(base)
102
- # alias methods just for ActiveRecord 2.x
103
- # for ActiveRecord 3.0 will just redefine create, update, delete methods which call super
104
- if ActiveRecord::VERSION::MAJOR < 3
105
- base.instance_eval do
106
- alias_method :create_without_custom_method, create_method_name_before_custom_methods
107
- alias_method create_method_name_before_custom_methods, :create_with_custom_method
108
- alias_method :update_without_custom_method, update_method_name_before_custom_methods
109
- alias_method update_method_name_before_custom_methods, :update_with_custom_method
110
- alias_method :destroy_without_custom_method, destroy_method_name_before_custom_methods
111
- alias_method destroy_method_name_before_custom_methods, :destroy_with_custom_method
112
- private :create, :update
113
- public :destroy
114
- end
115
- end
84
+ def destroy #:nodoc:
85
+ # check if class has custom delete method
86
+ if self.class.custom_delete_method
87
+ # wrap destroy in transaction
88
+ with_transaction_returning_status do
89
+ # run before/after callbacks defined in model
90
+ run_callbacks(:destroy) { destroy_using_custom_method }
116
91
  end
92
+ else
93
+ super
94
+ end
95
+ end
117
96
 
118
- if ActiveRecord::VERSION::MAJOR >= 3
119
- def destroy #:nodoc:
120
- # check if class has custom delete method
121
- if self.class.custom_delete_method
122
- # wrap destroy in transaction
123
- with_transaction_returning_status do
124
- # run before/after callbacks defined in model
125
- _run_destroy_callbacks { destroy_using_custom_method }
97
+ private
98
+
99
+ # Creates a record with custom create method
100
+ # and returns its id.
101
+ def create_record
102
+ # check if class has custom create method
103
+ if self.class.custom_create_method
104
+ # run before/after callbacks defined in model
105
+ run_callbacks(:create) do
106
+ # timestamp
107
+ if self.record_timestamps
108
+ current_time = current_time_from_proper_timezone
109
+
110
+ all_timestamp_attributes.each do |column|
111
+ if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
112
+ write_attribute(column.to_s, current_time)
126
113
  end
127
- else
128
- super
129
- end
130
- end
131
- end
132
-
133
- private
134
-
135
- # Creates a record with custom create method
136
- # and returns its id.
137
- if ActiveRecord::VERSION::MAJOR < 3
138
- def create_with_custom_method
139
- # check if class has custom create method
140
- self.class.custom_create_method ? create_using_custom_method : create_without_custom_method
141
- end
142
- else # ActiveRecord 3.x
143
- def create
144
- # check if class has custom create method
145
- if self.class.custom_create_method
146
- set_timestamps_before_custom_create_method
147
- # run before/after callbacks defined in model
148
- _run_create_callbacks { create_using_custom_method }
149
- else
150
- super
151
114
  end
152
115
  end
116
+ # run
117
+ create_using_custom_method
153
118
  end
119
+ else
120
+ super
121
+ end
122
+ end
154
123
 
155
- def create_using_custom_method
156
- self.class.connection.log_custom_method("custom create method", "#{self.class.name} Create") do
157
- self.id = instance_eval(&self.class.custom_create_method)
158
- end
159
- @new_record = false
160
- # Starting from ActiveRecord 3.0.3 @persisted is used instead of @new_record
161
- @persisted = true
162
- id
163
- end
124
+ def create_using_custom_method
125
+ log_custom_method("custom create method", "#{self.class.name} Create") do
126
+ self.id = instance_eval(&self.class.custom_create_method)
127
+ end
128
+ @new_record = false
129
+ # Starting from ActiveRecord 3.0.3 @persisted is used instead of @new_record
130
+ @persisted = true
131
+ id
132
+ end
164
133
 
165
- # Updates the associated record with custom update method
166
- # Returns the number of affected rows.
167
- if ActiveRecord::VERSION::MAJOR < 3
168
- def update_with_custom_method(attribute_names = @attributes.keys)
169
- # check if class has custom create method
170
- self.class.custom_update_method ? update_using_custom_method(attribute_names) : update_without_custom_method(attribute_names)
171
- end
172
- else # ActiveRecord 3.x
173
- def update(attribute_names = @attributes.keys)
174
- # check if class has custom update method
175
- if self.class.custom_update_method
176
- set_timestamps_before_custom_update_method
177
- # run before/after callbacks defined in model
178
- _run_update_callbacks do
179
- # update just dirty attributes
180
- if partial_updates?
181
- # Serialized attributes should always be written in case they've been
182
- # changed in place.
183
- update_using_custom_method(changed | (attributes.keys & self.class.serialized_attributes.keys))
184
- else
185
- update_using_custom_method(attribute_names)
186
- end
187
- end
188
- else
189
- super
134
+ # Updates the associated record with custom update method
135
+ # Returns the number of affected rows.
136
+ def update_record(attribute_names = @attributes.keys)
137
+ # check if class has custom update method
138
+ if self.class.custom_update_method
139
+ # run before/after callbacks defined in model
140
+ run_callbacks(:update) do
141
+ # timestamp
142
+ if should_record_timestamps?
143
+ current_time = current_time_from_proper_timezone
144
+
145
+ timestamp_attributes_for_update_in_model.each do |column|
146
+ column = column.to_s
147
+ next if attribute_changed?(column)
148
+ write_attribute(column, current_time)
190
149
  end
191
150
  end
192
- end
193
-
194
- def update_using_custom_method(attribute_names)
195
- return 0 if attribute_names.empty?
196
- self.class.connection.log_custom_method("custom update method with #{self.class.primary_key}=#{self.id}", "#{self.class.name} Update") do
197
- instance_eval(&self.class.custom_update_method)
198
- end
199
- 1
200
- end
201
-
202
- # Deletes the record in the database with custom delete method
203
- # and freezes this instance to reflect that no changes should
204
- # be made (since they can't be persisted).
205
- if ActiveRecord::VERSION::MAJOR < 3
206
- def destroy_with_custom_method
207
- # check if class has custom delete method
208
- self.class.custom_delete_method ? destroy_using_custom_method : destroy_without_custom_method
151
+ # update just dirty attributes
152
+ if partial_writes?
153
+ # Serialized attributes should always be written in case they've been
154
+ # changed in place.
155
+ update_using_custom_method(changed | (attributes.keys & self.class.serialized_attributes.keys))
156
+ else
157
+ update_using_custom_method(attribute_names)
209
158
  end
210
159
  end
160
+ else
161
+ super
162
+ end
163
+ end
211
164
 
212
- def destroy_using_custom_method
213
- unless new_record? || @destroyed
214
- self.class.connection.log_custom_method("custom delete method with #{self.class.primary_key}=#{self.id}", "#{self.class.name} Destroy") do
215
- instance_eval(&self.class.custom_delete_method)
216
- end
217
- end
218
-
219
- @destroyed = true
220
- freeze
221
- end
222
-
223
- if ActiveRecord::VERSION::MAJOR >= 3
224
- def set_timestamps_before_custom_create_method
225
- if record_timestamps
226
- current_time = current_time_from_proper_timezone
227
-
228
- write_attribute('created_at', current_time) if respond_to?(:created_at) && created_at.nil?
229
- write_attribute('created_on', current_time) if respond_to?(:created_on) && created_on.nil?
230
-
231
- write_attribute('updated_at', current_time) if respond_to?(:updated_at) && updated_at.nil?
232
- write_attribute('updated_on', current_time) if respond_to?(:updated_on) && updated_on.nil?
233
- end
234
- end
235
-
236
- def set_timestamps_before_custom_update_method
237
- if record_timestamps && (!partial_updates? || changed?)
238
- current_time = current_time_from_proper_timezone
165
+ def update_using_custom_method(attribute_names)
166
+ return 0 if attribute_names.empty?
167
+ log_custom_method("custom update method with #{self.class.primary_key}=#{self.id}", "#{self.class.name} Update") do
168
+ instance_eval(&self.class.custom_update_method)
169
+ end
170
+ 1
171
+ end
239
172
 
240
- write_attribute('updated_at', current_time) if respond_to?(:updated_at)
241
- write_attribute('updated_on', current_time) if respond_to?(:updated_on)
242
- end
243
- end
173
+ # Deletes the record in the database with custom delete method
174
+ # and freezes this instance to reflect that no changes should
175
+ # be made (since they can't be persisted).
176
+ def destroy_using_custom_method
177
+ unless new_record? || @destroyed
178
+ log_custom_method("custom delete method with #{self.class.primary_key}=#{self.id}", "#{self.class.name} Destroy") do
179
+ instance_eval(&self.class.custom_delete_method)
244
180
  end
245
-
246
181
  end
247
182
 
183
+ @destroyed = true
184
+ freeze
248
185
  end
249
- end
250
- end
251
186
 
252
- ActiveRecord::Base.class_eval do
253
- extend ActiveRecord::ConnectionAdapters::OracleEnhancedProcedures::ClassMethods
254
- end
255
-
256
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
257
- # public alias to log method which could be used from other objects
258
- alias_method :log_custom_method, :log
259
- public :log_custom_method
187
+ def log_custom_method(*args)
188
+ self.class.connection.send(:log, *args) { yield }
189
+ end
190
+ end
260
191
  end