Browse files

Rename JdbcSpec => ArJdbc

  • Loading branch information...
1 parent 0a39d33 commit f55ff48689b0331f868d06f9dab0668c3811f842 @nicksieger nicksieger committed Jul 1, 2010
View
4 lib/arjdbc/cachedb/adapter.rb
@@ -1,6 +1,6 @@
require 'arjdbc/mssql/tsql_helper'
-module ::JdbcSpec
+module ::ArJdbc
module CacheDB
include TSqlMethods
@@ -9,7 +9,7 @@ def self.adapter_matcher(name, *)
end
def self.column_selector
- [ /cache/i, lambda { | cfg, col | col.extend( ::JdbcSpec::CacheDB::Column ) } ]
+ [ /cache/i, lambda { | cfg, col | col.extend( ::ArJdbc::CacheDB::Column ) } ]
end
module Column
View
8 lib/arjdbc/db2/adapter.rb
@@ -1,18 +1,18 @@
-module JdbcSpec
+module ArJdbc
module DB2
def self.adapter_matcher(name, config)
if name =~ /db2/i
- return config[:url] =~ /^jdbc:derby:net:/ ? ::JdbcSpec::Derby : self
+ return config[:url] =~ /^jdbc:derby:net:/ ? ::ArJdbc::Derby : self
end
false
end
def self.adapter_selector
[/db2/i, lambda {|cfg,adapt|
if cfg[:url] =~ /^jdbc:derby:net:/
- adapt.extend(::JdbcSpec::Derby)
+ adapt.extend(::ArJdbc::Derby)
else
- adapt.extend(::JdbcSpec::DB2)
+ adapt.extend(::ArJdbc::DB2)
end }]
end
View
6 lib/arjdbc/derby/adapter.rb
@@ -1,13 +1,13 @@
require 'arjdbc/jdbc/missing_functionality_helper'
-module ::JdbcSpec
+module ::ArJdbc
module Derby
def self.adapter_matcher(name, *)
name =~ /derby/i ? self : false
end
def self.column_selector
- [/derby/i, lambda {|cfg,col| col.extend(::JdbcSpec::Derby::Column)}]
+ [/derby/i, lambda {|cfg,col| col.extend(::ArJdbc::Derby::Column)}]
end
def self.monkey_rails
@@ -59,7 +59,7 @@ def adapter_name #:nodoc:
'Derby'
end
- include JdbcSpec::MissingFunctionalityHelper
+ include ArJdbc::MissingFunctionalityHelper
def index_name_length
128
View
2 lib/arjdbc/firebird/adapter.rb
@@ -1,4 +1,4 @@
-module ::JdbcSpec
+module ::ArJdbc
module FireBird
def self.adapter_matcher(name, *)
name =~ /firebird/i ? self : false
View
2 lib/arjdbc/h2/adapter.rb
@@ -1,6 +1,6 @@
require 'arjdbc/hsqldb/adapter'
-module JdbcSpec
+module ArJdbc
module H2
include HSQLDB
View
4 lib/arjdbc/hsqldb/adapter.rb
@@ -1,4 +1,4 @@
-module ::JdbcSpec
+module ::ArJdbc
module HSQLDB
def self.extended(mod)
mod.class.class_eval do
@@ -11,7 +11,7 @@ def self.adapter_matcher(name, *)
end
def self.column_selector
- [/hsqldb|\.h2\./i, lambda {|cfg,col| col.extend(::JdbcSpec::HSQLDB::Column)}]
+ [/hsqldb|\.h2\./i, lambda {|cfg,col| col.extend(::ArJdbc::HSQLDB::Column)}]
end
module Column
View
8 lib/arjdbc/informix/adapter.rb
@@ -4,7 +4,7 @@ class Base
private
def write_lobs
- if connection.is_a?(JdbcSpec::Informix)
+ if connection.is_a?(ArJdbc::Informix)
self.class.columns.each do |c|
if [:text, :binary].include? c.type
value = self[c.name]
@@ -25,7 +25,7 @@ def write_lobs
end
end
-module ::JdbcSpec
+module ::ArJdbc
module Informix
def self.extended(base)
@@db_major_version = base.select_one("SELECT dbinfo('version', 'major') version FROM systables WHERE tabid = 1")['version'].to_i
@@ -37,7 +37,7 @@ def self.adapter_matcher(name, *)
def self.column_selector
[ /informix/i,
- lambda { |cfg, column| column.extend(::JdbcSpec::Informix::Column) } ]
+ lambda { |cfg, column| column.extend(::ArJdbc::Informix::Column) } ]
end
module Column
@@ -135,4 +135,4 @@ def select(sql, name = nil)
execute(sql.gsub(/(!=|<>)\s*null/i, "IS NOT NULL").gsub(/=\s*null/i, "IS NULL"), name)
end
end # module Informix
-end # module ::JdbcSpec
+end # module ::ArJdbc
View
10 lib/arjdbc/jdbc/adapter.rb
@@ -36,7 +36,7 @@ def type_to_sql(type, limit = nil, precision = nil, scale = nil)
end
end
-module JdbcSpec
+module ArJdbc
module QuotedPrimaryKeyExtension
def self.extended(base)
# Rails 3 method Rails 2 method
@@ -54,7 +54,7 @@ def self.extended(base)
alias :#{meth}_pre_pk :#{meth}
def #{meth}(include_primary_key = true, *args) #:nodoc:
aq = #{meth}_pre_pk(include_primary_key, *args)
- if connection.is_a?(JdbcSpec::Oracle) || connection.is_a?(JdbcSpec::Mimer)
+ if connection.is_a?(ArJdbc::Oracle) || connection.is_a?(ArJdbc::Mimer)
aq[#{pk_hash_key}] = #{pk_hash_value} if include_primary_key && aq[#{pk_hash_key}].nil?
end
aq
@@ -265,8 +265,8 @@ def create
class JdbcColumn < Column
attr_writer :limit, :precision
- COLUMN_TYPES = ::JdbcSpec.constants.map{|c|
- ::JdbcSpec.const_get c }.select{ |c|
+ COLUMN_TYPES = ::ArJdbc.constants.map{|c|
+ ::ArJdbc.const_get c }.select{ |c|
c.respond_to? :column_selector }.map{|c|
c.column_selector }.inject({}) { |h,val|
h[val[0]] = val[1]; h }
@@ -471,7 +471,7 @@ def jdbc_connection_class(spec)
# Locate specialized adapter specification if one exists based on config data
def adapter_spec(config)
dialect = (config[:dialect] || config[:driver]).to_s
- ::JdbcSpec.constants.map { |name| ::JdbcSpec.const_get name }.each do |constant|
+ ::ArJdbc.constants.map { |name| ::ArJdbc.const_get name }.each do |constant|
if constant.respond_to? :adapter_matcher
spec = constant.adapter_matcher(dialect, config)
return spec if spec
View
2 lib/arjdbc/jdbc/missing_functionality_helper.rb
@@ -1,4 +1,4 @@
-module JdbcSpec
+module ArJdbc
module MissingFunctionalityHelper
#Taken from SQLite adapter
View
2 lib/arjdbc/jdbc/railtie.rb
@@ -1,6 +1,6 @@
require 'rails/railtie'
-module ::JdbcSpec
+module ::ArJdbc
class Railtie < ::Rails::Railtie
rake_tasks do
load File.expand_path('../rake_tasks.rb', __FILE__)
View
4 lib/arjdbc/mimer/adapter.rb
@@ -1,7 +1,7 @@
-module JdbcSpec
+module ArJdbc
module Mimer
def self.extended(mod)
- ActiveRecord::Base.extend JdbcSpec::QuotedPrimaryKeyExtension
+ ActiveRecord::Base.extend ArJdbc::QuotedPrimaryKeyExtension
end
def self.adapter_matcher(name, *)
View
6 lib/arjdbc/mssql/adapter.rb
@@ -1,6 +1,6 @@
require 'arjdbc/mssql/tsql_helper'
-module ::JdbcSpec
+module ::ArJdbc
module MsSQL
include TSqlMethods
@@ -29,7 +29,7 @@ def self.adapter_matcher(name, *)
end
def self.column_selector
- [/sqlserver|tds/i, lambda {|cfg,col| col.extend(::JdbcSpec::MsSQL::Column)}]
+ [/sqlserver|tds/i, lambda {|cfg,col| col.extend(::ArJdbc::MsSQL::Column)}]
end
def self.jdbc_connection_class
@@ -150,7 +150,7 @@ def quote(value, column = nil)
when String, ActiveSupport::Multibyte::Chars
value = value.to_s
if column && column.type == :binary
- "'#{quote_string(JdbcSpec::MsSQL::Column.string_to_binary(value))}'" # ' (for ruby-mode)
+ "'#{quote_string(ArJdbc::MsSQL::Column.string_to_binary(value))}'" # ' (for ruby-mode)
elsif column && [:integer, :float].include?(column.type)
value = column.type == :integer ? value.to_i : value.to_f
value.to_s
View
4 lib/arjdbc/mysql/adapter.rb
@@ -4,14 +4,14 @@ module ActiveRecord::ConnectionAdapters
MysqlAdapter = Class.new(AbstractAdapter) unless const_defined?(:MysqlAdapter)
end
-module ::JdbcSpec
+module ::ArJdbc
module MySQL
def self.adapter_matcher(name, *)
name =~ /mysql/i ? self : false
end
def self.column_selector
- [/mysql/i, lambda {|cfg,col| col.extend(::JdbcSpec::MySQL::Column)}]
+ [/mysql/i, lambda {|cfg,col| col.extend(::ArJdbc::MySQL::Column)}]
end
def self.extended(adapter)
View
2 lib/arjdbc/mysql/connection_methods.rb
@@ -15,7 +15,7 @@ def mysql_connection(config)
end
config[:driver] ||= "com.mysql.jdbc.Driver"
connection = jdbc_connection(config)
- ::JdbcSpec::MySQL.kill_cancel_timer(connection.raw_connection)
+ ::ArJdbc::MySQL.kill_cancel_timer(connection.raw_connection)
connection
end
alias_method :jdbcmysql_connection, :mysql_connection
View
10 lib/arjdbc/oracle/adapter.rb
@@ -2,7 +2,7 @@ module ActiveRecord::ConnectionAdapters
OracleAdapter = Class.new(AbstractAdapter) unless const_defined?(:OracleAdapter)
end
-module ::JdbcSpec
+module ::ArJdbc
module Oracle
def self.extended(mod)
unless @lob_callback_added
@@ -21,7 +21,7 @@ def after_save_with_oracle_lob
ActiveRecord::Base.after_save :after_save_with_oracle_lob
@lob_callback_added = true
end
- ActiveRecord::Base.extend JdbcSpec::QuotedPrimaryKeyExtension
+ ActiveRecord::Base.extend ArJdbc::QuotedPrimaryKeyExtension
mod.class.class_eval do
alias_chained_method :insert, :query_dirty, :insert
alias_chained_method :columns, :query_cache, :columns
@@ -33,7 +33,7 @@ def self.adapter_matcher(name, *)
end
def self.column_selector
- [/oracle/i, lambda {|cfg,col| col.extend(::JdbcSpec::Oracle::Column)}]
+ [/oracle/i, lambda {|cfg,col| col.extend(::ArJdbc::Oracle::Column)}]
end
module Column
@@ -47,15 +47,15 @@ def primary=(val)
def type_cast(value)
return nil if value.nil?
case type
- when :datetime then JdbcSpec::Oracle::Column.string_to_time(value, self.class)
+ when :datetime then ArJdbc::Oracle::Column.string_to_time(value, self.class)
else
super
end
end
def type_cast_code(var_name)
case type
- when :datetime then "JdbcSpec::Oracle::Column.string_to_time(#{var_name}, self.class)"
+ when :datetime then "ArJdbc::Oracle::Column.string_to_time(#{var_name}, self.class)"
else
super
end
View
4 lib/arjdbc/postgresql/adapter.rb
@@ -2,7 +2,7 @@ module ActiveRecord::ConnectionAdapters
PostgreSQLAdapter = Class.new(AbstractAdapter) unless const_defined?(:PostgreSQLAdapter)
end
-module ::JdbcSpec
+module ::ArJdbc
module PostgreSQL
def self.extended(mod)
mod.class.class_eval do
@@ -15,7 +15,7 @@ def self.adapter_matcher(name, *)
end
def self.column_selector
- [/postgre/i, lambda {|cfg,col| col.extend(::JdbcSpec::PostgreSQL::Column)}]
+ [/postgre/i, lambda {|cfg,col| col.extend(::ArJdbc::PostgreSQL::Column)}]
end
def self.jdbc_connection_class
View
22 lib/arjdbc/sqlite3/adapter.rb
@@ -4,7 +4,7 @@ module ActiveRecord::ConnectionAdapters
Sqlite3Adapter = Class.new(AbstractAdapter) unless const_defined?(:Sqlite3Adapter)
end
-module ::JdbcSpec
+module ::ArJdbc
module SQLite3
def self.extended(base)
base.class.class_eval do
@@ -17,7 +17,7 @@ def self.adapter_matcher(name, *)
end
def self.column_selector
- [/sqlite/i, lambda {|cfg,col| col.extend(::JdbcSpec::SQLite3::Column)}]
+ [/sqlite/i, lambda {|cfg,col| col.extend(::ArJdbc::SQLite3::Column)}]
end
def self.jdbc_connection_class
@@ -33,12 +33,12 @@ def type_cast(value)
return nil if value.nil?
case type
when :string then value
- when :integer then JdbcSpec::SQLite3::Column.cast_to_integer(value)
+ when :integer then ArJdbc::SQLite3::Column.cast_to_integer(value)
when :primary_key then defined?(value.to_i) ? value.to_i : (value ? 1 : 0)
when :float then value.to_f
- when :datetime then JdbcSpec::SQLite3::Column.cast_to_date_or_time(value)
- when :date then JdbcSpec::SQLite3::Column.cast_to_date_or_time(value)
- when :time then JdbcSpec::SQLite3::Column.cast_to_time(value)
+ when :datetime then ArJdbc::SQLite3::Column.cast_to_date_or_time(value)
+ when :date then ArJdbc::SQLite3::Column.cast_to_date_or_time(value)
+ when :time then ArJdbc::SQLite3::Column.cast_to_time(value)
when :decimal then self.class.value_to_decimal(value)
when :boolean then self.class.value_to_boolean(value)
else value
@@ -47,10 +47,10 @@ def type_cast(value)
def type_cast_code(var_name)
case type
- when :integer then "JdbcSpec::SQLite3::Column.cast_to_integer(#{var_name})"
- when :datetime then "JdbcSpec::SQLite3::Column.cast_to_date_or_time(#{var_name})"
- when :date then "JdbcSpec::SQLite3::Column.cast_to_date_or_time(#{var_name})"
- when :time then "JdbcSpec::SQLite3::Column.cast_to_time(#{var_name})"
+ when :integer then "ArJdbc::SQLite3::Column.cast_to_integer(#{var_name})"
+ when :datetime then "ArJdbc::SQLite3::Column.cast_to_date_or_time(#{var_name})"
+ when :date then "ArJdbc::SQLite3::Column.cast_to_date_or_time(#{var_name})"
+ when :time then "ArJdbc::SQLite3::Column.cast_to_time(#{var_name})"
else
super
end
@@ -323,7 +323,7 @@ def add_lock!(sql, options) #:nodoc:
end
protected
- include JdbcSpec::MissingFunctionalityHelper
+ include ArJdbc::MissingFunctionalityHelper
def translate_exception(exception, message)
case exception.message
View
2 lib/arjdbc/sybase/adapter.rb
@@ -1,4 +1,4 @@
-module JdbcSpec
+module ArJdbc
module Sybase
def self.adapter_matcher(name, *)
name =~ /sybase|tds/i ? self : false
View
6 src/java/arjdbc/jdbc/AdapterJavaService.java
@@ -49,11 +49,11 @@ public boolean basicLoad(final Ruby runtime) throws IOException {
PostgresqlRubyJdbcConnection.createPostgresqlJdbcConnectionClass(runtime, jdbcConnection);
MssqlRubyJdbcConnection.createMssqlJdbcConnectionClass(runtime, jdbcConnection);
Sqlite3RubyJdbcConnection.createSqlite3JdbcConnectionClass(runtime, jdbcConnection);
- RubyModule jdbcSpec = runtime.getOrCreateModule("JdbcSpec");
+ RubyModule arJdbc = runtime.getOrCreateModule("ArJdbc");
rubyApi = JavaEmbedUtils.newObjectAdapter();
- MySQLModule.load(jdbcSpec);
- DerbyModule.load(jdbcSpec, rubyApi);
+ MySQLModule.load(arJdbc);
+ DerbyModule.load(arJdbc, rubyApi);
return true;
}
}
View
0 test/db/cachedb.rb 100755 → 100644
File mode changed.
View
26 test/db/derby.rb
@@ -1,14 +1,12 @@
-require 'logger'
-
-config = {
- :adapter => 'derby',
- :database => "derby-testdb"
-}
-
-ActiveRecord::Base.establish_connection(config)
-
-at_exit {
- # Clean up derby files
- require 'fileutils'
- FileUtils.rm_rf('derby-testdb')
-}
+config = {
+ :adapter => 'derby',
+ :database => "derby-testdb"
+}
+
+ActiveRecord::Base.establish_connection(config)
+
+at_exit {
+ # Clean up derby files
+ require 'fileutils'
+ FileUtils.rm_rf('derby-testdb')
+}
View
6 test/db/jndi_config.rb
@@ -6,7 +6,7 @@
InitialContext = javax.naming.InitialContext
Reference = javax.naming.Reference
StringRefAddr = javax.naming.StringRefAddr
-
+
System.set_property(Context::INITIAL_CONTEXT_FACTORY,
'com.sun.jndi.fscontext.RefFSContextFactory')
project_path = File.expand_path(File.dirname(__FILE__) + '/../..')
@@ -18,9 +18,9 @@
derby_ref = Reference.new('javax.sql.DataSource',
'org.apache.commons.dbcp.BasicDataSourceFactory',
nil)
-derby_ref.add StringRefAddr.new('driverClassName',
+derby_ref.add StringRefAddr.new('driverClassName',
'org.apache.derby.jdbc.EmbeddedDriver')
-derby_ref.add StringRefAddr.new('url',
+derby_ref.add StringRefAddr.new('url',
'jdbc:derby:derby-testdb;create=true')
derby_ref.add StringRefAddr.new('username', 'sa')
derby_ref.add StringRefAddr.new('password', '')
View
23 test/db2_simple_test.rb
@@ -8,3 +8,26 @@ class DB2SimpleTest < Test::Unit::TestCase
class DB2HasManyThroughTest < Test::Unit::TestCase
include HasManyThroughMethods
end
+
+class DB2Test < Test::Unit::TestCase
+ def setup
+ @inst = Object.new
+ @inst.extend ArJdbc::DB2
+ @column = Object.new
+ class << @column
+ attr_accessor :type
+ end
+ end
+
+ def test_quote_decimal
+ assert_equal %q{'123.45'}, @inst.quote("123.45")
+ @column.type = :decimal
+ assert_equal %q{123.45}, @inst.quote("123.45", @column), "decimal columns should not have quotes"
+ end
+
+ def test_primary_key_generation
+ @column.type = :primary_key
+ assert_equal 'int not null generated by default as identity (start with 1) primary key', @inst.modify_types({:string => {}, :integer => {}, :boolean => {}})[:primary_key]
+ end
+
+end
View
26 test/jdbc_adapter/jdbc_db2_test.rb
@@ -1,26 +0,0 @@
-require 'java'
-require 'arjdbc/jdbc/jdbc_db2'
-require 'test/unit'
-
-class JdbcSpec::DB2Test < Test::Unit::TestCase
- def setup
- @inst = Object.new
- @inst.extend JdbcSpec::DB2
- @column = Object.new
- class <<@column
- attr_accessor :type
- end
- end
-
- def test_quote_decimal
- assert_equal %q{'123.45'}, @inst.quote("123.45")
- @column.type = :decimal
- assert_equal %q{123.45}, @inst.quote("123.45", @column), "decimal columns should not have quotes"
- end
-
- def test_primary_key_generation
- @column.type = :primary_key
- assert_equal 'int not null generated by default as identity (start with 1) primary key', @inst.modify_types({:string => {}, :integer => {}, :boolean => {}})[:primary_key]
- end
-
-end
View
32 test/jdbc_adapter/jdbc_sybase_test.rb
@@ -1,32 +0,0 @@
-require 'jdbc_common'
-
-class MockConnection
-
- def adapter=( adapt )
- end
-
-end
-
-module ActiveRecord
- module ConnectionAdapters
-
- class SybaseAdapterSelectionTest < Test::Unit::TestCase
-
- def testJtdsSelectionUsingDialect()
- config = {
- :driver => 'net.sourceforge.jtds.Driver',
- :dialect => 'sybase'
- }
- adapt = JdbcAdapter.new(MockConnection.new, nil, config)
- assert adapt.kind_of?(JdbcSpec::Sybase), "Should be a sybase adapter"
- end
-
- def testJtdsSelectionNotUsingDialect
- config = { :driver => 'net.sourceforge.jtds.Driver' }
- adapt = JdbcAdapter.new(MockConnection.new, nil, config)
- assert adapt.kind_of?(JdbcSpec::MsSQL), "Should be a MsSQL apdater"
- end
-
- end
- end
-end
View
22 test/sybase_jtds_simple_test.rb
@@ -4,3 +4,25 @@
class SybaseJtdsSimpleTest < Test::Unit::TestCase
include SimpleTestMethods
end
+
+class SybaseAdapterSelectionTest < Test::Unit::TestCase
+ class MockConnection
+ def adapter=(adapt)
+ end
+ end
+
+ def test_jtds_selection_using_dialect
+ config = {
+ :driver => 'net.sourceforge.jtds.Driver',
+ :dialect => 'sybase'
+ }
+ adapt = JdbcAdapter.new(MockConnection.new, nil, config)
+ assert adapt.kind_of?(ArJdbc::Sybase), "Should be a sybase adapter"
+ end
+
+ def test_jtds_selection_not_using_dialect
+ config = { :driver => 'net.sourceforge.jtds.Driver' }
+ adapt = JdbcAdapter.new(MockConnection.new, nil, config)
+ assert adapt.kind_of?(ArJdbc::MsSQL), "Should be a MsSQL apdater"
+ end
+end

0 comments on commit f55ff48

Please sign in to comment.