activerecord-jdbcsqlanywhere-adapter 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ *.jar
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in activerecord-sqlanywhere-adapter.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Brian Olsen <brian@maven-group.org>
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.
@@ -0,0 +1,5 @@
1
+ activerecord-sqlanywhere-adapter
2
+ ===========================
3
+
4
+ This is an ActiveRecord adapter for Sybase SQLAnywhere.
5
+
@@ -0,0 +1,46 @@
1
+ require 'bundler'
2
+
3
+ def install_tasks(opts = nil)
4
+ dir = caller.find{|c| /Rakefile:/}[/^(.*?)\/Rakefile:/, 1]
5
+ h = Bundler::GemHelper.new(dir, opts && opts[:name])
6
+ h.install
7
+ h
8
+ end
9
+ helper = install_tasks
10
+ spec = helper.gemspec
11
+
12
+ require 'rake/clean'
13
+ CLEAN.include 'test/reports','lib/**/*.jar','*.log', 'pkg'
14
+
15
+ task :git_local_check do
16
+ sh "git diff --no-ext-diff --ignore-submodules --quiet --exit-code" do |ok, _|
17
+ raise "working directory is unclean" if !ok
18
+ sh "git diff-index --cached --quiet --ignore-submodules HEAD --" do |ok, _|
19
+ raise "git index is unclean" if !ok
20
+ end
21
+ end
22
+ end
23
+ task :build => [:java_compile, :git_local_check]
24
+
25
+ require 'rake/testtask'
26
+ Rake::TestTask.new(:test) do |test|
27
+ test.libs << 'lib' << 'test'
28
+ ar_jdbc = ENV['AR_JDBC'] ||
29
+ (begin
30
+ gem 'activerecord-jdbc-adapter'
31
+ Gem.loaded_specs['activerecord-jdbc-adapter'].full_gem_path
32
+ rescue
33
+ raise "Please install activerecord-jdbc-adapter to run tests."
34
+ end)
35
+ test.libs << File.join(ar_jdbc, 'test')
36
+ test.pattern = 'test/**/*test*.rb'
37
+ test.verbose = true
38
+ end
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "#{spec.name} #{spec.version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/activerecord-jdbcsqlanywhere-adapter", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "activerecord-jdbcsqlanywhere-adapter"
6
+ s.version = ArJdbc::SybaseSQLAnywhere::VERSION
7
+ s.author = 'Brian Olsen'
8
+ s.email = 'brian@maven-group.org'
9
+ s.homepage = "http://github.com/griff/activerecord-jdbcsqlanywhere-adapter"
10
+ s.summary = "Sybase SQLAnywhere JDBC adapter for JRuby on Rails"
11
+ s.description = "Install this gem to use Sybase SQLAnywhere with JRuby on Rails"
12
+
13
+ s.required_rubygems_version = ">= 1.3.6"
14
+
15
+ s.add_dependency('activerecord-jdbc-adapter', "~> 1.1.1")
16
+ s.add_development_dependency "bundler", ">= 1.0.0"
17
+
18
+ s.files = `git ls-files`.split("\n") << 'lib/arjdbc/sqlanywhere/adapter_java.jar'
19
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
20
+ s.require_path = 'lib'
21
+ end
@@ -0,0 +1 @@
1
+ require 'arjdbc/sqlanywhere'
@@ -0,0 +1,5 @@
1
+ module ArJdbc
2
+ module SybaseSQLAnywhere
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ module ::ArJdbc
2
+ extension :SybaseSQLAnywhere do |name|
3
+ if name =~ /sqlanywhere/i
4
+ require 'arjdbc/sqlanywhere'
5
+ true
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ require 'arjdbc/jdbc'
2
+ require 'arjdbc/sqlanywhere/connection_methods'
3
+ require 'arjdbc/sqlanywhere/adapter_java'
4
+ require 'arjdbc/sqlanywhere/adapter'
@@ -0,0 +1,17 @@
1
+ module ::ArJdbc
2
+ module SybaseSQLAnywhere
3
+ def self.jdbc_connection_class
4
+ ::ActiveRecord::ConnectionAdapters::SQLAnywhereJdbcConnection
5
+ end
6
+
7
+ def self.column_selector
8
+ [/sqlanywhere/i, lambda {|cfg,col| col.extend(::ArJdbc::SybaseSQLAnywhere::Column)}]
9
+ end
10
+
11
+ module Column
12
+ def init_column(name, default, *args)
13
+ @name = name.downcase
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class ActiveRecord::Base
2
+ class << self
3
+ def sqlanywhere_connection( config )
4
+ config[:port] ||= 2638
5
+ config[:url] ||= "jdbc:sybase:Tds:#{config[:server]}:#{config[:port]}?serviceName=#{config[:database]}"
6
+ config[:driver] ||= "com.sybase.jdbc3.jdbc.SybDriver"
7
+ config[:dialect] = "sqlanywhere"
8
+ jdbc_connection(config)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ def java_classpath_arg # myriad of ways to discover JRuby classpath
2
+ begin
3
+ cpath = Java::java.lang.System.getProperty('java.class.path').split(File::PATH_SEPARATOR)
4
+ cpath += Java::java.lang.System.getProperty('sun.boot.class.path').split(File::PATH_SEPARATOR)
5
+ jruby_cpath = cpath.compact.join(File::PATH_SEPARATOR)
6
+ rescue => e
7
+ end
8
+ unless jruby_cpath
9
+ jruby_cpath = ENV['JRUBY_PARENT_CLASSPATH'] || ENV['JRUBY_HOME'] &&
10
+ FileList["#{ENV['JRUBY_HOME']}/lib/*.jar"].join(File::PATH_SEPARATOR)
11
+ end
12
+ jruby_cpath += File::PATH_SEPARATOR + Gem.find_files('arjdbc/jdbc/adapter_java.jar').join(File::PATH_SEPARATOR)
13
+ jruby_cpath ? "-cp \"#{jruby_cpath}\"" : ""
14
+ end
15
+
16
+ jar_name = File.join(*%w(lib arjdbc sqlanywhere adapter_java.jar))
17
+
18
+ desc "Compile the native Java code."
19
+ task :java_compile do
20
+ debug = ENV['DEBUG'] ? '-g' : ''
21
+ pkg_classes = File.join(*%w(pkg classes))
22
+ mkdir_p pkg_classes
23
+
24
+ sh "javac -target 1.5 -source 1.5 #{debug} -d pkg/classes #{java_classpath_arg} #{FileList['src/java/**/*.java'].join(' ')}"
25
+ sh "jar cf #{jar_name} -C #{pkg_classes} ."
26
+ end
27
+ file jar_name => :java_compile
@@ -0,0 +1,49 @@
1
+ /*
2
+ **** BEGIN LICENSE BLOCK *****
3
+ * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
4
+ * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
5
+ * Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
6
+ * Copyright (c) 2011 Brian Olsen <brian@maven-group.org>
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining
9
+ * a copy of this software and associated documentation files (the
10
+ * "Software"), to deal in the Software without restriction, including
11
+ * without limitation the rights to use, copy, modify, merge, publish,
12
+ * distribute, sublicense, and/or sell copies of the Software, and to
13
+ * permit persons to whom the Software is furnished to do so, subject to
14
+ * the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be
17
+ * included in all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ ***** END LICENSE BLOCK *****/
27
+
28
+ package arjdbc.sqlanywhere;
29
+
30
+ import java.io.IOException;
31
+
32
+ import org.jruby.Ruby;
33
+ import org.jruby.RubyClass;
34
+ import org.jruby.RubyModule;
35
+ import org.jruby.RubyObjectAdapter;
36
+ import org.jruby.javasupport.JavaEmbedUtils;
37
+ import org.jruby.runtime.load.BasicLibraryService;
38
+
39
+ import arjdbc.jdbc.RubyJdbcConnection;
40
+
41
+ public class AdapterJavaService implements BasicLibraryService {
42
+ private static RubyObjectAdapter rubyApi;
43
+
44
+ public boolean basicLoad(final Ruby runtime) throws IOException {
45
+ RubyClass jdbcConnection = RubyJdbcConnection.createJdbcConnectionClass(runtime);
46
+ SQLAnywhereRubyJdbcConnection.createSQLAnywhereJdbcConnectionClass(runtime, jdbcConnection);
47
+ return true;
48
+ }
49
+ }
@@ -0,0 +1,85 @@
1
+ /*
2
+ **** BEGIN LICENSE BLOCK *****
3
+ * Copyright (c) 2006-2010 Nick Sieger <nick@nicksieger.com>
4
+ * Copyright (c) 2006-2007 Ola Bini <ola.bini@gmail.com>
5
+ * Copyright (c) 2008-2009 Thomas E Enebo <enebo@acm.org>
6
+ * Copyright (c) 2011 Brian Olsen <brian@maven-group.org>
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining
9
+ * a copy of this software and associated documentation files (the
10
+ * "Software"), to deal in the Software without restriction, including
11
+ * without limitation the rights to use, copy, modify, merge, publish,
12
+ * distribute, sublicense, and/or sell copies of the Software, and to
13
+ * permit persons to whom the Software is furnished to do so, subject to
14
+ * the following conditions:
15
+ *
16
+ * The above copyright notice and this permission notice shall be
17
+ * included in all copies or substantial portions of the Software.
18
+ *
19
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ ***** END LICENSE BLOCK *****/
27
+
28
+ package arjdbc.sqlanywhere;
29
+
30
+ import java.sql.DatabaseMetaData;
31
+ import java.sql.ResultSet;
32
+ import java.sql.SQLException;
33
+ import java.sql.Statement;
34
+ import java.sql.Types;
35
+
36
+ import arjdbc.jdbc.RubyJdbcConnection;
37
+
38
+ import org.jruby.Ruby;
39
+ import org.jruby.RubyClass;
40
+ import org.jruby.runtime.ObjectAllocator;
41
+ import org.jruby.runtime.ThreadContext;
42
+ import org.jruby.runtime.builtin.IRubyObject;
43
+
44
+ /**
45
+ *
46
+ * @author brianolsen
47
+ */
48
+ public class SQLAnywhereRubyJdbcConnection extends RubyJdbcConnection {
49
+ protected SQLAnywhereRubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
50
+ super(runtime, metaClass);
51
+ }
52
+
53
+ public static RubyClass createSQLAnywhereJdbcConnectionClass(Ruby runtime, RubyClass jdbcConnection) {
54
+ RubyClass clazz = RubyJdbcConnection.getConnectionAdapters(runtime).defineClassUnder("SQLAnywhereJdbcConnection",
55
+ jdbcConnection, SQLANYWHERE_JDBCCONNECTION_ALLOCATOR);
56
+ clazz.defineAnnotatedMethods(SQLAnywhereRubyJdbcConnection.class);
57
+
58
+ return clazz;
59
+ }
60
+
61
+ private static ObjectAllocator SQLANYWHERE_JDBCCONNECTION_ALLOCATOR = new ObjectAllocator() {
62
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
63
+ return new SQLAnywhereRubyJdbcConnection(runtime, klass);
64
+ }
65
+ };
66
+
67
+ /**
68
+ * Treat LONGVARCHAR as CLOB on Informix for purposes of converting a JDBC value to Ruby.
69
+ */
70
+ @Override
71
+ protected IRubyObject jdbcToRuby(Ruby runtime, int column, int type, ResultSet resultSet)
72
+ throws SQLException {
73
+ if (type == Types.LONGVARCHAR) {
74
+ type = Types.CLOB;
75
+ }
76
+ return super.jdbcToRuby(runtime, column, type, resultSet);
77
+ }
78
+
79
+ @Override
80
+ protected IRubyObject unmarshalResults(ThreadContext context, DatabaseMetaData metadata,
81
+ Statement stmt, boolean downCase) throws SQLException {
82
+ return super.unmarshalResults(context, metadata, stmt, true);
83
+ }
84
+
85
+ }
@@ -0,0 +1,9 @@
1
+ config = {
2
+ :username => 'dba',
3
+ :password => 'weblog',
4
+ :adapter => 'sqlanywhere',
5
+ :host => ENV[ "SQLANYWHERE_HOST" ] || 'localhost',
6
+ :database => ENV[ "SQLANYWHERE_NAMESPACE" ] || 'weblog_development'
7
+ }
8
+
9
+ ActiveRecord::Base.establish_connection( config )
@@ -0,0 +1,6 @@
1
+ require 'jdbc_common'
2
+ require 'db/sqlanywhere'
3
+
4
+ class SQLAnywhereSimpleTest < Test::Unit::TestCase
5
+ include SimpleTestMethods
6
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-jdbcsqlanywhere-adapter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Brian Olsen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-09 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activerecord-jdbc-adapter
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 1
30
+ - 1
31
+ version: 1.1.1
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 0
44
+ - 0
45
+ version: 1.0.0
46
+ type: :development
47
+ version_requirements: *id002
48
+ description: Install this gem to use Sybase SQLAnywhere with JRuby on Rails
49
+ email: brian@maven-group.org
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - .gitignore
58
+ - Gemfile
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - activerecord-jdbcsqlanywhere-adapter.gemspec
63
+ - lib/active_record/connection_adapters/sqlanywhere_adapter.rb
64
+ - lib/activerecord-jdbcsqlanywhere-adapter.rb
65
+ - lib/arjdbc/discover.rb
66
+ - lib/arjdbc/sqlanywhere.rb
67
+ - lib/arjdbc/sqlanywhere/adapter.rb
68
+ - lib/arjdbc/sqlanywhere/connection_methods.rb
69
+ - rakelib/compile.rake
70
+ - src/java/arjdbc/sqlanywhere/AdapterJavaService.java
71
+ - src/java/arjdbc/sqlanywhere/SQLAnywhereRubyJdbcConnection.java
72
+ - test/db/sqlanywhere.rb
73
+ - test/sqlanywhere_simple_test.rb
74
+ - lib/arjdbc/sqlanywhere/adapter_java.jar
75
+ has_rdoc: true
76
+ homepage: http://github.com/griff/activerecord-jdbcsqlanywhere-adapter
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options: []
81
+
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 1
97
+ - 3
98
+ - 6
99
+ version: 1.3.6
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.6
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Sybase SQLAnywhere JDBC adapter for JRuby on Rails
107
+ test_files: []
108
+