activerecord-postgis-adapter 0.6.6 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.rdoc +7 -0
- data/{lib/rgeo/active_record/postgis_adapter/railtie.rb → LICENSE.txt} +2 -12
- data/lib/active_record/connection_adapters/postgis_adapter.rb +1 -60
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/create_connection.rb +15 -74
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/databases.rake +0 -38
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/main_adapter.rb +0 -68
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/postgis_database_tasks.rb +0 -36
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_column.rb +0 -36
- data/lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb +0 -36
- data/lib/active_record/connection_adapters/postgis_adapter/railtie.rb +0 -36
- data/lib/active_record/connection_adapters/postgis_adapter/shared/arel_tosql.rb +0 -36
- data/lib/active_record/connection_adapters/postgis_adapter/shared/common_adapter_methods.rb +3 -70
- data/lib/active_record/connection_adapters/postgis_adapter/shared/railtie.rb +1 -54
- data/lib/active_record/connection_adapters/postgis_adapter/shared/setup.rb +0 -36
- data/lib/active_record/connection_adapters/postgis_adapter/version.rb +7 -0
- data/lib/activerecord-postgis-adapter.rb +0 -36
- data/lib/activerecord/postgis/adapter.rb +0 -36
- data/test/database.yml +5 -0
- data/test/tc_basic.rb +0 -35
- data/test/tc_ddl.rb +0 -35
- data/test/tc_nested_class.rb +0 -35
- data/test/tc_spatial_queries.rb +0 -35
- data/test/tc_tasks.rb +0 -78
- metadata +33 -38
- data/Version +0 -1
- data/lib/active_record/connection_adapters/postgis_adapter/rails3/create_connection.rb +0 -96
- data/lib/active_record/connection_adapters/postgis_adapter/rails3/databases.rake +0 -232
- data/lib/active_record/connection_adapters/postgis_adapter/rails3/main_adapter.rb +0 -298
- data/lib/active_record/connection_adapters/postgis_adapter/rails3/spatial_column.rb +0 -195
- data/lib/active_record/connection_adapters/postgis_adapter/rails3/spatial_table_definition.rb +0 -145
- data/lib/active_record/connection_adapters/postgis_adapter/shared/jdbc_compat.rb +0 -134
- data/lib/active_record/connection_adapters/postgis_adapter/shared/version.rb +0 -62
@@ -1,195 +0,0 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# PostGIS adapter for ActiveRecord
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
;
|
35
|
-
|
36
|
-
|
37
|
-
module ActiveRecord # :nodoc:
|
38
|
-
|
39
|
-
module ConnectionAdapters # :nodoc:
|
40
|
-
|
41
|
-
module PostGISAdapter # :nodoc:
|
42
|
-
|
43
|
-
|
44
|
-
class SpatialColumn < ConnectionAdapters::PostgreSQLColumn # :nodoc:
|
45
|
-
|
46
|
-
|
47
|
-
FACTORY_SETTINGS_CACHE = {}
|
48
|
-
|
49
|
-
|
50
|
-
def initialize(name_, default_, sql_type_=nil, null_=true, opts_={})
|
51
|
-
@factory_settings = opts_.delete(:factory_settings)
|
52
|
-
@table_name = opts_.delete(:table_name)
|
53
|
-
@geographic = sql_type_ =~ /geography/i ? true : false
|
54
|
-
if opts_.length > 0
|
55
|
-
# This case comes from an entry in the geometry_columns table
|
56
|
-
@geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name(opts_[:type]) ||
|
57
|
-
::RGeo::Feature::Geometry
|
58
|
-
@srid = opts_[:srid].to_i
|
59
|
-
@has_z = opts_[:has_z] ? true : false
|
60
|
-
@has_m = opts_[:has_m] ? true : false
|
61
|
-
elsif @geographic
|
62
|
-
# Geographic type information is embedded in the SQL type
|
63
|
-
@geometric_type = ::RGeo::Feature::Geometry
|
64
|
-
@srid = 4326
|
65
|
-
@has_z = @has_m = false
|
66
|
-
if sql_type_ =~ /geography\((.*)\)$/i
|
67
|
-
params_ = $1.split(',')
|
68
|
-
if params_.size >= 2
|
69
|
-
if params_.first =~ /([a-z]+[^zm])(z?)(m?)/i
|
70
|
-
@has_z = $2.length > 0
|
71
|
-
@has_m = $3.length > 0
|
72
|
-
@geometric_type = ::RGeo::ActiveRecord.geometric_type_from_name($1)
|
73
|
-
end
|
74
|
-
if params_.last =~ /(\d+)/
|
75
|
-
@srid = $1.to_i
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
elsif sql_type_ =~ /geography|geometry|point|linestring|polygon/i
|
80
|
-
# Just in case there is a geometry column with no geometry_columns entry.
|
81
|
-
@geometric_type = ::RGeo::Feature::Geometry
|
82
|
-
@srid = @has_z = @has_m = nil
|
83
|
-
else
|
84
|
-
# Non-spatial column
|
85
|
-
@geometric_type = @has_z = @has_m = @srid = nil
|
86
|
-
end
|
87
|
-
super(name_, default_, sql_type_, null_)
|
88
|
-
if type == :spatial
|
89
|
-
if @srid
|
90
|
-
@limit = {:srid => @srid, :type => @geometric_type.type_name.underscore}
|
91
|
-
@limit[:has_z] = true if @has_z
|
92
|
-
@limit[:has_m] = true if @has_m
|
93
|
-
@limit[:geographic] = true if @geographic
|
94
|
-
else
|
95
|
-
@limit = {:no_constraints => true}
|
96
|
-
end
|
97
|
-
end
|
98
|
-
FACTORY_SETTINGS_CACHE[@factory_settings.object_id] = @factory_settings
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
attr_reader :geographic
|
103
|
-
attr_reader :srid
|
104
|
-
attr_reader :geometric_type
|
105
|
-
attr_reader :has_z
|
106
|
-
attr_reader :has_m
|
107
|
-
|
108
|
-
alias_method :geographic?, :geographic
|
109
|
-
alias_method :has_z?, :has_z
|
110
|
-
alias_method :has_m?, :has_m
|
111
|
-
|
112
|
-
|
113
|
-
def spatial?
|
114
|
-
type == :spatial
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
def has_spatial_constraints?
|
119
|
-
!@srid.nil?
|
120
|
-
end
|
121
|
-
|
122
|
-
|
123
|
-
def klass
|
124
|
-
type == :spatial ? ::RGeo::Feature::Geometry : super
|
125
|
-
end
|
126
|
-
|
127
|
-
|
128
|
-
def type_cast(value_)
|
129
|
-
if type == :spatial
|
130
|
-
SpatialColumn.convert_to_geometry(value_, @factory_settings, @table_name, name,
|
131
|
-
@geographic, @srid, @has_z, @has_m)
|
132
|
-
else
|
133
|
-
super
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
|
138
|
-
def type_cast_code(var_name_)
|
139
|
-
if type == :spatial
|
140
|
-
"::ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumn.convert_to_geometry("+
|
141
|
-
"#{var_name_}, ::ActiveRecord::ConnectionAdapters::PostGISAdapter::SpatialColumn::"+
|
142
|
-
"FACTORY_SETTINGS_CACHE[#{@factory_settings.object_id}], #{@table_name.inspect}, "+
|
143
|
-
"#{name.inspect}, #{@geographic ? 'true' : 'false'}, #{@srid.inspect}, "+
|
144
|
-
"#{@has_z ? 'true' : 'false'}, #{@has_m ? 'true' : 'false'})"
|
145
|
-
else
|
146
|
-
super
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
|
151
|
-
private
|
152
|
-
|
153
|
-
|
154
|
-
def simplified_type(sql_type_)
|
155
|
-
sql_type_ =~ /geography|geometry|point|linestring|polygon/i ? :spatial : super
|
156
|
-
end
|
157
|
-
|
158
|
-
|
159
|
-
def self.convert_to_geometry(input_, factory_settings_, table_name_, column_, geographic_, srid_, has_z_, has_m_)
|
160
|
-
if srid_
|
161
|
-
constraints_ = {:geographic => geographic_, :has_z_coordinate => has_z_,
|
162
|
-
:has_m_coordinate => has_m_, :srid => srid_}
|
163
|
-
else
|
164
|
-
constraints_ = nil
|
165
|
-
end
|
166
|
-
if ::RGeo::Feature::Geometry === input_
|
167
|
-
factory_ = factory_settings_.get_column_factory(table_name_, column_, constraints_)
|
168
|
-
::RGeo::Feature.cast(input_, factory_) rescue nil
|
169
|
-
elsif input_.respond_to?(:to_str)
|
170
|
-
input_ = input_.to_str
|
171
|
-
if input_.length == 0
|
172
|
-
nil
|
173
|
-
else
|
174
|
-
factory_ = factory_settings_.get_column_factory(table_name_, column_, constraints_)
|
175
|
-
marker_ = input_[0,1]
|
176
|
-
if marker_ == "\x00" || marker_ == "\x01" || input_[0,4] =~ /[0-9a-fA-F]{4}/
|
177
|
-
::RGeo::WKRep::WKBParser.new(factory_, :support_ewkb => true).parse(input_) rescue nil
|
178
|
-
else
|
179
|
-
::RGeo::WKRep::WKTParser.new(factory_, :support_ewkt => true).parse(input_) rescue nil
|
180
|
-
end
|
181
|
-
end
|
182
|
-
else
|
183
|
-
nil
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
end
|
189
|
-
|
190
|
-
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|
194
|
-
|
195
|
-
end
|
data/lib/active_record/connection_adapters/postgis_adapter/rails3/spatial_table_definition.rb
DELETED
@@ -1,145 +0,0 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# PostGIS adapter for ActiveRecord
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
;
|
35
|
-
|
36
|
-
|
37
|
-
module ActiveRecord # :nodoc:
|
38
|
-
|
39
|
-
module ConnectionAdapters # :nodoc:
|
40
|
-
|
41
|
-
module PostGISAdapter # :nodoc:
|
42
|
-
|
43
|
-
TableDefinitionSuperclass = if defined?(ConnectionAdapters::PostgreSQLAdapter::TableDefinition)
|
44
|
-
ConnectionAdapters::PostgreSQLAdapter::TableDefinition
|
45
|
-
else
|
46
|
-
ConnectionAdapters::TableDefinition
|
47
|
-
end
|
48
|
-
|
49
|
-
class SpatialTableDefinition < TableDefinitionSuperclass # :nodoc:
|
50
|
-
|
51
|
-
def column(name_, type_, options_={})
|
52
|
-
if (info_ = @base.spatial_column_constructor(type_.to_sym))
|
53
|
-
type_ = options_[:type] || info_[:type] || type_
|
54
|
-
if type_.to_s == 'geometry' &&
|
55
|
-
(options_[:no_constraints] ||
|
56
|
-
options_[:limit].is_a?(::Hash) && options_[:limit][:no_constraints])
|
57
|
-
then
|
58
|
-
options_.delete(:limit)
|
59
|
-
else
|
60
|
-
options_[:type] = type_
|
61
|
-
type_ = :spatial
|
62
|
-
end
|
63
|
-
end
|
64
|
-
super(name_, type_, options_)
|
65
|
-
if type_ == :spatial
|
66
|
-
col_ = self[name_]
|
67
|
-
col_.extend(SpatialColumnDefinitionMethods) unless col_.respond_to?(:geographic?)
|
68
|
-
options_.merge!(col_.limit) if col_.limit.is_a?(::Hash)
|
69
|
-
col_.set_spatial_type(options_[:type])
|
70
|
-
col_.set_geographic(options_[:geographic])
|
71
|
-
col_.set_srid(options_[:srid])
|
72
|
-
col_.set_has_z(options_[:has_z])
|
73
|
-
col_.set_has_m(options_[:has_m])
|
74
|
-
end
|
75
|
-
self
|
76
|
-
end
|
77
|
-
|
78
|
-
def to_sql
|
79
|
-
@columns.find_all{ |c_| !c_.respond_to?(:geographic?) || c_.geographic? }.map{ |c_| c_.to_sql } * ', '
|
80
|
-
end
|
81
|
-
|
82
|
-
def non_geographic_spatial_columns
|
83
|
-
@columns.find_all{ |c_| c_.respond_to?(:geographic?) && !c_.geographic? }
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
|
89
|
-
module SpatialColumnDefinitionMethods # :nodoc:
|
90
|
-
|
91
|
-
def spatial_type
|
92
|
-
@spatial_type
|
93
|
-
end
|
94
|
-
|
95
|
-
def geographic?
|
96
|
-
@geographic
|
97
|
-
end
|
98
|
-
|
99
|
-
def srid
|
100
|
-
@srid ? @srid.to_i : (geographic? ? 4326 : -1)
|
101
|
-
end
|
102
|
-
|
103
|
-
def has_z?
|
104
|
-
@has_z
|
105
|
-
end
|
106
|
-
|
107
|
-
def has_m?
|
108
|
-
@has_m
|
109
|
-
end
|
110
|
-
|
111
|
-
def set_geographic(value_)
|
112
|
-
@geographic = value_ ? true : false
|
113
|
-
end
|
114
|
-
|
115
|
-
def set_spatial_type(value_)
|
116
|
-
@spatial_type = value_.to_s
|
117
|
-
end
|
118
|
-
|
119
|
-
def set_srid(value_)
|
120
|
-
@srid = value_
|
121
|
-
end
|
122
|
-
|
123
|
-
def set_has_z(value_)
|
124
|
-
@has_z = value_ ? true : false
|
125
|
-
end
|
126
|
-
|
127
|
-
def set_has_m(value_)
|
128
|
-
@has_m = value_ ? true : false
|
129
|
-
end
|
130
|
-
|
131
|
-
def sql_type
|
132
|
-
type_ = spatial_type.upcase.gsub('_', '')
|
133
|
-
type_ << 'Z' if has_z?
|
134
|
-
type_ << 'M' if has_m?
|
135
|
-
"GEOGRAPHY(#{type_},#{srid})"
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
|
-
|
141
|
-
end
|
142
|
-
|
143
|
-
end
|
144
|
-
|
145
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
# -----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# PostGIS adapter for ActiveRecord
|
4
|
-
#
|
5
|
-
# -----------------------------------------------------------------------------
|
6
|
-
# Copyright 2010-2012 Daniel Azuma
|
7
|
-
#
|
8
|
-
# All rights reserved.
|
9
|
-
#
|
10
|
-
# Redistribution and use in source and binary forms, with or without
|
11
|
-
# modification, are permitted provided that the following conditions are met:
|
12
|
-
#
|
13
|
-
# * Redistributions of source code must retain the above copyright notice,
|
14
|
-
# this list of conditions and the following disclaimer.
|
15
|
-
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
-
# this list of conditions and the following disclaimer in the documentation
|
17
|
-
# and/or other materials provided with the distribution.
|
18
|
-
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
-
# contributors to this software, may be used to endorse or promote products
|
20
|
-
# derived from this software without specific prior written permission.
|
21
|
-
#
|
22
|
-
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
-
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
-
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
-
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
-
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
-
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
-
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
-
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
-
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
-
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
-
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
-
# -----------------------------------------------------------------------------
|
34
|
-
;
|
35
|
-
|
36
|
-
|
37
|
-
module ActiveRecord # :nodoc:
|
38
|
-
|
39
|
-
module ConnectionAdapters # :nodoc:
|
40
|
-
|
41
|
-
|
42
|
-
# Extend JDBC's PostgreSQLAdapter implementation for compatibility with
|
43
|
-
# ActiveRecord's default PostgreSQLAdapter.
|
44
|
-
|
45
|
-
class PostgreSQLAdapter # :nodoc:
|
46
|
-
|
47
|
-
|
48
|
-
# Add `query` method for compatibility
|
49
|
-
|
50
|
-
def query(*args)
|
51
|
-
select_rows(*args)
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
# Backport from master, so PostGIS adapater will work with current stable
|
56
|
-
# activerecord-jdbc-adapter gem.
|
57
|
-
#
|
58
|
-
# https://github.com/jruby/activerecord-jdbc-adapter/pull/200
|
59
|
-
|
60
|
-
unless method_defined?(:schema_search_path=)
|
61
|
-
def schema_search_path=(schema_csv)
|
62
|
-
if schema_csv
|
63
|
-
execute "SET search_path TO #{schema_csv}"
|
64
|
-
@schema_search_path = schema_csv
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
# Backport from master, so PostGIS adapater will work with current stable
|
71
|
-
# activerecord-jdbc-adapter gem.
|
72
|
-
#
|
73
|
-
# https://github.com/jruby/activerecord-jdbc-adapter/pull/200
|
74
|
-
|
75
|
-
unless method_defined?(:schema_search_path)
|
76
|
-
# Returns the active schema search path.
|
77
|
-
def schema_search_path
|
78
|
-
@schema_search_path ||= exec_query('SHOW search_path', 'SCHEMA')[0]['search_path']
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
# For ActiveRecord 3.1 compatibility under activerecord-jdbc-adapter
|
84
|
-
# 1.2.x: Add the "postgis" adapter to the matcher of jdbc-like adapters.
|
85
|
-
if(defined?(ArJdbc::Version::VERSION) && ArJdbc::Version::VERSION.to_f < 1.3)
|
86
|
-
def self.visitor_for(pool)
|
87
|
-
config = pool.spec.config
|
88
|
-
adapter = config[:adapter]
|
89
|
-
adapter_spec = config[:adapter_spec] || self
|
90
|
-
if adapter =~ /^(jdbc|jndi|postgis)$/
|
91
|
-
adapter_spec.arel2_visitors(config).values.first.new(pool)
|
92
|
-
else
|
93
|
-
adapter_spec.arel2_visitors(config)[adapter].new(pool)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
|
102
|
-
module PostGISAdapter # :nodoc:
|
103
|
-
|
104
|
-
|
105
|
-
# Based on the default <tt>postgresql_connection</tt> definition from
|
106
|
-
# activerecord-jdbc-adapter
|
107
|
-
|
108
|
-
def self.create_jdbc_connection(context_, config_)
|
109
|
-
begin
|
110
|
-
require 'jdbc/postgres'
|
111
|
-
::Jdbc::Postgres.load_driver(:require) if defined?(::Jdbc::Postgres.load_driver)
|
112
|
-
rescue LoadError # assuming driver.jar is on the class-path
|
113
|
-
end
|
114
|
-
require "arjdbc/postgresql"
|
115
|
-
config_[:username] ||= ::Java::JavaLang::System.get_property("user.name")
|
116
|
-
config_[:host] ||= "localhost"
|
117
|
-
config_[:port] ||= 5432
|
118
|
-
config_[:url] ||= "jdbc:postgresql://#{config_[:host]}:#{config_[:port]}/#{config_[:database]}"
|
119
|
-
config_[:url] << config_[:pg_params] if config_[:pg_params]
|
120
|
-
config_[:driver] ||= defined?(::Jdbc::Postgres.driver_name) ? ::Jdbc::Postgres.driver_name : 'org.postgresql.Driver'
|
121
|
-
config_[:adapter_class] = ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter
|
122
|
-
config_[:adapter_spec] = ::ArJdbc::PostgreSQL
|
123
|
-
conn_ = context_.jdbc_connection(config_)
|
124
|
-
conn_.execute("SET SEARCH_PATH TO #{config_[:schema_search_path]}") if config_[:schema_search_path]
|
125
|
-
conn_
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|