activerecord-jdbc-adapter 70.0.pre-java → 70.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/activerecord-jdbc-adapter.gemspec +1 -3
  4. data/lib/arel/visitors/compat.rb +5 -33
  5. data/lib/arel/visitors/h2.rb +1 -13
  6. data/lib/arel/visitors/hsqldb.rb +1 -21
  7. data/lib/arel/visitors/sql_server.rb +2 -103
  8. data/lib/arjdbc/abstract/core.rb +8 -9
  9. data/lib/arjdbc/abstract/database_statements.rb +8 -0
  10. data/lib/arjdbc/discover.rb +0 -67
  11. data/lib/arjdbc/jdbc/adapter.rb +1 -1
  12. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  13. data/lib/arjdbc/jdbc/column.rb +1 -26
  14. data/lib/arjdbc/jdbc.rb +0 -7
  15. data/lib/arjdbc/mysql/adapter.rb +2 -1
  16. data/lib/arjdbc/oracle/adapter.rb +4 -23
  17. data/lib/arjdbc/postgresql/adapter.rb +152 -3
  18. data/lib/arjdbc/postgresql/oid_types.rb +155 -108
  19. data/lib/arjdbc/sqlite3/adapter.rb +54 -36
  20. data/lib/arjdbc/tasks/database_tasks.rb +0 -15
  21. data/lib/arjdbc/util/serialized_attributes.rb +0 -22
  22. data/lib/arjdbc/util/table_copier.rb +2 -1
  23. data/lib/arjdbc/version.rb +1 -1
  24. data/rakelib/02-test.rake +3 -18
  25. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +5 -0
  26. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +5 -0
  27. metadata +5 -38
  28. data/lib/active_record/connection_adapters/as400_adapter.rb +0 -2
  29. data/lib/active_record/connection_adapters/db2_adapter.rb +0 -1
  30. data/lib/active_record/connection_adapters/derby_adapter.rb +0 -1
  31. data/lib/active_record/connection_adapters/informix_adapter.rb +0 -1
  32. data/lib/arel/visitors/db2.rb +0 -137
  33. data/lib/arel/visitors/derby.rb +0 -112
  34. data/lib/arel/visitors/firebird.rb +0 -79
  35. data/lib/arjdbc/db2/adapter.rb +0 -808
  36. data/lib/arjdbc/db2/as400.rb +0 -142
  37. data/lib/arjdbc/db2/column.rb +0 -131
  38. data/lib/arjdbc/db2/connection_methods.rb +0 -48
  39. data/lib/arjdbc/db2.rb +0 -4
  40. data/lib/arjdbc/derby/active_record_patch.rb +0 -13
  41. data/lib/arjdbc/derby/adapter.rb +0 -521
  42. data/lib/arjdbc/derby/connection_methods.rb +0 -20
  43. data/lib/arjdbc/derby/schema_creation.rb +0 -15
  44. data/lib/arjdbc/derby.rb +0 -3
  45. data/lib/arjdbc/firebird/adapter.rb +0 -413
  46. data/lib/arjdbc/firebird/connection_methods.rb +0 -23
  47. data/lib/arjdbc/firebird.rb +0 -4
  48. data/lib/arjdbc/informix/adapter.rb +0 -139
  49. data/lib/arjdbc/informix/connection_methods.rb +0 -9
  50. data/lib/arjdbc/sybase/adapter.rb +0 -47
  51. data/lib/arjdbc/sybase.rb +0 -2
  52. data/lib/arjdbc/tasks/db2_database_tasks.rb +0 -104
  53. data/lib/arjdbc/tasks/derby_database_tasks.rb +0 -95
  54. data/src/java/arjdbc/derby/DerbyModule.java +0 -178
  55. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +0 -152
  56. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +0 -174
  57. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +0 -75
