activerecord-jdbcnuodb-adapter 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: !binary |-
4
+ YjQyNTYyZWU5MjBmN2M5NGVhOWU2ZjVjYmJlY2M4ZjhmZDZhNGM4OQ==
5
+ data.tar.gz: !binary |-
6
+ NGRmZmI2ZmM2ZjBlODY0MmM0ODViYWFlMjdjNjIxNjRmZDc2OGMyNg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjVlMGM1ODc2ODJkZjYxNTg2ZTdmYjdhY2M3YTQwZWRhYzc4MWY5ZjRhYTY1
10
+ Zjk5YTk1MDEzNTJlMWI3MjM0NWFmNDNlYjg1OWI0NzZkOTY2YWMzODg3NDlh
11
+ YzI4ODk5MTBiNDJhZDI2ZWE2MjZiNDViZWQyYjg0M2MwMjMwZWE=
12
+ data.tar.gz: !binary |-
13
+ ZWQ4ZDNjMTJhN2U2YWU2NDI2MTAwNmExYjFkMDA4YjkxYWRlMjU1MWNkMWFk
14
+ MWM2YmU1OTI4YmM5MWZiZmVjZWY4ZjJjMjU4YmM3N2E0MDlhZTQ2MTc4OTMx
15
+ MzNjNjBlNGUzMWQ4NTcyNzMwOGY0MmQzNjA1YjNjNDI5MzhlMjI=
data/.travis.yml CHANGED
@@ -2,6 +2,8 @@ language: ruby
2
2
 
3
3
  rvm:
4
4
  - jruby-head
5
+ - jruby-18mode
6
+ - jruby-19mode
5
7
 
6
8
  env:
7
9
  - NUODB_ROOT=/opt/nuodb
@@ -16,7 +18,11 @@ before_script:
16
18
  - sudo dpkg -i /var/tmp/nuodb.deb
17
19
 
18
20
  script:
19
- - NUODB_ROOT=/opt/nuodb bundle exec rake test install
21
+ - jruby -S gem update --system
22
+ - jruby -S bundle install
23
+ - jruby -S gem list
24
+ - NUODB_ROOT=/opt/nuodb jruby -S bundle exec rake build install
25
+ - jruby -S gem list
20
26
 
21
27
  after_script:
22
28
  - sudo dpkg -r nuodb
data/README.rdoc CHANGED
@@ -13,16 +13,106 @@ An ActiveRecord JDBC Adapter for NuoDB.
13
13
  1. Include NuoDB information in the database.yml file as:
14
14
 
15
15
  development:
16
- adapter: nuodb
17
- database: test
18
- username: cloud
19
- password: user
20
- schema: test
16
+ adapter: nuodb
17
+ database: development
18
+ schema: test
19
+ username: cloud
20
+ password: user
21
+
22
+ test:
23
+ adapter: nuodb
24
+ database: development
25
+ schema: test
26
+ username: cloud
27
+ password: user
28
+
29
+ production:
30
+ adapter: nuodb
31
+ database: development
32
+ schema: test
33
+ username: cloud
34
+ password: user
21
35
 
22
36
  2. In the Gemfile, call the nuodb gem with:
23
37
 
24
38
  jruby -S gem 'activerecord-jdbcnuodb-adapter'
25
39
 
