sequel-jdbc-pervasive-adapter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+ gem 'pry'
3
+ # Specify your gem's dependencies in sequel-jdbc-pervasive-adapter.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Colin Casey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,23 @@
1
+ = sequel-jdbc-hxtt-adapter
2
+
3
+ A sequel adapter for working with MS Access files using HXTT's pure JDBC Access driver. JRuby is required when using this
4
+ adapter. It will not work in any other Ruby interpreter.
5
+
6
+ == HXTT Driver
7
+
8
+ The jar library containing the HXTT driver is not supplied but you can obtain a trial version or purchase it at http://www.hxtt.com
9
+
10
+ == Note on Patches/Pull Requests
11
+
12
+ * Fork the project.
13
+ * Make your feature addition or bug fix.
14
+ * Add tests for it. This is important so I don't break it in a
15
+ future version unintentionally.
16
+ * Commit, do not mess with rakefile, version, or history.
17
+ (if you want to have your own version, that is fine but
18
+ bump version in a commit by itself I can ignore when I pull)
19
+ * Send me a pull request. Bonus points for topic branches.
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2010 Colin Casey. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.3
@@ -0,0 +1,11 @@
1
+ require "sequel-jdbc-pervasive-adapter/version"
2
+
3
+ module Sequel
4
+ module Jdbc
5
+ module Pervasive
6
+ module Adapter
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Sequel
2
+ module Jdbc
3
+ module Pervasive
4
+ module Adapter
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,172 @@
1
+ # encoding: utf-8
2
+ require "sequel-jdbc-pervasive-adapter/jpscs.jar"
3
+ require "sequel-jdbc-pervasive-adapter/pvjdbc2.jar"
4
+ require "sequel-jdbc-pervasive-adapter/pvjdbc2x.jar"
5
+
6
+ Java::JavaClass.for_name("com.pervasive.jdbc.v2.Driver")
7
+
8
+ module Sequel
9
+ module JDBC
10
+ module Pervasive
11
+ module DatabaseMethods
12
+ AUTO_INCREMENT = 'AUTO_INCREMENT'.freeze
13
+ PRIMARY_KEY = 'PRIMARY KEY'.freeze
14
+ SQL_BEGIN = "START TRANSACTION".freeze
15
+ SQL_COMMIT = "COMMIT".freeze
16
+ SQL_SAVEPOINT = 'SAVEPOINT autopoint_%d'.freeze
17
+ SQL_ROLLBACK_TO_SAVEPOINT = 'ROLLBACK TO SAVEPOINT autopoint_%d'.freeze
18
+ NULL = "NULL".freeze
19
+ NOT_NULL = "NOT NULL".freeze
20
+ UNIQUE = "UNIQUE".freeze
21
+
22
+ # Return instance of Sequel::JDBC::Pervasive::Dataset with the given opts.
23
+ def dataset(opts=nil)
24
+ Sequel::JDBC::Pervasive::Dataset.new(self, opts)
25
+ end
26
+
27
+ def database_type
28
+ :pervasive
29
+ end
30
+
31
+ def supports_savepoints?
32
+ true
33
+ end
34
+
35
+ def tables
36
+ ts = []
37
+ m = output_identifier_meth
38
+ metadata(:getTables, nil, nil, nil, ['TABLE'].to_java(:string)) do |h|
39
+ h = downcase_hash_keys(h)
40
+ ts << m.call(h[:table_name])
41
+ end
42
+ ts
43
+ end
44
+
45
+ private
46
+ def identifier_input_method_default
47
+ :to_s
48
+ end
49
+
50
+ def identifier_output_method_default
51
+ :to_s
52
+ end
53
+
54
+ def schema_parse_table(table, opts={})
55
+ m = output_identifier_meth
56
+ im = input_identifier_meth
57
+ ds = dataset
58
+ schema, table = schema_and_table(table)
59
+ schema ||= opts[:schema]
60
+ schema = im.call(schema) if schema
61
+ table = im.call(table)
62
+ pks, ts = [], []
63
+ metadata(:getPrimaryKeys, nil, schema, table) do |h|
64
+ h = downcase_hash_keys(h)
65
+ pks << h[:column_name]
66
+ end
67
+ metadata(:getColumns, nil, schema, table, nil) do |h|
68
+ h = downcase_hash_keys(h)
69
+ ts << [m.call(h[:column_name]), {:type=>schema_column_type(h[:type_name]), :db_type=>h[:type_name], :default=>(h[:column_def] == '' ? nil : h[:column_def]), :allow_null=>(h[:nullable] != 0), :primary_key=>pks.include?(h[:column_name]), :column_size=>h[:column_size]}]
70
+ end
71
+ ts
72
+ end
73
+
74
+ def downcase_hash_keys(h)
75
+ lh = {}
76
+ h.each { |k,v| lh[k.to_s.downcase.to_sym] = v }
77
+ lh
78
+ end
79
+
80
+ def column_definition_sql(column)
81
+ sql = "#{quote_identifier(column[:name])} #{type_literal(column)}"
82
+ sql << UNIQUE if column[:unique]
83
+ null = column.include?(:null) ? column[:null] : column[:allow_null]
84
+ sql << NOT_NULL if null == false
85
+ sql << NULL if null == true
86
+ sql << " DEFAULT #{column[:default].is_a?(String) ? "'\"#{column[:default]}\"'" : literal(column[:default])}" if column.include?(:default)
87
+ sql << " #{auto_increment_sql} " if column[:auto_increment]
88
+ sql << PRIMARY_KEY if column[:primary_key]
89
+ sql << column_references_column_constraint_sql(column) if column[:table]
90
+ sql
91
+ end
92
+
93
+ def auto_increment_sql
94
+ AUTO_INCREMENT
95
+ end
96
+
97
+ def begin_transaction_sql
98
+ SQL_BEGIN
99
+ end
100
+
101
+ def begin_savepoint_sql(depth)
102
+ SQL_SAVEPOINT % depth
103
+ end
104
+
105
+ def rollback_savepoint_sql(depth)
106
+ SQL_ROLLBACK_TO_SAVEPOINT % depth
107
+ end
108
+
109
+ def commit_transaction_sql
110
+ SQL_COMMIT
111
+ end
112
+
113
+ def type_literal_generic_float(column)
114
+ :float
115
+ end
116
+ end
117
+
118
+ class Dataset < JDBC::Dataset
119
+ BOOL_TRUE = 'TRUE'.freeze
120
+ BOOL_FALSE = 'FALSE'.freeze
121
+ SELECT_CLAUSE_METHODS = Dataset.clause_methods(:select, %w'limit columns from where')
122
+
123
+ def quoted_identifier(name)
124
+ "[#{name}]"
125
+ end
126
+
127
+ def literal_false
128
+ BOOL_FALSE
129
+ end
130
+
131
+ def literal_true
132
+ BOOL_TRUE
133
+ end
134
+
135
+ def select_clause_methods
136
+ SELECT_CLAUSE_METHODS
137
+ end
138
+
139
+ def select_limit_sql(sql)
140
+ sql << "SELECT TOP #{@opts[:limit]}" if @opts[:limit]
141
+ end
142
+
143
+ def supports_is_true?
144
+ false
145
+ end
146
+
147
+ def process_result_set(result)
148
+ # get column names
149
+ meta = result.getMetaData
150
+ cols = []
151
+ i = 0
152
+ meta.getColumnCount.times{cols << [output_identifier(meta.getColumnLabel(i+=1)), i]}
153
+ @columns = cols.map{|c| c.at(0)}
154
+ row = {}
155
+ blk = if @convert_types
156
+ lambda{ |n, i|
157
+ row[n] = convert_type(result.getObject(i))
158
+ }
159
+ else
160
+ lambda{|n, i| row[n] = result.getObject(i)}
161
+ end
162
+ # get rows
163
+ while result.next
164
+ row = {}
165
+ cols.each(&blk)
166
+ yield row
167
+ end
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ require 'sequel'
3
+ require 'sequel/adapters/jdbc'
4
+
5
+ Sequel::JDBC::DATABASE_SETUP[:pervasive] = proc do |db|
6
+ require 'sequel/adapters/jdbc/pervasive'
7
+ db.extend(Sequel::JDBC::Pervasive::DatabaseMethods)
8
+ java.sql.DriverManager.registerDriver("com.pervasive.jdbc.v2.Driver");
9
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sequel-jdbc-pervasive-adapter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sequel-jdbc-pervasive-adapter"
7
+ s.version = Sequel::Jdbc::Pervasive::Adapter::VERSION
8
+ s.authors = ["Stefan Penner"]
9
+ s.email = ["stefan.penner@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Pervasive JDBC Sequel Adapter}
12
+ s.description = %q{Basic Implementation of a Pervasive JDBC Sequel Adapter}
13
+
14
+ s.rubyforge_project = "sequel-jdbc-pervasive-adapter"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "sequel"
24
+ end
@@ -0,0 +1,33 @@
1
+ require 'sequel/jdbc_pervasive_adapter'
2
+
3
+ DB_STRING = ENV['PERVASIVE_DB']
4
+
5
+ db = Sequel.connect(DB_STRING)
6
+ class Item < Sequel::Model(db[:item])
7
+ end
8
+
9
+ describe 'pervasive' do
10
+
11
+ it 'fails to connect to non existent database' do
12
+ expect {
13
+ Sequel.connect("jdbc:pervasive://nowhere/nada").tables
14
+ }.to raise_error(Sequel::DatabaseConnectionError)
15
+ end
16
+
17
+ context "with test database" do
18
+ subject do
19
+ Sequel.connect(DB_STRING)
20
+ end
21
+
22
+ its(:database_type) { should equal(:pervasive) }
23
+ its(:tables) { should include(:item) }
24
+
25
+ context "ORM" do
26
+ subject { Item }
27
+ its(:first) { should_not be_nil }
28
+ it "limits" do
29
+ subject.limit(1).all.count.should == 1
30
+ end
31
+ end
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sequel-jdbc-pervasive-adapter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Stefan Penner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-02-14 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: sequel
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ description: Basic Implementation of a Pervasive JDBC Sequel Adapter
38
+ email:
39
+ - stefan.penner@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.rdoc
52
+ - Rakefile
53
+ - VERSION
54
+ - lib/sequel-jdbc-pervasive-adapter.rb
55
+ - lib/sequel-jdbc-pervasive-adapter/jpscs.jar
56
+ - lib/sequel-jdbc-pervasive-adapter/pvjdbc2.jar
57
+ - lib/sequel-jdbc-pervasive-adapter/pvjdbc2x.jar
58
+ - lib/sequel-jdbc-pervasive-adapter/version.rb
59
+ - lib/sequel/adapters/jdbc/pervasive.rb
60
+ - lib/sequel/jdbc_pervasive_adapter.rb
61
+ - sequel-jdbc-pervasive-adapter.gemspec
62
+ - spec/sequel_jdbc_pervasive_adapter_spec.rb
63
+ homepage: ""
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project: sequel-jdbc-pervasive-adapter
86
+ rubygems_version: 1.8.9
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Pervasive JDBC Sequel Adapter
90
+ test_files:
91
+ - spec/sequel_jdbc_pervasive_adapter_spec.rb