activerecord-jdbc-adapter 5.0.pre1 → 51.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -2
- data/.travis.yml +15 -416
- data/Gemfile +35 -37
- data/README.md +23 -118
- data/RUNNING_TESTS.md +31 -26
- data/Rakefile +2 -3
- data/activerecord-jdbc-adapter.gemspec +1 -2
- data/lib/arjdbc/abstract/connection_management.rb +21 -0
- data/lib/arjdbc/abstract/core.rb +62 -0
- data/lib/arjdbc/abstract/database_statements.rb +46 -0
- data/lib/arjdbc/abstract/statement_cache.rb +58 -0
- data/lib/arjdbc/abstract/transaction_support.rb +86 -0
- data/lib/arjdbc/derby/adapter.rb +6 -1
- data/lib/arjdbc/discover.rb +0 -7
- data/lib/arjdbc/firebird/adapter.rb +2 -2
- data/lib/arjdbc/jdbc/adapter.rb +10 -252
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/connection.rb +6 -0
- data/lib/arjdbc/jdbc.rb +2 -2
- data/lib/arjdbc/mysql/adapter.rb +87 -944
- data/lib/arjdbc/mysql/connection_methods.rb +4 -2
- data/lib/arjdbc/postgresql/adapter.rb +288 -1023
- data/lib/arjdbc/postgresql/base/array_decoder.rb +26 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +25 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +8 -5
- data/lib/arjdbc/postgresql/column.rb +10 -599
- data/lib/arjdbc/postgresql/connection_methods.rb +9 -0
- data/lib/arjdbc/postgresql/name.rb +24 -0
- data/lib/arjdbc/postgresql/oid_types.rb +25 -110
- data/lib/arjdbc/sqlite3/adapter.rb +171 -170
- data/lib/arjdbc/tasks/database_tasks.rb +1 -3
- data/lib/arjdbc/tasks/db2_database_tasks.rb +2 -2
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +3 -3
- data/rakelib/02-test.rake +0 -12
- data/rakelib/compile.rake +1 -1
- data/rakelib/db.rake +7 -5
- data/rakelib/rails.rake +63 -64
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +1 -17
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +518 -1260
- data/src/java/arjdbc/mysql/MySQLModule.java +3 -3
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +53 -134
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +214 -240
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +0 -20
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +85 -10
- metadata +20 -34
- data/Appraisals +0 -41
- data/lib/active_record/connection_adapters/oracle_adapter.rb +0 -1
- data/lib/arjdbc/common_jdbc_methods.rb +0 -89
- data/lib/arjdbc/mysql/bulk_change_table.rb +0 -150
- data/lib/arjdbc/mysql/column.rb +0 -162
- data/lib/arjdbc/mysql/explain_support.rb +0 -82
- data/lib/arjdbc/mysql/schema_creation.rb +0 -58
- data/lib/arjdbc/oracle/adapter.rb +0 -952
- data/lib/arjdbc/oracle/column.rb +0 -126
- data/lib/arjdbc/oracle/connection_methods.rb +0 -21
- data/lib/arjdbc/oracle.rb +0 -4
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +0 -21
- data/lib/arjdbc/postgresql/base/oid.rb +0 -412
- data/lib/arjdbc/postgresql/base/schema_definitions.rb +0 -131
- data/lib/arjdbc/postgresql/explain_support.rb +0 -53
- data/lib/arjdbc/postgresql/oid/bytea.rb +0 -2
- data/lib/arjdbc/postgresql/schema_creation.rb +0 -60
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +0 -297
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +0 -65
- data/src/java/arjdbc/oracle/OracleModule.java +0 -75
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +0 -465
@@ -42,7 +42,16 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
42
42
|
properties['tcpKeepAlive'] ||= config[:keepalives] if config.key?(:keepalives)
|
43
43
|
properties['kerberosServerName'] ||= config[:krbsrvname] if config[:krbsrvname]
|
44
44
|
|
45
|
+
# If prepared statements are off, lets make sure they are really *off*
|
46
|
+
properties['prepareThreshold'] = 0 unless config[:prepared_statements]
|
47
|
+
|
45
48
|
jdbc_connection(config)
|
49
|
+
rescue ActiveRecord::JDBCError => e
|
50
|
+
if e.message.include?('does not exist')
|
51
|
+
raise ActiveRecord::NoDatabaseError, e.message
|
52
|
+
else
|
53
|
+
raise
|
54
|
+
end
|
46
55
|
end
|
47
56
|
alias_method :jdbcpostgresql_connection, :postgresql_connection
|
48
57
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# This patches the Name class so that it doesn't use pg gem specific quoting
|
2
|
+
module ActiveRecord
|
3
|
+
module ConnectionAdapters
|
4
|
+
module PostgreSQL
|
5
|
+
class Name
|
6
|
+
|
7
|
+
def quoted
|
8
|
+
if schema
|
9
|
+
"#{quote_identifier(schema)}#{SEPARATOR}#{quote_identifier(identifier)}"
|
10
|
+
else
|
11
|
+
quote_identifier(identifier)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def quote_identifier(name)
|
18
|
+
%("#{name.to_s.gsub("\"", "\"\"")}")
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -3,13 +3,7 @@ require 'thread'
|
|
3
3
|
module ArJdbc
|
4
4
|
module PostgreSQL
|
5
5
|
|
6
|
-
|
7
|
-
require 'active_record/connection_adapters/postgresql/oid'
|
8
|
-
require 'arjdbc/postgresql/oid/bytea.rb'
|
9
|
-
else
|
10
|
-
require 'arjdbc/postgresql/base/oid'
|
11
|
-
end
|
12
|
-
|
6
|
+
require 'active_record/connection_adapters/postgresql/oid'
|
13
7
|
require 'arjdbc/postgresql/base/pgconn'
|
14
8
|
|
15
9
|
def self.unescape_bytea(escaped)
|
@@ -22,6 +16,13 @@ module ArJdbc
|
|
22
16
|
# @private
|
23
17
|
module OIDTypes
|
24
18
|
|
19
|
+
# Support arrays/ranges for defining attributes that don't exist in the db
|
20
|
+
Type.add_modifier({ array: true }, OID::Array, adapter: :postgresql)
|
21
|
+
Type.add_modifier({ range: true }, OID::Range, adapter: :postgresql)
|
22
|
+
Type.register(:enum, OID::Enum, adapter: :postgresql)
|
23
|
+
Type.register(:point, OID::Point, adapter: :postgresql)
|
24
|
+
Type.register(:legacy_point, OID::LegacyPoint, adapter: :postgresql)
|
25
|
+
|
25
26
|
# @override
|
26
27
|
def enable_extension(name)
|
27
28
|
result = super(name)
|
@@ -47,14 +48,7 @@ module ArJdbc
|
|
47
48
|
def lookup_cast_type(sql_type)
|
48
49
|
oid = execute("SELECT #{quote(sql_type)}::regtype::oid", "SCHEMA")
|
49
50
|
super oid.first['oid'].to_i
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_oid_type(oid, fmod, column_name)
|
53
|
-
type_map.fetch(oid, fmod) {
|
54
|
-
warn "unknown OID #{oid}: failed to recognize type of '#{column_name}'. It will be treated as String."
|
55
|
-
type_map[oid] = OID::Identity.new
|
56
|
-
}
|
57
|
-
end unless AR42
|
51
|
+
end
|
58
52
|
|
59
53
|
def get_oid_type(oid, fmod, column_name, sql_type = '')
|
60
54
|
if !type_map.key?(oid)
|
@@ -67,40 +61,10 @@ module ArJdbc
|
|
67
61
|
type_map.register_type(oid, cast_type)
|
68
62
|
end
|
69
63
|
}
|
70
|
-
end if AR42
|
71
|
-
|
72
|
-
@@type_map_cache = {}
|
73
|
-
@@type_map_cache_lock = Mutex.new
|
74
|
-
|
75
|
-
if AR42
|
76
|
-
TypeMap = ActiveRecord::Type::HashLookupTypeMap
|
77
|
-
else
|
78
|
-
TypeMap = OID::TypeMap
|
79
|
-
end
|
80
|
-
|
81
|
-
# @see #type_map
|
82
|
-
# @private
|
83
|
-
TypeMap.class_eval do
|
84
|
-
def dup
|
85
|
-
dup = super # make sure @mapping is not shared
|
86
|
-
dup.instance_variable_set(:@mapping, @mapping.dup)
|
87
|
-
dup
|
88
|
-
end
|
89
64
|
end
|
90
65
|
|
91
66
|
def type_map
|
92
|
-
|
93
|
-
# ... since it's only used for `adapter.accessor`
|
94
|
-
@type_map ||= begin
|
95
|
-
if type_map = @@type_map_cache[ type_cache_key ]
|
96
|
-
type_map.dup
|
97
|
-
else
|
98
|
-
type_map = TypeMap.new
|
99
|
-
initialize_type_map(type_map)
|
100
|
-
cache_type_map(type_map)
|
101
|
-
type_map
|
102
|
-
end
|
103
|
-
end
|
67
|
+
@type_map
|
104
68
|
end
|
105
69
|
|
106
70
|
def reload_type_map
|
@@ -112,62 +76,11 @@ module ArJdbc
|
|
112
76
|
|
113
77
|
private
|
114
78
|
|
115
|
-
def cache_type_map(type_map)
|
116
|
-
@@type_map_cache_lock.synchronize do
|
117
|
-
@@type_map_cache[ type_cache_key ] = type_map
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def type_cache_key
|
122
|
-
config.hash + ( 7 * extensions.hash )
|
123
|
-
end
|
124
|
-
|
125
|
-
def add_oid(row, records_by_oid, type_map)
|
126
|
-
return type_map if type_map.key? row['type_elem'].to_i
|
127
|
-
|
128
|
-
if OID.registered_type? typname = row['typname']
|
129
|
-
# this composite type is explicitly registered
|
130
|
-
vector = OID::NAMES[ typname ]
|
131
|
-
else
|
132
|
-
# use the default for composite types
|
133
|
-
unless type_map.key? typelem = row['typelem'].to_i
|
134
|
-
add_oid records_by_oid[ row['typelem'] ], records_by_oid, type_map
|
135
|
-
end
|
136
|
-
|
137
|
-
vector = OID::Vector.new row['typdelim'], type_map[typelem]
|
138
|
-
end
|
139
|
-
|
140
|
-
type_map[ row['oid'].to_i ] = vector
|
141
|
-
type_map
|
142
|
-
end
|
143
|
-
|
144
|
-
def initialize_type_map(type_map)
|
145
|
-
result = execute('SELECT oid, typname, typelem, typdelim, typinput FROM pg_type', 'SCHEMA')
|
146
|
-
leaves, nodes = result.partition { |row| row['typelem'].to_s == '0' }
|
147
|
-
# populate the leaf nodes
|
148
|
-
leaves.find_all { |row| OID.registered_type? row['typname'] }.each do |row|
|
149
|
-
type_map[ row['oid'].to_i ] = OID::NAMES[ row['typname'] ]
|
150
|
-
end
|
151
|
-
|
152
|
-
records_by_oid = result.group_by { |row| row['oid'] }
|
153
|
-
|
154
|
-
arrays, nodes = nodes.partition { |row| row['typinput'] == 'array_in' }
|
155
|
-
|
156
|
-
# populate composite types
|
157
|
-
nodes.each { |row| add_oid row, records_by_oid, type_map }
|
158
|
-
|
159
|
-
# populate array types
|
160
|
-
arrays.find_all { |row| type_map.key? row['typelem'].to_i }.each do |row|
|
161
|
-
array = OID::Array.new type_map[ row['typelem'].to_i ]
|
162
|
-
type_map[ row['oid'].to_i ] = array
|
163
|
-
end
|
164
|
-
end unless AR42
|
165
|
-
|
166
79
|
def initialize_type_map(m)
|
167
80
|
register_class_with_limit m, 'int2', Type::Integer
|
168
81
|
register_class_with_limit m, 'int4', Type::Integer
|
169
82
|
register_class_with_limit m, 'int8', Type::Integer
|
170
|
-
m.
|
83
|
+
m.register_type 'oid', OID::Oid.new
|
171
84
|
m.register_type 'float4', Type::Float.new
|
172
85
|
m.alias_type 'float8', 'float4'
|
173
86
|
m.register_type 'text', Type::Text.new
|
@@ -192,19 +105,21 @@ module ArJdbc
|
|
192
105
|
m.register_type 'inet', OID::Inet.new
|
193
106
|
m.register_type 'uuid', OID::Uuid.new
|
194
107
|
m.register_type 'xml', OID::Xml.new
|
195
|
-
m.register_type '
|
196
|
-
m.register_type '
|
108
|
+
m.register_type 'box', OID::SpecializedString.new(:box)
|
109
|
+
m.register_type 'circle', OID::SpecializedString.new(:circle)
|
197
110
|
m.register_type 'citext', OID::SpecializedString.new(:citext)
|
111
|
+
m.register_type 'line', OID::SpecializedString.new(:line)
|
112
|
+
m.register_type 'lseg', OID::SpecializedString.new(:lseg)
|
198
113
|
m.register_type 'ltree', OID::SpecializedString.new(:ltree)
|
114
|
+
m.register_type 'macaddr', OID::SpecializedString.new(:macaddr)
|
115
|
+
m.register_type 'path', OID::SpecializedString.new(:path)
|
116
|
+
m.register_type 'polygon', OID::SpecializedString.new(:polygon)
|
117
|
+
m.register_type 'tsvector', OID::SpecializedString.new(:tsvector)
|
199
118
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
m.alias_type 'polygon', 'varchar'
|
205
|
-
m.alias_type 'circle', 'varchar'
|
206
|
-
m.alias_type 'lseg', 'varchar'
|
207
|
-
m.alias_type 'box', 'varchar'
|
119
|
+
m.register_type 'interval' do |_, _, sql_type|
|
120
|
+
precision = extract_precision(sql_type)
|
121
|
+
OID::SpecializedString.new(:interval, precision: precision)
|
122
|
+
end
|
208
123
|
|
209
124
|
m.register_type 'timestamp' do |_, _, sql_type|
|
210
125
|
precision = extract_precision(sql_type)
|
@@ -232,7 +147,7 @@ module ArJdbc
|
|
232
147
|
end
|
233
148
|
|
234
149
|
load_additional_types(m)
|
235
|
-
end
|
150
|
+
end
|
236
151
|
|
237
152
|
def load_additional_types(type_map, oids = nil)
|
238
153
|
if supports_ranges?
|
@@ -261,7 +176,7 @@ module ArJdbc
|
|
261
176
|
|
262
177
|
records = execute(query, 'SCHEMA')
|
263
178
|
initializer.run(records)
|
264
|
-
end
|
179
|
+
end
|
265
180
|
|
266
181
|
end
|
267
182
|
end
|