40
+ 3. Optionally integrate rake db:test tasks (see below).
41
+
42
+ ===SUPPORTING RAILS DB MIGRATE TASKS
43
+
44
+ We are making the driver compliant with the rake task interfaces in the :db namespace.
45
+ You can now use standard rake tasks for just about everything except for creating the
46
+ actual databases.
47
+
48
+ The only problem is that the rails tasks themselves are not open or extensible in a
49
+ manner that a driver can extend. As such there are a few integration points necessary
50
+ on the application side of the house; this section details them.
51
+
52
+ Place the following content in your lib/override_task.rb file:
53
+
54
+ Rake::TaskManager.class_eval do
55
+ def alias_task(fq_name)
56
+ new_name = "#{fq_name}:original"
57
+ @tasks[new_name] = @tasks.delete(fq_name)
58
+ end
59
+ end
60
+
61
+ def alias_task(fq_name)
62
+ Rake.application.alias_task(fq_name)
63
+ end
64
+
65
+ def alias_task_chain(*args, &block)
66
+ name, params, deps = Rake.application.resolve_args(args.dup)
67
+ fq_name = Rake.application.instance_variable_get(:@scope).dup.push(name).join(':')
68
+ alias_task(fq_name)
69
+ Rake::Task.define_task(*args, &block)
70
+ end
71
+
72
+ Then in your lib/tasks/databases.rake script add the following content:
73
+
74
+ require 'override_task'
75
+
76
+ namespace :db do
77
+
78
+ namespace :structure do
79
+
80
+ alias_task_chain :dump => :environment do
81
+ if ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'nuodb'
82
+ puts 'Task db:structure:dump skipped for NuoDB.'
83
+ else
84
+ Rake::Task['db:structure:dump:original'].execute
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ namespace :test do
91
+
92
+ alias_task_chain :purge => [:environment, :load_config] do
93
+ if ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'nuodb'
94
+ ActiveRecord::Base.establish_connection(:test)
95
+ ActiveRecord::Base.connection.execute("drop schema #{ActiveRecord::Base.configurations[Rails.env]['schema']} cascade;")
96
+ else
97
+ Rake::Task['db:test:purge:original'].execute
98
+ end
99
+ end
100
+
101
+ alias_task_chain :clone_structure => 'db:structure:dump' do
102
+ if ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'nuodb'
103
+ puts 'Task db:structure:clone_structure skipped for NuoDB.'
104
+ else
105
+ Rake::Task['db:test:clone_structure:original'].execute
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+
113
+ With these changes to your Rails application you will be able to run
114
+ db:test:prepare tasks or similar.
115
+
26
116
  == ENVIRONMENT SETUP
27
117
 
28
118
  === MAC
@@ -48,11 +138,11 @@ To compile and test run this command:
48
138
 
49
139
  == INSTALLING THE GEM
50
140
 
51
- jruby -S gem install activerecord-jdbcnuodb-adapter-1.0.1.gem
141
+ jruby -S gem install activerecord-jdbcnuodb-adapter-1.0.2.gem
52
142
 
53
143
  Or from the source tree:
54
144
 
55
- jruby -S gem install pkg/activerecord-jdbcnuodb-adapter-1.0.1.gem
145
+ jruby -S gem install pkg/activerecord-jdbcnuodb-adapter-1.0.2.gem
56
146
 
57
147
  == TESTING THE GEM
58
148
 
@@ -79,7 +169,7 @@ Run the tests:
79
169
 
80
170
  jruby -S gem install rails
81
171
  jruby -S gem install jdbc-nuodb-1.0.1.gem
82
- jruby -S gem install activerecord-jdbcnuodb-adapter-1.0.1.gem
172
+ jruby -S gem install activerecord-jdbcnuodb-adapter-1.0.2.gem
83
173
 
84
174
  2. Verify the gems are installed:
85
175
 
@@ -96,26 +186,26 @@ Run the tests:
96
186
 
97
187
  Tag the product using tags per the SemVer specification; our tags have a v-prefix:
98
188
 
99
- git tag -a v1.0.1 -m "SemVer Version: v1.0.1"
189
+ git tag -a v1.0.2 -m "SemVer Version: v1.0.2"
100
190
  git push --tags
101
191
 
102
192
  If you make a mistake, take it back quickly:
103
193
 
104
- git tag -d v1.0.1
105
- git push origin :refs/tags/v1.0.1
194
+ git tag -d v1.0.2
195
+ git push origin :refs/tags/v1.0.2
106
196
 
107
197
  ===PUBLISHING
108
198
 
109
199
  Here are the commands used to publish:
110
200
 
111
- gem push pkg/activerecord-jdbcnuodb-adapter-1.0.1.gem
201
+ gem push pkg/activerecord-jdbcnuodb-adapter-1.0.2.gem
112
202
 
113
203
  == INSPECTING THE GEM
114
204
 
115
205
  It is often useful to inspect the contents of a Gem before distribution.
116
206
  To do this you dump the contents of a gem thus:
117
207
 
