jdbc-helper 0.7.3 → 0.7.4

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/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ database.yml.local
20
+
@@ -0,0 +1,158 @@
1
+ ### 0.7.4 / 2012/07/09
2
+ * Revised Connectors
3
+ * Use `JDBCHelper::MySQL` instead of `JDBCHelper::MySQLConnector`
4
+ * Optional `timeout` parameter has been removed. For backward-compatibility, `XXXConnector` still receives timeout parameter, though deprecated.
5
+ * Added Cassandra connector
6
+ * `JDBCHelper::Cassandra#connect`
7
+
8
+ ### 0.7.3 / 2012/05/11
9
+ * Fixed occasional error when rolling back transaction: "Can't call rollback when autocommit=true"
10
+
11
+ ### 0.7.2 / 2012/03/07
12
+ * Added JDBCHelper::Connection#execute, JDBCHelper::PreparedStatement#execute
13
+ * Returns update count as Fixnum or JDBCHelper::Connection::ResultSetEnumerator
14
+ depending on the type of the given statement.
15
+ * Bug fix: Setting nil value for PreparedStatements fails on SQL Server
16
+ * Modified to refer to ParameterMetaData when calling setNull method
17
+ * Current version of SQL Server driver has some crazy bugs with PreparedStatements.
18
+ You may notice that SQL Server complains on a perfectly fine SQL statement
19
+ only when you try to access the metadata of its wrapping PreparedStatement.
20
+ For such cases, where we can't refer to ParameterMetaData (and you will see a warning log),
21
+ setting nulls should still fail.
22
+
23
+ ### 0.7.1 / 2012/02/28
24
+ * Modified nextval/currval syntax in JDBCHelper::SequenceWrapper
25
+ * PostgreSQL: nextval('[sequence]')
26
+ * Others: [sequence].nextval
27
+ * Bug fix: JDBCHelper::Connection#inspect returns invalid data
28
+
29
+ ### 0.7.0 / 2012/01/30
30
+ * Helper methods for generating where clauses for TableWarppers
31
+ * `JDBCHelper::SQL.expr` (`JDBCHelper::SQL` deprecated in favor of `expr`)
32
+ * `JDBCHelper::SQL.ne`
33
+ * `JDBCHelper::SQL.gt`
34
+ * `JDBCHelper::SQL.ge`
35
+ * `JDBCHelper::SQL.lt`
36
+ * `JDBCHelper::SQL.le`
37
+ * `JDBCHelper::SQL.like`
38
+ * `JDBCHelper::SQL.not_like`
39
+ * `JDBCHelper::SQL.not_null`
40
+ * Tested on PostgreSQL
41
+ * Tested on MS SQL Server
42
+ * JDBCHelper::PostgresConnector added.
43
+ * JDBCHelper::SqlServerConnector added.
44
+
45
+
46
+ ### 0.6.3 / 2011/11/09
47
+ * Added flexibility when writing TableWrapper conditions with the new ActiveRecord-like Array-expression.
48
+
49
+ ```ruby
50
+ table.count(["title != ? or year <= ?", 'N/A', '2011'], :month => (1..3), :day => 10)
51
+ ```
52
+
53
+ ### 0.6.2 / 2011/10/27
54
+ * Bug fix: JDBCHelper::Connection#initialize *still* modifies its input Hash
55
+
56
+ ### 0.6.1 / 2011/09/05
57
+ * Minor fix for an inefficient type conversion
58
+ * More tests. Test coverage over 97%.
59
+
60
+ ### 0.6.0 / 2011/09/05
61
+ * Datatype handling
62
+ * Proper BLOB handling.
63
+ * Proper handling of Numeric types.
64
+ * Numeric value will be returned as Fixnum, Bignum, Float or BigDecimal. (No more Strings!)
65
+ * ParameterizedStatement#set_param achieves better precision with Time#to_f
66
+ * Increased test coverage
67
+
68
+ ### 0.5.1 / 2011/08/29
69
+ * Bug fix: TableWrapper objects are cached to prevent proliferation of PreparedStatements.
70
+
71
+ ```ruby
72
+ # In the previous version, codes like the following generated too many prepared statements.
73
+ (0..10000).each do |i|
74
+ db.table(:my_table).count(:id => i)
75
+ end
76
+ ```
77
+
78
+ ### 0.5.0 / 2011/08/29
79
+ * TableWrapper internally uses PreparedStatements instead of regular statements for better performance. <b>However, this makes it impossible to serialize batched operations.</b> Thus, you should not use batched statements with TableWrapper when the order of operations is important.
80
+ * TableWrapper#close closes cached PreparedStatements.
81
+ * Connection#execute_batch and Connection#clear_batch have been modified to execute or clear every PreparedStatment of the Connection.
82
+ * Connection overrides clone method to create another connection to the same database.
83
+
84
+ ### 0.4.10 / 2011/08/09
85
+ * Sadly, I found that with Oracle, precision and scale information from ResultSetMetaData is completely unreliable. Going conservative.
86
+
87
+ ### 0.4.9 / 2011/08/09
88
+ * Oracle NUMBER datatype is retrived as Fixnum or Bignum or String depending on its precision and scale.
89
+
90
+ ### 0.4.8 / 2011/07/12
91
+ * Improved fetch size interface
92
+ * Supports non-string property values in the input parameter for Connection object
93
+
94
+ ### 0.4.7 / 2011/06/28
95
+ * PreparedStatement performance improvement. Minimized unneccesary to_s call when setting parameters. 10% to 30% improvement observed for usual bulk insertion.
96
+
97
+ ### 0.4.6 / 2011/06/20
98
+ * Bug fix: Invalid alias for JDBCHelper::TableWrapper#drop!
99
+ * Bug fix: JDBCHelper::Connection#initialize modifies its input Hash
100
+ * Added attr_readers for url and driver to JDBCHelper::Connection
101
+
102
+ ### 0.4.5 / 2011/06/10
103
+ * JDBCHelper::TableWrapper#default method added which allows you to specify common default values for the subsequent inserts and updates.
104
+
105
+ ### 0.4.4 / 2011/06/08
106
+ * Where conditions have become accumulative, which means you can chain multiple JDBCHelper::TableWrapper#where methods to further limit the scope.
107
+
108
+ ```ruby
109
+ users = conn.table(:users).where(:status => 1).where(:age => 20..30).to_a
110
+ ```
111
+
112
+ ### 0.4.3 / 2011/06/06
113
+ * Improved handling of hash parameters for JDBCHelper::ProcedureWrapper. Missing parameters in the given Hash are treated as nulls. And now it works for both Oracle and MySQL.
114
+ * Users are encouraged to update their MySQL JDBC driver to the latest version. Some features of ProcedureWrapper may not work properly on older versions.
115
+
116
+ ### 0.4.2 / 2011/06/03
117
+ * JDBCHelper::SequenceWrapper added.
118
+ * JDBCHelper::TableWrapper#drop!, JDBCHelper::TableWrapper#truncate!
119
+
120
+ ### 0.4.1 / 2011/06/01
121
+ * Methods in JDBCHelper::TableWrapper which take where conditions as their arguments are modified to take varible length arguments.
122
+
123
+ ### 0.4.0 / 2011/05/31
124
+ * Rewrote JDBCHelper::TableWrapper interface
125
+ * JDBCHelper::TableWrapper has become Enumerable with new select, where, and order methods
126
+ * JDBCHelper::TableWrapper now supports batch updates
127
+ * WARNING: JDBCHelper::TableWrapper#select and methods in JDBCHelper::SQL are not backward-compatible.
128
+
129
+ ### 0.3.2 / 2011/05/25
130
+ * JDBCHelper::MySQLConnector.connect and JDBCHelper::OracleConnector.connect can take a block
131
+
132
+ ### 0.3.0 / 2011/05/21
133
+ * Supports CallableStatement with IN/INOUT/OUT parameters
134
+ * Added JDBCHelper::FunctionWrapper
135
+ * Added JDBCHelper::ProcedureWrapper
136
+ * Performance tuning (10-20% improvement for some scenarios)
137
+ * Removed PreparedStatement caching since PreparedStatement can be invalidated after DDLs
138
+ * Revised JDBCHelper::SQL methods (JDBCHelper::SQL#where now prepends `where')
139
+ * Minor bug fixes
140
+ * Tested with MySQL and Oracle
141
+
142
+ ### 0.2.1 / 2011/05/19
143
+ * JDBCHelper::Connection::Row can now be accessed with Range, Symbol and *[offset, length] index
144
+
145
+ ### 0.2.0 / 2011/05/19
146
+ * Feature: JDBCHelper::TableWrapper added to reduce the hassle of writing SQLs.
147
+ * YARD documentation
148
+
149
+ ### 0.1.3 / 2011/04/22
150
+ * Bug fix: setTimestamp now works correctly for java.sql.Timestamp
151
+ * Usability: Ruby Time object is automatically converted to java.sql.Timestamp object if the type of the target column is Timestamp.
152
+
153
+ ### 0.1.1-0.1.2 / 2011/04/01
154
+ * Yanked bad gem.
155
+
156
+ ### 0.1.0 / 2011/03/31
157
+ * Created. Based on samdorr-db 0.2.7. samdorr-db will be no longer maintained from now on.
158
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jdbc-helper.gemspec
4
+ gemspec
data/README.markdown CHANGED
@@ -17,7 +17,7 @@ crucial database operations from primitive selects and updates to more complex o
17
17
  batch updates, prepared statements and transactions.
18
18
  As the name implies, this gem only works on JRuby.
19
19
 
20
- Tested on MySQL 5.5, Oracle 11g R2, PostgreSQL 9.0.4 and MS SQL Server 2008 R2.
20
+ Tested on MySQL 5.5, Oracle 11g R2, PostgreSQL 9.0.4, MS SQL Server 2008 R2 and Cassandra 1.1.1 (CQL3).
21
21
 
22
22
  ## Installation
23
23
  ### Install gem
@@ -52,21 +52,49 @@ conn = JDBCHelper::Connection.new(
52
52
  :driver => 'com.mysql.jdbc.Driver',
53
53
  :url => 'jdbc:mysql://localhost/test',
54
54
  :user => 'mysql',
55
- :password => '')
55
+ :password => password)
56
56
  conn.close