@@ -1,142 +0,0 @@
1
- require 'arjdbc/db2/adapter'
2
-
3
- module ArJdbc
4
- module AS400
5
- include DB2
6
-
7
- module ActiveRecord::ConnectionAdapters
8
- remove_const(:AS400Adapter) if const_defined?(:AS400Adapter)
9
- class AS400Adapter < DB2Adapter
10
-
11
- include ::ArJdbc::AS400
12
-
13
- def jdbc_connection_class(spec)
14
- ArJdbc::AS400.jdbc_connection_class
15
- end
16
- end
17
- end
18
-
19
- # @private
20
- def self.extended(adapter); DB2.extended(adapter); end
21
-
22
- # @private
23
- def self.initialize!; DB2.initialize!; end
24
-
25
- # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
26
- def self.jdbc_connection_class; DB2.jdbc_connection_class; end
27
-
28
- def self.column_selector
29
- [ /as400/i, lambda { |config, column| column.extend(Column) } ]
30
- end
31
-
32
- # Boolean emulation can be disabled using :
33
- #
34
- # ArJdbc::AS400.emulate_booleans = false
35
- #
36
- def self.emulate_booleans; DB2.emulate_booleans; end
37
- def self.emulate_booleans=(emulate); DB2.emulate_booleans = emulate; end
38
-
39
- ADAPTER_NAME = 'AS400'.freeze
40
-
41
- def adapter_name
42
- ADAPTER_NAME
43
- end
44
-
45
- # @override
46
- def prefetch_primary_key?(table_name = nil)
47
- # TRUE if the table has no identity column
48
- names = table_name.upcase.split(".")
49
- sql = "SELECT 1 FROM SYSIBM.SQLPRIMARYKEYS WHERE "
50
- sql << "TABLE_SCHEM = '#{names.first}' AND " if names.size == 2
51
- sql << "TABLE_NAME = '#{names.last}'"
52
- select_one(sql).nil?
53
- end
54
-
55
- # @override
56
- def rename_column(table_name, column_name, new_column_name)
57
- raise NotImplementedError, "rename_column is not supported on IBM iSeries"
58
- end
59
-
60
- # @override
61
- def execute_table_change(sql, table_name, name = nil)
62
- execute_and_auto_confirm(sql, name)
63
- end
64
-
65
- # holy moly batman! all this to tell AS400 "yes i am sure"
66
- def execute_and_auto_confirm(sql, name = nil)
67
-
68
- begin
69
- @connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*SYSRPYL)',0000000031.00000)"
70
- @connection.execute_update "call qsys.qcmdexc('ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY(''I'')',0000000045.00000)"
71
- rescue Exception => e
72
- raise "Could not call CHGJOB INQMSGRPY(*SYSRPYL) and ADDRPYLE SEQNBR(9876) MSGID(CPA32B2) RPY('I').\n" +
73
- "Do you have authority to do this?\n\n#{e.inspect}"
74
- end
75
-
76
- begin
77
- result = execute(sql, name)
78
- rescue Exception
79
- raise
80
- else
81
- # Return if all work fine
82
- result
83
- ensure
84
-
85
- # Ensure default configuration restoration
86
- begin
87
- @connection.execute_update "call qsys.qcmdexc('QSYS/CHGJOB INQMSGRPY(*DFT)',0000000027.00000)"
88
- @connection.execute_update "call qsys.qcmdexc('RMVRPYLE SEQNBR(9876)',0000000021.00000)"
89
- rescue Exception => e
90
- raise "Could not call CHGJOB INQMSGRPY(*DFT) and RMVRPYLE SEQNBR(9876).\n" +
91
- "Do you have authority to do this?\n\n#{e.inspect}"
92
- end
93
-
94
- end
95
- end
96
- private :execute_and_auto_confirm
97
-
98
- # disable all schemas browsing when default schema is specified
99
- def table_exists?(name)
100
- return false unless name
101
- schema ? @connection.table_exists?(name, schema) : @connection.table_exists?(name)
102
- end
103
-
104
- DRIVER_NAME = 'com.ibm.as400.access.AS400JDBCDriver'.freeze
105
-
106
- # @private
107
- # @deprecated no longer used
108
- def as400?
109
- true
110
- end
111
-
112
- private
113
-
114
- # @override
115
- def db2_schema
116
- @db2_schema = false unless defined? @db2_schema
117
- return @db2_schema if @db2_schema != false
118
- @db2_schema =
119
- if config[:schema].present?
120
- config[:schema]
121
- elsif config[:jndi].present?
122
- # Only found method to set db2_schema from jndi
123
- result = select_one("SELECT CURRENT_SCHEMA FROM SYSIBM.SYSDUMMY1")
124
- schema = result['00001']
125
- # If the connection uses the library list schema name will be nil
126
- if schema == '*LIBL'
127
- schema = nil
128
- end
129
- schema
130
- else
131
- # AS400 implementation takes schema from library name (last part of URL)
132
- # jdbc:as400://localhost/schema;naming=system;libraries=lib1,lib2
133
- schema = nil
134
- split = config[:url].split('/')
135
- # Return nil if schema isn't defined
136
- schema = split.last.split(';').first.strip if split.size == 4
137
- schema
138
- end
139
- end
140
-
141
- end
142
- end
@@ -1,131 +0,0 @@
1
- module ArJdbc
2
- module DB2
3
-
4
- # @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
5
- def self.column_selector
6
- [ /(db2|zos)/i, lambda { |config, column| column.extend(Column) } ]
7
- end
8
-
9
- # @see ActiveRecord::ConnectionAdapters::JdbcColumn
10
- module Column
11
-
12
- # @private
13
- def self.included(base)
14
- # NOTE: assumes a standalone DB2Column class
15
- class << base; include Cast; end
16
- end
17
-
18
- # @deprecated use `self.class.string_to_time`
19
- def self.cast_to_date_or_time(value)
20
- return value if value.is_a? Date
21
- return nil if value.blank?
22
- # https://github.com/jruby/activerecord-jdbc-adapter/commit/c225126e025df2e98ba3386c67e2a5bc5e5a73e6
23
- return Time.now if value =~ /^CURRENT/
24
- guess_date_or_time((value.is_a? Time) ? value : cast_to_time(value))
25
- rescue
26
- value
27
- end
28
-
29
- # @deprecated use `self.class.string_to_time` or `self.class.string_to_dummy_time`
30
- def self.cast_to_time(value)
31
- return value if value.is_a? Time
32
- # AS400 returns a 2 digit year, LUW returns a 4 digit year
33
- time = DateTime.parse(value).to_time rescue nil
34
- return nil unless time
35
- time_array = [time.year, time.month, time.day, time.hour, time.min, time.sec]
36
- time_array[0] ||= 2000; time_array[1] ||= 1; time_array[2] ||= 1;
37
- Time.send(ActiveRecord.default_timezone, *time_array) rescue nil
38
- end
39
-
40
- # @deprecated
41
- # @private
42
- def self.guess_date_or_time(value)
43
- return value if value.is_a? Date
44
- ( value && value.hour == 0 && value.min == 0 && value.sec == 0 ) ?
45
- Date.new(value.year, value.month, value.day) : value
46
- end
47
-
48
- # @override
49
- def type_cast(value)
50
- # AR5.2
51
- return super unless respond_to?(:type)
52
-
53
- return nil if value.nil? || value == 'NULL' || value =~ /^\s*NULL\s*$/i
54
- case type
55
- when :string then value
56
- when :integer then value.respond_to?(:to_i) ? value.to_i : (value ? 1 : 0)
57
- when :primary_key then value.respond_to?(:to_i) ? value.to_i : (value ? 1 : 0)
58
- when :float then value.to_f
59
- when :date then self.class.string_to_date(value)
60
- when :datetime then self.class.string_to_time(value)
61
- when :timestamp then self.class.string_to_time(value)
62
- when :time then self.class.string_to_dummy_time(value)
63
- # TODO AS400 stores binary strings in EBCDIC (CCSID 65535), need to convert back to ASCII
64
- else
65
- super
66
- end
67
- end
68
-
69
- # @override
70
- def type_cast_code(var_name)
71
- case type
72
- when :date then "#{self.class.name}.string_to_date(#{var_name})"
73
- when :datetime then "#{self.class.name}.string_to_time(#{var_name})"
74
- when :timestamp then "#{self.class.name}.string_to_time(#{var_name})"
75
- when :time then "#{self.class.name}.string_to_dummy_time(#{var_name})"
76
- else
77
- super
78
- end
79
- end
80
-
81
- private
82
-
83
- # Post process default value from JDBC into a Rails-friendly format (columns{-internal})
84
- def default_value(value)
85
- # IBM i (AS400) will return an empty string instead of null for no default
86
- return nil if value.blank?
87
-
88
- # string defaults are surrounded by single quotes
89
- return $1 if value =~ /^'(.*)'$/
90
-
91
- value
92
- end
93
-
94
- module Cast
95
-
96
- # @override
97
- def string_to_date(value)
98
- return nil unless value = current_date_time_parse(value)
99
-
100
- super
101
- end
102
-
103
- # @override
104
- def string_to_time(value)
105
- return nil unless value = current_date_time_parse(value)
106
-
107
- super
108
- end
109
-
110
- # @override
111
- def string_to_dummy_time(value)
112
- return nil unless value = current_date_time_parse(value)
113
-
114
- super
115
- end
116
-
117
- private
118
-
119
- def current_date_time_parse(value)
120
- return value unless value.is_a?(String)
121
- return nil if value.empty?
122
- return Time.now if value.index('CURRENT') == 0
123
-
124
- return value
125
- end
126
-
127
- end
128
-
129
- end
130
- end
131
- end
@@ -1,48 +0,0 @@
1
- ArJdbc::ConnectionMethods.module_eval do
2
- # @note Assumes DB2 driver (*db2jcc.jar*) is on class-path.
3
- def db2_connection(config)
4
- config[:adapter_spec] ||= ::ArJdbc::DB2
5
-
6
- return jndi_connection(config) if jndi_config?(config)
7
-
8
- config[:url] ||= begin
9
- if config[:host] # Type 4 URL: jdbc:db2://server:port/database
10
- config[:port] ||= 50000
11
- "jdbc:db2://#{config[:host]}:#{config[:port]}/#{config[:database]}"
12
- else # Type 2 URL: jdbc:db2:database
13
- "jdbc:db2:#{config[:database]}"
14
- end
15
- end
16
- config[:driver] ||= ::ArJdbc::DB2::DRIVER_NAME
17
- config[:connection_alive_sql] ||= 'SELECT 1 FROM syscat.tables FETCH FIRST 1 ROWS ONLY'
18
- config[:adapter_class] = ActiveRecord::ConnectionAdapters::DB2Adapter unless config.key?(:adapter_class)
19
-
20
- jdbc_connection(config)
21
- end
22
- alias_method :jdbcdb2_connection, :db2_connection
23
-
24
- # @note Assumes AS400 driver (*jt400.jar*) is on class-path.
25
- def as400_connection(config)
26
- config[:adapter_spec] ||= ::ArJdbc::AS400
27
-
28
- return jndi_connection(config) if config[:jndi]
29
-
30
- config[:url] ||= begin
31
- # jdbc:as400://[host]
32
- url = 'jdbc:as400://'
33
- url << config[:host] if config[:host]
34
- # jdbc:as400://myiSeries;database name=IASP1
35
- url << ";database name=#{config[:database]}" if config[:database]
36
- # jdbc:as400://[host];proxy server=HODServerName:proxyServerPort
37
- url << ";proxy server=#{config[:proxy]}" if config[:proxy]
38
- url
39
- end
40
- require 'arjdbc/db2/as400'
41
- config[:driver] ||= ::ArJdbc::AS400::DRIVER_NAME
42
- config[:connection_alive_sql] ||= 'SELECT 1 FROM sysibm.tables FETCH FIRST 1 ROWS ONLY'
43
- config[:adapter_class] = ActiveRecord::ConnectionAdapters::AS400Adapter unless config.key?(:adapter_class)
44
-
45
- jdbc_connection(config)
46
- end
47
- alias_method :jdbcas400_connection, :as400_connection
48
- end
data/lib/arjdbc/db2.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'arjdbc'
2
- require 'arjdbc/db2/adapter'
3
- require 'arjdbc/db2/connection_methods'
4
- ArJdbc.warn_unsupported_adapter 'db2', [4, 2] # warns on AR >= 4.2
@@ -1,13 +0,0 @@
1
- # Needed because Rails is broken wrt to quoting of some values.
2
- # Most databases are nice about it, but not Derby.
3
- # The real issue is that you can't compare a CHAR value to a NUMBER column.
4
- ActiveRecord::Associations::ClassMethods.module_eval do
5
- private
6
- def select_limited_ids_list(options, join_dependency)
7
- return super unless connection.is_a?(ArJdbc::Derby)
8
- connection.select_all(
9
- construct_finder_sql_for_association_limiting(options, join_dependency),
10
- "#{name} Load IDs For Limited Eager Loading"
11
- ).collect { |row| connection.quote(row[primary_key], columns_hash[primary_key]) }.join(", ")
12
- end
13
- end