118
- gem unpack pkg/activerecord-jdbcnuodb-adapter-1.0.1.gem
208
+ gem unpack pkg/activerecord-jdbcnuodb-adapter-1.0.2.gem
119
209
 
120
210
  == REFERENCES
121
211
 
@@ -1,5 +1,5 @@
1
1
  module ArJdbc
2
2
  module NuoDB
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
@@ -1,7 +1,7 @@
1
1
  module Arel
2
2
  module Visitors
3
3
  class NuoDB < Arel::Visitors::ToSql
4
- def visit_Arel_Nodes_SelectStatement o
4
+ def visit_Arel_Nodes_SelectStatement(o)
5
5
  [
6
6
  (visit(o.with) if o.with),
7
7
  o.cores.map { |x| visit_Arel_Nodes_SelectCore x }.join,
@@ -12,7 +12,7 @@ module Arel
12
12
  ].compact.join ' '
13
13
  end
14
14
 
15
- def visit_Arel_Nodes_Limit o
15
+ def visit_Arel_Nodes_Limit(o)
16
16
  "FETCH FIRST #{visit o.expr} ROWS ONLY"
17
17
  end
18
18
  end
@@ -16,10 +16,17 @@ module ::ArJdbc
16
16
 
17
17
  module ColumnExtensions
18
18
 
19
+ # Maps NuoDB types to logical rails types.
19
20
  def simplified_type(field_type)
20
21
  case field_type
21
22
  when /bit/i then
22
23
  :boolean
24
+ when /timestamp/i then
25
+ :timestamp
26
+ when /time/i then
27
+ :time
28
+ when /date/i then
29
+ :date
23
30
  else
24
31
  super
25
32
  end
@@ -49,7 +56,7 @@ module ::ArJdbc
49
56
  :binary => {:name => 'binary'},
50
57
  :boolean => {:name => 'boolean'},
51
58
  :date => {:name => 'date'},
52
- :datetime => {:name => 'datetime'},
59
+ :datetime => {:name => 'timestamp'},
53
60
  :decimal => {:name => 'decimal'},
54
61
  :float => {:name => 'float', :limit => 8},
55
62
  :integer => {:name => 'integer'},
@@ -63,6 +70,7 @@ module ::ArJdbc
63
70
  :numeric => {:name => 'numeric(20)'},
64
71
  }
65
72
 
73
+ # Maps logical rails types to NuoDB types.
66
74
  def native_database_types
67
75
  NATIVE_DATABASE_TYPES
68
76
  end
@@ -98,14 +106,25 @@ module ::ArJdbc
98
106
  def modify_types(tp)
99
107
  tp[:primary_key] = 'int not null generated always primary key'
100
108
  tp[:boolean] = {:name => 'boolean'}
101
- tp[:integer] = {:name => 'int', :limit => 4}
109
+ tp[:date] = {:name => 'date', :limit => nil}
110
+ tp[:datetime] = {:name => 'timestamp', :limit => nil}
102
111
  tp[:decimal] = {:name => 'decimal'}
112
+ tp[:integer] = {:name => 'int', :limit => 4}
103
113
  tp[:string] = {:name => 'string'}
104
- tp[:timestamp] = {:name => 'datetime'}
105
- tp[:datetime][:limit] = nil
114
+ tp[:time] = {:name => 'time', :limit => nil}
115
+ tp[:timestamp] = {:name => 'timestamp', :limit => nil}
106
116
  tp
107
117
  end
108
118
 
119
+ protected
120
+
121
+ def translate_exception(exception, message)
122
+ # future translations here...
123
+ super
124
+ end
125
+
126
+ public
127
+
109
128
  # QUOTING ================================================================
110
129
 
111
130
  def quote(value, column = nil)
@@ -171,6 +190,28 @@ module ::ArJdbc
171
190
  else
172
191
  raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
173
192
  end
193
+ when 'timestamp'
194
+ column_type_sql = 'timestamp'
195
+ unless precision.nil?
196
+ case precision
197
+ when 0..9
198
+ column_type_sql << "(#{precision})"
199
+ else
200
+ nil
201
+ end
202
+ end
203
+ column_type_sql
204
+ when 'time'
205
+ column_type_sql = 'time'
206
+ unless precision.nil?
207
+ case precision
208
+ when 0..9
209
+ column_type_sql << "(#{precision})"
210
+ else
211
+ nil
212
+ end
213
+ end
214
+ column_type_sql
174
215
  else
