@@ -873,22 +873,57 @@ def self.type_cast_config_to_boolean(config)
873873
874874 # @note Used by Java API to convert dates from (custom) SELECTs (might get refactored).
875875 # @private
876- def _string_to_date ( value )
877- jdbc_column_class . string_to_date ( value )
878- end
876+ def _string_to_date ( value ) ; jdbc_column_class . string_to_date ( value ) end
879877
880878 # @note Used by Java API to convert times from (custom) SELECTs (might get refactored).
881879 # @private
882- def _string_to_time ( value )
883- jdbc_column_class . string_to_dummy_time ( value )
884- end
880+ def _string_to_time ( value ) ; jdbc_column_class . string_to_dummy_time ( value ) end
885881
886882 # @note Used by Java API to convert times from (custom) SELECTs (might get refactored).
887883 # @private
888- def _string_to_timestamp ( value )
889- jdbc_column_class . string_to_time ( value )
884+ def _string_to_timestamp ( value ) ; jdbc_column_class . string_to_time ( value ) end
885+
886+ if ActiveRecord ::VERSION ::STRING > '4.2'
887+
888+ # @private
889+ @@_date = nil
890+
891+ # @private
892+ def _string_to_date ( value )
893+ if jdbc_column_class . respond_to? ( :string_to_date )
894+ jdbc_column_class . string_to_date ( value )
895+ else
896+ ( @@_date ||= ActiveRecord ::Type ::Date . new ) . send ( :cast_value , value )
897+ end
898+ end
899+
900+ # @private
901+ @@_time = nil
902+
903+ # @private
904+ def _string_to_time ( value )
905+ if jdbc_column_class . respond_to? ( :string_to_dummy_time )
906+ jdbc_column_class . string_to_dummy_time ( value )
907+ else
908+ ( @@_time ||= ActiveRecord ::Type ::Time . new ) . send ( :cast_value , value )
909+ end
910+ end
911+
912+ # @private
913+ @@_date_time = nil
914+
915+ # @private
916+ def _string_to_timestamp ( value )
917+ if jdbc_column_class . respond_to? ( :string_to_time )
918+ jdbc_column_class . string_to_time ( value )
919+ else
920+ ( @@_date_time ||= ActiveRecord ::Type ::DateTime . new ) . send ( :cast_value , value )
921+ end
922+ end
923+
890924 end
891925
926+
892927 if ActiveRecord ::VERSION ::MAJOR < 4 # emulating Rails 3.x compatibility
893928 JdbcConnection . raw_date_time = true if JdbcConnection . raw_date_time? == nil
894929 JdbcConnection . raw_boolean = true if JdbcConnection . raw_boolean? == nil
0 commit comments