57
+ ```
58
+
59
+ ### Shortcut connectors
60
+
61
+ jdbc-helper provides shortcut connectors for the following databases
62
+ so that you don't have to specify lengthy class names and JDBC URLs.
57
63
 
64
+ * MySQL (`JDBCHelper::MySQL`)
65
+ * Oracle (`JDBCHelper::Oracle`)
66
+ * PostgreSQL (`JDBCHelper::PostgreSQL`)
67
+ * MS SQL Server (`JDBCHelper::MSSQL`)
68
+ * Cassandra (`JDBCHelper::Cassandra`)
58
69
 
70
+ ```ruby
59
71
  # MySQL shortcut connector
60
- JDBCHelper::MySQLConnector.connect('localhost', 'mysql', '', 'test')
72
+ mc = JDBCHelper::MySQL.connect(host, user, password, db)
61
73
 
62
74
  # Oracle shortcut connector
63
- JDBCHelper::OracleConnector.connect(host, user, password, service_name)
75
+ oc = JDBCHelper::Oracle.connect(host, user, password, service_name)
64
76
 
65
77
  # PostgreSQL shortcut connector
66
- JDBCHelper::PostgresConnector.connect(host, user, password, db)
78
+ pc = JDBCHelper::PostgreSQL.connect(host, user, password, db)
67
79
 