175
216
  super
176
217
  end
@@ -184,6 +225,19 @@ module ::ArJdbc
184
225
  raise NotImplementedError, "rename_table is not implemented"
185
226
  end
186
227
 
228
+ def recreate_database(name, options = {}) #:nodoc:
229
+ drop_database(name)
230
+ create_database(name, options)
231
+ end
232
+
233
+ def create_database(name, options = {}) #:nodoc:
234
+ puts "create_database"
235
+ end
236
+
237
+ def drop_database(name) #:nodoc:
238
+ puts "drop_database"
239
+ end
240
+
187
241
  # DATABASE STATEMENTS ====================================================
188
242
 
189
243
  def exec_insert(sql, name, binds)
@@ -191,6 +245,26 @@ module ::ArJdbc
191
245
  @connection.execute_insert(sql)
192
246
  end
193
247
 
248
+ LOST_CONNECTION_ERROR_MESSAGES = [
249
+ "End of stream reached",
250
+ "Broken pipe"]
251
+
252
+ # Monkey patch the execute method as reconnect is broken in the underlying
253
+ # Rails infrastructure; see these bug numbers and references:
254
+ #
255
+ # - https://github.com/jruby/activerecord-jdbc-adapter/issues/232
256
+ # - https://github.com/jruby/activerecord-jdbc-adapter/issues/237
257
+ def execute(sql, name = nil, binds = [])
258
+ tries ||= 2
259
+ super
260
+ rescue ActiveRecord::StatementInvalid => exception
261
+ if LOST_CONNECTION_ERROR_MESSAGES.any? { |msg| exception.message =~ /#{msg}/ }
262
+ reconnect!
263
+ retry unless (tries -= 1).zero?
264
+ end
265
+ raise
266
+ end
267
+
194
268
  # CONNECTION POOL ========================================================
195
269
 
196
270
  def primary_keys(table)
@@ -1,6 +1,12 @@
1
1
  class ActiveRecord::Base
2
2
  class << self
3
3
  def nuodb_connection(config)
4
+ begin
5
+ require 'jdbc/nuodb'
6
+ ::Jdbc::NuoDB.load_driver(:require) if defined?(::Jdbc::NuoDB.load_driver)
7
+ rescue LoadError # assuming driver.jar is on the class-path
8
+ end
9
+
4
10
  config[:port] ||= 48004
5
11
  config[:schema] ||= config[:database]
6
12
  config[:url] ||= "jdbc:com.nuodb://#{config[:host]}:#{config[:port]}/#{config[:database]}?schema=#{config[:schema]}"
@@ -8,6 +14,8 @@ class ActiveRecord::Base
8
14
  config[:adapter_spec] ||= ::ArJdbc::NuoDB
9
15
  config[:adapter_class] = ActiveRecord::ConnectionAdapters::NuoDBAdapter
10
16
  config[:connection_alive_sql] ||= 'select 1 from system.tables fetch first 1 rows'
17
+ options = (config[:options] ||= {})
18
+ # set connection specific options here...
11
19
  jdbc_connection(config)
12
20
  end
13
21
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-jdbcnuodb-adapter
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.1
4
+ version: 1.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Robert Buck
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-02-24 00:00:00.000000000 Z
12
+ date: 2013-03-17 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: jdbc-nuodb
@@ -19,13 +18,11 @@ dependencies:
19
18
  - - "~>"
20
19
  - !ruby/object:Gem::Version
21
20
  version: 1.0.1
22
- none: false
23
21
  requirement: !ruby/object:Gem::Requirement
24
22
  requirements:
25
23
  - - "~>"
26
24
  - !ruby/object:Gem::Version
27
25
  version: 1.0.1
28
- none: false
29
26
  prerelease: false
30
27
  type: :runtime
31
28
  - !ruby/object:Gem::Dependency
@@ -35,13 +32,11 @@ dependencies:
35
32
  - - ">="
36
33
  - !ruby/object:Gem::Version
37
34
  version: 1.0.0
38
- none: false
39
35
  requirement: !ruby/object:Gem::Requirement
40
36
  requirements:
41
37
  - - ">="
42
38
  - !ruby/object:Gem::Version
43
39
  version: 1.0.0
44
- none: false
45
40
  prerelease: false
46
41
  type: :runtime
47
42
  - !ruby/object:Gem::Dependency
@@ -50,16 +45,12 @@ dependencies:
50
45
  requirements:
51
46
  - - ">="
52
47
  - !ruby/object:Gem::Version
53
- version: !binary |-
54
- MA==
55
- none: false
48
+ version: '0'
56
49
  requirement: !ruby/object:Gem::Requirement
57
50
  requirements:
58
51
  - - ">="
59
52
  - !ruby/object:Gem::Version
60
- version: !binary |-
61
- MA==
62
- none: false
53
+ version: '0'
63
54
  prerelease: false
64
55
  type: :development
65
56
  - !ruby/object:Gem::Dependency
@@ -69,13 +60,11 @@ dependencies:
69
60
  - - "~>"
70
61
  - !ruby/object:Gem::Version
71
62
  version: 2.11.0
72
- none: false
73
63
  requirement: !ruby/object:Gem::Requirement
74
64
  requirements:
75
65
  - - "~>"
76
66
  - !ruby/object:Gem::Version
77
67
  version: 2.11.0
78
- none: false
79
68
  prerelease: false
80
69
  type: :development
81
70
  - !ruby/object:Gem::Dependency
@@ -85,13 +74,11 @@ dependencies:
85
74
  - - "~>"
86
75
  - !ruby/object:Gem::Version
87
76
  version: 2.11.0
88
- none: false
89
77
  requirement: !ruby/object:Gem::Requirement
90
78
  requirements:
91
79
  - - "~>"
92
80
  - !ruby/object:Gem::Version
93
81
  version: 2.11.0
94
- none: false
95
82
  prerelease: false
96
83
  type: :development
97
84
  - !ruby/object:Gem::Dependency
@@ -101,13 +88,11 @@ dependencies:
101
88
  - - "~>"
102
89
  - !ruby/object:Gem::Version
103
90
  version: 2.11.0
104
- none: false
105
91
  requirement: !ruby/object:Gem::Requirement
106
92
  requirements:
107
93
  - - "~>"
108
94
  - !ruby/object:Gem::Version
109
95
  version: 2.11.0
110
- none: false
111
96
  prerelease: false
112
97
  type: :development
113
98
  - !ruby/object:Gem::Dependency
@@ -117,13 +102,11 @@ dependencies:
117
102
  - - "~>"
118
103
  - !ruby/object:Gem::Version
119
104
  version: 2.11.0
120
- none: false
121
105
  requirement: !ruby/object:Gem::Requirement
122
106
  requirements:
123
107
  - - "~>"
124
108
  - !ruby/object:Gem::Version
125
109
  version: 2.11.0
126
- none: false
127
110
  prerelease: false
128
111
  type: :development
129
112
  description: ActiveRecord adapter for NuoDB. Only for use with JRuby. Requires separate Cache JDBC driver.
@@ -164,6 +147,7 @@ files:
164
147
  homepage: http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter
165
148
  licenses:
166
149
  - BSD
150
+ metadata: {}
167
151
  post_install_message:
168
152
  rdoc_options:
169
153
  - "--charset=UTF-8"
@@ -173,19 +157,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
157
  requirements:
174
158
  - - ">="
175
159
  - !ruby/object:Gem::Version
176
- version: !binary |-
177
- MA==
178
- none: false
160
+ version: '0'
179
161
  required_rubygems_version: !ruby/object:Gem::Requirement
180
162
  requirements:
181
163
  - - !binary |-
182
164
  Pg==
183
165
  - !ruby/object:Gem::Version
184
166
  version: 1.3.1
185
- none: false
186
167
  requirements: []
187
168
  rubyforge_project:
188
- rubygems_version: 1.8.24
169
+ rubygems_version: 2.0.3
189
170
  signing_key:
190
171
  specification_version: 3
191
172
  summary: ActiveRecord adapter for NuoDB.