Skip to content
Browse files

Merge pull request #2 from patcheng/4bffb0e1325f1dec97431554c79edb8c2…

…7ce28f4

ability to create JNDI using any class without keep adding different extension
  • Loading branch information...
2 parents 11fa7b8 + 4bffb0e commit 3851c389d2032986c5118931c972fa5cd64df59c @calavera calavera committed Feb 17, 2012
View
2 lib/trinidad_dbpool/webapp_extension.rb
@@ -16,6 +16,8 @@ def create_resource tomcat, app_context, opts
url = opts.delete(:url)
url = protocol + url unless %r{^#{protocol}} =~ url
opts[:url] = url
+
+ driver_name = opts.delete(:driver) || self.driver_name
resource = Trinidad::Tomcat::ContextResource.new
resource.set_auth(opts.delete(:auth)) if opts.key?(:auth)
View
2 lib/trinidad_generic_dbpool_extension.rb
@@ -0,0 +1,2 @@
+require 'trinidad_dbpool'
+require 'trinidad_generic_dbpool_extension/generic_webapp_extension'
View
13 lib/trinidad_generic_dbpool_extension/generic_webapp_extension.rb
@@ -0,0 +1,13 @@
+module Trinidad
+ module Extensions
+ class GenericDbpoolWebAppExtension < DbpoolWebAppExtension
+ def driver_name
+ nil
+ end
+
+ def protocol
+ 'jdbc:'
+ end
+ end
+ end
+end
View
28 spec/trinidad_generic_dbpool_extension_spec.rb
@@ -0,0 +1,28 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe Trinidad::Extensions::GenericDbpoolWebAppExtension do
+ include DbpoolExampleHelperMethods
+
+ before(:each) do
+ @defaults = { :jndi => 'jdbc/TestDB', :url => '' }
+ @tomcat = mock_tomcat
+ @context = build_context
+ end
+
+ it "sets the generic driver name as a resource property" do
+ extension = build_extension @defaults
+ resources = extension.configure(@tomcat, @context)
+ resources.should be_only_and_have_property('driverClassName', nil)
+ end
+
+ it "adds the protocol if the url doesn't include it" do
+ options = @defaults.merge :url => 'localhost:3306/without_protocol'
+ extension = build_extension options
+ resources = extension.configure(@tomcat, @context)
+ resources.should be_only_and_have_property('url', "jdbc:#{options[:url]}")
+ end
+
+ def build_extension options
+ Trinidad::Extensions::MysqlDbpoolWebAppExtension.new options
+ end
+end
View
55 trinidad_generic_dbpool_extension.gemspec
@@ -0,0 +1,55 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{trinidad_generic_dbpool_extension}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["David Calavera"]
+ s.date = %q{2010-05-05}
+ s.description = %q{Addon to support Generic database pools in Trinidad}
+ s.email = %q{calavera@apache.org}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.rdoc"
+ ]
+ s.files = [
+ "LICENSE",
+ "README.rdoc",
+ "VERSION",
+ "lib/trinidad_generic_dbpool_extension.rb",
+ "lib/trinidad_generic_dbpool_extension/generic_webapp_extension.rb"
+ ]
+ s.homepage = %q{http://github.com/calavera/trinidad-dbpool}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.6}
+ s.summary = %q{Addon to support Generic database pools in Trinidad}
+ s.test_files = [
+ "spec/spec_helper.rb",
+ "spec/trinidad_generic_dbpool_extension_spec.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<trinidad_dbpool>, [">= 0"])
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_development_dependency(%q<mocha>, [">= 0"])
+ else
+ s.add_dependency(%q<trinidad_dbpool>, [">= 0"])
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_dependency(%q<mocha>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<trinidad_dbpool>, [">= 0"])
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
+ s.add_dependency(%q<mocha>, [">= 0"])
+ end
+end
+

0 comments on commit 3851c38

Please sign in to comment.
Something went wrong with that request. Please try again.