Permalink
Browse files

Initial commit

  • Loading branch information...
nicksieger committed Oct 7, 2010
0 parents commit ab866704bc0eedfc7b72044f9b6099bd2915e0dc
25 LICENSE
@@ -0,0 +1,25 @@
+Note that this license covers the code used to connect ActiveRecord to
+the Cache DB only, and not the Cache drivers or database itself, which
+must be obtained from www.intersystems.com.
+
+The MIT License
+
+Copyright (c) 2010 Nick Sieger
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,4 @@
+activerecord-cachedb-adapter
+===========================
+
+
115 Rakefile
@@ -0,0 +1,115 @@
+require 'rubygems'
+require 'rake'
+require 'date'
+
+#############################################################################
+#
+# Helper functions
+#
+#############################################################################
+
+def name
+ @name ||= Dir['*.gemspec'].first.split('.').first
+end
+
+def version
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
+end
+
+def date
+ Date.today.to_s
+end
+
+def rubyforge_project
+ "jruby-extras"
+end
+
+def gemspec_file
+ "#{name}.gemspec"
+end
+
+def gem_file
+ "#{name}-#{version}.gem"
+end
+
+def replace_header(head, header_name)
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
+end
+
+#############################################################################
+#
+# Standard tasks
+#
+#############################################################################
+
+task :default => :test
+
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ ar_jdbc = ENV['AR_JDBC'] ||
+ (begin
+ gem 'activerecord-jdbc-adapter'
+ Gem.loaded_specs['activerecord-jdbc-adapter'].full_gem_path
+ rescue
+ raise "Please install activerecord-jdbc-adapter to run tests."
+ end)
+ test.libs << File.join(ar_jdbc, 'test')
+ test.pattern = 'test/**/*test*.rb'
+ test.verbose = true
+end
+
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "#{name} #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
+
+task :release => :build do
+ unless `git branch` =~ /^\* master$/
+ puts "You must be on the master branch to release!"
+ exit!
+ end
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
+ sh "git tag v#{version}"
+ sh "git push origin master"
+ sh "git push origin v#{version}"
+ sh "gem push pkg/#{name}-#{version}.gem"
+end
+
+task :build => :gemspec do
+ sh "mkdir -p pkg"
+ sh "gem build #{gemspec_file}"
+ sh "mv #{gem_file} pkg"
+end
+
+task :gemspec do
+ # read spec file and split out manifest section
+ spec = File.read(gemspec_file)
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
+
+ # replace name version and date
+ replace_header(head, :name)
+ replace_header(head, :version)
+ replace_header(head, :date)
+ #comment this out if your rubyforge_project has a different name
+ replace_header(head, :rubyforge_project)
+
+ # determine file list from git ls-files
+ files = `git ls-files`.
+ split("\n").
+ sort.
+ reject { |file| file =~ /^\./ }.
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
+ map { |file| " #{file}" }.
+ join("\n")
+
+ # piece file back together and write
+ manifest = " s.files = %w[\n#{files}\n ]\n"
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
+ puts "Updated #{gemspec_file}"
+end
@@ -0,0 +1,37 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = 'activerecord-cachedb-adapter'
+ s.version = '0.1'
+ s.date = '2010-10-07'
+
+ s.platform = Gem::Platform.new([nil, "java", nil])
+ s.rubyforge_project = %q{jruby-extras}
+
+ s.summary = "ActiveRecord adapter for Intersystems CacheDb."
+ s.description = "ActiveRecord adapter for Intersystems CacheDb. Only for use with JRuby. Requires separate Cache JDBC driver."
+
+ s.authors = ["Nick Sieger"]
+ s.email = 'nick@nicksieger.com'
+ s.homepage = 'http://jruby-extras.rubyforge.org/activerecord-jdbc-adapter'
+ s.require_paths = %w[lib]
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.extra_rdoc_files = %w[README.md LICENSE]
+
+ # = MANIFEST =
+ s.files = %w[
+
+ ]
+ # = MANIFEST =
+
+ s.test_files = s.files.select { |path| path =~ /^test\/(.*test.*\.rb/ }
+
+ s.add_dependency(%q<activerecord-jdbc-adapter>, [">= 1.0.0"])
+
+ s.rubygems_version = %q{1.3.7}
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+ end
+end
@@ -0,0 +1 @@
+require 'arjdbc/cachedb'
@@ -0,0 +1,5 @@
+module ArJdbc
+ module CacheDb
+ VERSION = "0.1"
+ end
+end
@@ -0,0 +1,3 @@
+require 'arjdbc/jdbc'
+require 'arjdbc/cachedb/connection_methods'
+require 'arjdbc/cachedb/adapter'
@@ -0,0 +1,20 @@
+require 'arjdbc/mssql/tsql_helper'
+
+module ::ArJdbc
+ module CacheDB
+ include TSqlMethods
+
+ def self.column_selector
+ [ /cache/i, lambda { | cfg, col | col.extend( ::ArJdbc::CacheDB::Column ) } ]
+ end
+
+ module Column
+ end
+
+ def create_table(name, options = { })
+ super(name, options)
+ primary_key = options[:primary_key] || "id"
+ execute "ALTER TABLE #{name} ADD CONSTRAINT #{name}_PK PRIMARY KEY(#{primary_key})" unless options[:id] == false
+ end
+ end
+end
@@ -0,0 +1,10 @@
+class ActiveRecord::Base
+ class << self
+ def cachedb_connection( config )
+ config[:port] ||= 1972
+ config[:url] ||= "jdbc:Cache://#{config[:host]}:#{config[:port]}/#{ config[:database]}"
+ config[:driver] ||= "com.intersys.jdbc.CacheDriver"
+ jdbc_connection(config)
+ end
+ end
+end
@@ -0,0 +1,11 @@
+# arjdbc/discover.rb: Declare ArJdbc.extension modules in this file
+# that loads a custom module and adapter.
+
+module ::ArJdbc
+ extension :CacheDB do |name|
+ if name =~ /cache/i
+ require 'arjdbc/cachedb'
+ true
+ end
+ end
+end
@@ -0,0 +1,6 @@
+require 'jdbc_common'
+require 'db/cachedb'
+
+class CacheDBSimpleTest < Test::Unit::TestCase
+ include SimpleTestMethods
+end
@@ -0,0 +1,9 @@
+config = {
+ :username => '_SYSTEM',
+ :password => 'SYS',
+ :adapter => 'cachedb',
+ :host => ENV[ "CACHE_HOST" ] || 'localhost',
+ :database => ENV[ "CACHE_NAMESPACE" ] || 'weblog_development'
+}
+
+ActiveRecord::Base.establish_connection( config )

0 comments on commit ab86670

Please sign in to comment.