68
80
  # MS SQL Server shortcut connector
69
- JDBCHelper::SqlServerConnector.connect(host, user, password, db)
81
+ sc = JDBCHelper::MSSQL.connect(host, user, password, db)
82
+
83
+ # Cassandra CQL3 connector
84
+ cc = JDBCHelper::Cassandra.connect(host, keyspace)
85
+
86
+ # Extra parameters
87
+ mc = JDBCHelper::MySQL.connect(host, user, password, db,
88
+ :rewriteBatchedStatements => true)
89
+
90
+ # With connection timeout of 30 seconds
91
+ mc = JDBCHelper::MySQL.connect(host, user, password, db,
92
+ :rewriteBatchedStatements => true, :timeout => 30)
93
+
94
+ # When block is given, connection is automatically closed after the block is executed
95
+ JDBCHelper::Cassandra.connect(host, keyspace) do |cc|
96
+ # ...
97
+ end
70
98
  ```
71
99
 
72
100
  ### Querying database table
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.verbose = true
9
+ end
10
+
11
+ Rake::TestTask.new(:performance) do |test|
12
+ test.libs << 'lib' << 'test'
13
+ test.pattern = 'test/performance.rb'
14
+ test.verbose = true
15
+ end
16
+
17
+ require 'rcov/rcovtask'
18
+ Rcov::RcovTask.new do |test|
19
+ test.libs << 'test'
20
+ test.pattern = 'test/**/test_*.rb'
21
+ test.rcov_opts << '--exclude rcov'
22
+ test.verbose = true
23
+ end
24
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.7.4
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/jdbc-helper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Junegunn Choi"]
6
+ gem.email = ["junegunn.c@gmail.com"]
7
+ gem.description = %q{A JDBC helper for JRuby/Database developers.}
8
+ gem.summary = %q{A JDBC helper for JRuby/Database developers.}
9
+ gem.homepage = "https://github.com/junegunn/jdbc-helper"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "jdbc-helper"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = JDBCHelper::VERSION
17
+
18
+ gem.add_runtime_dependency 'insensitive_hash', '~> 0.2.4'
19
+ gem.add_development_dependency "bundler", "~> 1.1.4"
20
+ gem.add_development_dependency "rcov", "~> 0.9"
21
+ gem.add_development_dependency "test-unit", ">= 2.3.0"
22
+ end
@@ -147,7 +147,7 @@ class Connection
147
147
  def initialize(args = {})
148
148
  # Subsequent deletes should not affect the input
149
149
  @args = Marshal.load(Marshal.dump(args))
150
- args = InsensitiveHash[ Marshal.load(Marshal.dump(args)) ]
150
+ args = InsensitiveHash[ @args ]
151
151
 
152
152
  raise ArgumentError.new("driver not given") unless args.has_key? :driver
153
153
  raise ArgumentError.new("url not given") unless args.has_key? :url
@@ -167,8 +167,8 @@ class Connection
167
167
  end
168
168
 
169
169
  props = java.util.Properties.new
170
- args.keys.each do |key|
171
- props.setProperty(key.to_s, args[key].to_s) if args[key]
170
+ args.each do |k, v|
171
+ props.setProperty(k.to_s, v.to_s) if v
172
172
  end
173
173
 
174
174
  @conn = java.sql.DriverManager.get_connection(@url, props)
@@ -0,0 +1,21 @@
1
+ # encoding: UTF-8
2
+ # Junegunn Choi (junegunn.c@gmail.com)
3
+
4
+ module JDBCHelper
5
+ # Shortcut connector for Cassandra CQL3
6
+ # @since 0.7.4
7
+ module Cassandra
8
+ extend Connector
9
+
10
+ # @param [String] host
11
+ # @param [String] keyspace
12
+ # @param [Hash] extra_params
13
+ # @return [JDBCHelper::Connection]
14
+ def self.connect(host, keyspace, extra_params = {}, &block)
15
+ connect_impl :cassandra, {
16
+ :url => ["jdbc:cassandra://#{host}", keyspace].compact.join('/')
17
+ }, extra_params, &block
18
+ end
19
+ end#Cassandra
20
+ end#JDBCHelper
21
+
@@ -0,0 +1,40 @@
1
+ # encoding: UTF-8
2
+ # Junegunn Choi (junegunn.c@gmail.com)
3
+
4
+ module JDBCHelper
5
+ # Shortcut connector for MS SQL Server
6
+ module MSSQL
7
+ extend Connector
8
+
9
+ # @param [String] host
10
+ # @param [String] user
11
+ # @param [String] password
12
+ # @param [String] db
13
+ # @param [Hash] extra_params
14
+ # @return [JDBCHelper::Connection]
15
+ def self.connect(host, user, password, db, extra_params = {}, &block)
16
+ connect_impl :sqlserver, {
17
+ :url => "jdbc:sqlserver://#{host};databaseName=#{db};",
18
+ :user => user,
19
+ :password => password
20
+ }, extra_params, &block
21
+ end
22
+ end#SqlServer
23
+
24
+ # Alias
25
+ SqlServer = MSSQL
26
+
27
+ # Backward-compatibility
28
+ # @deprecated
29
+ module SqlServerConnector
30
+ extend Connector
31
+ def self.connect(host, user, password, db,
32
+ timeout = Constants::DEFAULT_LOGIN_TIMEOUT,
33
+ extra_params = {}, &block)
34
+ check_params extra_params
35
+ MSSQL.connect(host, user, password, db,
36
+ {:timeout => timeout}.merge(extra_params), &block)
37
+ end
38
+ end
39
+ end#JDBCHelper
40
+
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+ # Junegunn Choi (junegunn.c@gmail.com)
3
+
4
+ module JDBCHelper
5
+ # Shortcut connector for MySQL
6
+ module MySQL
7
+ extend Connector
8
+
9
+ # @param [String] host
10
+ # @param [String] user
11
+ # @param [String] password
12
+ # @param [String] db
13
+ # @param [Hash] extra_params
14
+ # @return [JDBCHelper::Connection]
15
+ def self.connect(host, user, password, db, extra_params = {}, &block)
16
+ connect_impl :mysql, {
17
+ :url => "jdbc:mysql://#{host}/#{db}",
18
+ :user => user,
19
+ :password => password
20
+ }, extra_params, &block
21
+ end
22
+ end#MySQLConnector
23
+
24
+ # @deprecated
25
+ module MySQLConnector
26
+ extend Connector
27
+ def self.connect(host, user, password, db,
28
+ timeout = Constants::DEFAULT_LOGIN_TIMEOUT,
29
+ extra_params = {}, &block)
30
+ check_params extra_params
31
+ MySQL.connect(host, user, password, db,
32
+ {:timeout => timeout}.merge(extra_params), &block)
33
+ end
34
+ end
35
+ end#JDBCHelper
36
+
@@ -0,0 +1,58 @@
1
+ # encoding: UTF-8
2
+ # Junegunn Choi (junegunn.c@gmail.com)
3
+
4
+ module JDBCHelper
5
+ # Shortcut connector for Oracle
6
+ module Oracle
7
+ extend Connector
8
+
9
+ # @param [String] host
10
+ # @param [String] user
11
+ # @param [String] password
12
+ # @param [String] service_name
13
+ # @return [JDBCHelper::Connection]
14
+ def self.connect(host, user, password, service_name, extra_params = {}, &block)
15
+ connect_impl :oracle, {
16
+ :url => "jdbc:oracle:thin:@#{host}/#{service_name}",
17
+ :user => user,
18
+ :password => password
19
+ }, {}, &block
20
+ end
21
+
22
+ # @param [String] host
23
+ # @param [String] user
24
+ # @param [String] password
25
+ # @param [String] sid
26
+ # @return [JDBCHelper::Connection]
27
+ # @deprecated
28
+ def self.connect_by_sid(host, user, password, sid,
29
+ extra_params = {}, &block)
30
+ connect_impl :oracle, {
31
+ :url => "jdbc:oracle:thin:@#{host}:#{sid}",
32
+ :user => user,
33
+ :password => password
34
+ }, {}, &block
35
+ end
36
+ end#OracleConnector
37
+
38
+ # @deprecated
39
+ module OracleConnector
40
+ extend Connector
41
+ def self.connect(host, user, password, service_name,
42
+ timeout = Constants::DEFAULT_LOGIN_TIMEOUT,
43
+ extra_params = {}, &block)
44
+ check_params extra_params
45
+ Oracle.connect(host, user, password, service_name,
46
+ {:timeout => timeout}.merge(extra_params), &block)
47
+ end
48
+
49
+ def self.connect_by_sid(host, user, password, sid,
50
+ timeout = Constants::DEFAULT_LOGIN_TIMEOUT,
51
+ extra_params = {}, &block)
52
+ check_params extra_params
53
+ Oracle.connect_by_sid(host, user, password, sid,
54
+ {:timeout => timeout}.merge(extra_params), &block)
55
+ end
56
+ end
57
+ end#JDBCHelper
58
+
@@ -0,0 +1,40 @@
1
+ # encoding: UTF-8
2
+ # Junegunn Choi (junegunn.c@gmail.com)
3
+
4
+ module JDBCHelper
5
+ # Shortcut connector for PostgreSQL
6
+ module PostgreSQL
7
+ extend Connector
8
+
9
+ # @param [String] host
10
+ # @param [String] user
11
+ # @param [String] password
12
+ # @param [String] db
13
+ # @param [Hash] extra_params
14
+ # @return [JDBCHelper::Connection]
15
+ def self.connect(host, user, password, db, extra_params = {}, &block)
16
+ connect_impl :postgres, {
17
+ :url => "jdbc:postgresql://#{host}/#{db}",
18
+ :user => user,
19
+ :password => password
20
+ }, extra_params, &block
21
+ end
22
+ end#Postgres
23
+
24
+ # Alias
25
+ Postgres = PostgreSQL
26
+
27
+ # Backward-compatibility
28
+ # @deprecated
29
+ module PostgresConnector
30
+ extend Connector
31
+ def self.connect(host, user, password, db,
32
+ timeout = Constants::DEFAULT_LOGIN_TIMEOUT,
33
+ extra_params = {}, &block)
34
+ check_params extra_params
35
+ PostgreSQL.connect(host, user, password, db,
36
+ {:timeout => timeout}.merge(extra_params), &block)
37
+ end
38
+ end
39
+ end#JDBCHelper
40
+
@@ -2,20 +2,34 @@
2
2
  # Junegunn Choi (junegunn.c@gmail.com)
3
3
 
4
4
  module JDBCHelper
5
- class Connector
6
- private
7
- def self.ensure_close conn
8
- begin
9
- yield conn
10
- ensure
11
- conn.close rescue nil
12
- end
5
+ module Connector
6
+ def ensure_close conn
7
+ begin
8
+ yield conn
9
+ ensure
10
+ conn.close rescue nil
13
11
  end
14
- end#Connector
12
+ end
13
+
14
+ def check_params params
15
+ if params && !params.is_a?(Hash)
16
+ raise ArgumentError.new('extra_params must be a hash')
17
+ end
18
+ end
19
+
20
+ def connect_impl type, params, extra_params, &block
21
+ check_params extra_params
22
+
23
+ conn = Connection.new(
24
+ Constants::Connector::DEFAULT_PARAMETERS[type].merge(extra_params || {}).merge(params))
25
+ block_given? ? ensure_close(conn, &block) : conn
26
+ end
27
+ end#Connector
15
28
  end#JDBCHelper
16
29
 
17
- require 'jdbc-helper/connector/oracle_connector'
18
- require 'jdbc-helper/connector/mysql_connector'
19
- require 'jdbc-helper/connector/postgres_connector'
20
- require 'jdbc-helper/connector/sql_server_connector'
30
+ require 'jdbc-helper/connector/oracle'
31
+ require 'jdbc-helper/connector/mysql'
32
+ require 'jdbc-helper/connector/postgresql'
33
+ require 'jdbc-helper/connector/mssql'
34
+ require 'jdbc-helper/connector/cassandra'
21
35
 
@@ -11,26 +11,30 @@ module Constants
11
11
 
12
12
  # Constants only for Connectors
13
13
  module Connector
14
- JDBC_DRIVER = {
15
- :oracle => 'oracle.jdbc.driver.OracleDriver',
16
- :mysql => 'com.mysql.jdbc.Driver',
17
- :postgres => 'org.postgresql.Driver',
18
- :sqlserver => 'com.microsoft.sqlserver.jdbc.SQLServerDriver'
19
- }
20
-
21
14
  DEFAULT_PARAMETERS = {
22
15
  :mysql => {
23
- 'zeroDateTimeBehavior' => 'convertToNull',
24
- # Removed from 0.6.3:
16
+ :driver => 'com.mysql.jdbc.Driver',
17
+ :zeroDateTimeBehavior => 'convertToNull',
18
+ # Removed from 0.6.3:
25
19
  # This can have a performance hit when batch size is large
26
- # 'rewriteBatchedStatements' => 'true',
27
- 'useServerPrepStmts' => 'true',
28
- 'useCursorFetch' => 'true'
20
+ # :rewriteBatchedStatements => 'true',
21
+ :useServerPrepStmts => 'true',
22
+ :useCursorFetch => 'true',
23
+ },
24
+ :oracle => {
25
+ :driver => 'oracle.jdbc.driver.OracleDriver',
26
+ },
27
+ :postgres => {
28
+ :driver => 'org.postgresql.Driver',
29
+ :stringtype => 'unspecified',
29
30
  },
30
- :postgres => {
31
- 'stringtype' => 'unspecified'
31
+ :sqlserver => {
32
+ :driver => 'com.microsoft.sqlserver.jdbc.SQLServerDriver',
32
33
  },
33
- :sqlserver => {}
34
+ :cassandra => {
35
+ :driver => 'org.apache.cassandra.cql.jdbc.CassandraDriver',
36
+ :cqlVersion => '3.0.0',
37
+ }
34
38
  }
35
39
  end#Connector
36
40
  end#Constants
@@ -0,0 +1,3 @@
1
+ module JDBCHelper
2
+ VERSION = '0.7.4'
3
+ end
data/lib/jdbc-helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # encoding: UTF-8
2
2
  # Junegunn Choi (junegunn.c@gmail.com)
3
3
 
4
+ require 'jdbc-helper/version'
5
+
4
6
  if RUBY_PLATFORM.match(/java/).nil?
5
7
  raise LoadError, 'JRuby is required for JDBC'
6
8
  end
data/test/helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require 'insensitive_hash'
3
4
  #require 'pry'
4
5
 
5
6
  begin
@@ -23,7 +24,7 @@ module JDBCHelperTestHelper
23
24
  def config
24
25
  path = File.dirname(__FILE__) + '/database.yml'
25
26
  path += '.local' if File.exists?(path + '.local')
26
- @db_config ||= YAML.load File.read(path)
27
+ @db_config ||= YAML.load(File.read(path)).insensitive
27
28
  end
28
29
 
29
30
  def create_test_procedure_simple conn, name
@@ -76,9 +77,8 @@ module JDBCHelperTestHelper
76
77
 
77
78
  def each_connection(&block)
78
79
  config.each do | db, conn_info |
79
- conn = JDBCHelper::Connection.new(conn_info.reject { |k,v| k == 'database'})
80
80
  # Just for quick and dirty testing
81
- @type = case conn_info['driver'] || conn_info[:driver]
81
+ @type = case conn_info[:driver]
82
82
  when /mysql/i
83
83
  :mysql
84
84
  when /oracle/i
@@ -88,10 +88,12 @@ module JDBCHelperTestHelper
88
88
  when /sqlserver/i
89
89
  :sqlserver
90
90
  else
91
- p conn_info
92
91
  :unknown
93
92
  end
94
93
 
94
+ next if @type == :unknown
95
+
96
+ conn = JDBCHelper::Connection.new(conn_info.reject { |k,v| k == 'database'})
95
97
  conn.update 'set global max_allowed_packet = 1073741824' if @type == :mysql
96
98
 
97
99
  begin