Permalink
Browse files

database connection pool for Trinidad

  • Loading branch information...
1 parent be7b8f0 commit 47fb2c5133992d26977b0a3d241af00aa6e19929 @calavera committed Mar 23, 2010
View
1 .gitignore
@@ -19,3 +19,4 @@ rdoc
pkg
## PROJECT::SPECIFIC
+*.gemspec
View
44 Rakefile
@@ -1,22 +1,58 @@
require 'rubygems'
require 'rake'
+namespace :dbpool do
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "trinidad-dbpool"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
- gem.email = "david.calavera@gmail.com"
+ gem.summary = %Q{Addon to support database pools in Trinidad}
+ gem.description = %Q{Addon to support database pools in Trinidad}
+ gem.email = "calavera@apache.org"
gem.homepage = "http://github.com/calavera/trinidad-dbpool"
gem.authors = ["David Calavera"]
+ gem.add_dependency "trinidad_jars"
+
gem.add_development_dependency "rspec", ">= 1.2.9"
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+
+ gem.files = FileList['lib/trinidad-dbpool.rb', 'lib/trinidad-dbpool/webapp_addon.rb', 'LICENSE', 'README.rdoc', 'VERSION']
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end
+end
+
+namespace :mysql_dbpool do
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = "trinidad-mysql-dbpool-extension"
+ gem.summary = %Q{Addon to support MySql database pools in Trinidad}
+ gem.description = %Q{Addon to support MySql database pools in Trinidad}
+ gem.email = "calavera@apache.org"
+ gem.homepage = "http://github.com/calavera/trinidad-dbpool"
+ gem.authors = ["David Calavera"]
+ gem.add_dependency "trinidad-dbpool"
+ gem.add_development_dependency "rspec", ">= 1.2.9"
+
+ gem.files = FileList['lib/trinidad-mysql-dbpool-extension.rb',
+ 'lib/trinidad-mysql-dbpool-extension/mysql_webapp_addon.rb',
+ 'trinidad-libs/mysql-connector-java-5.1.12-bin.jar',
+ 'LICENSE', 'README.rdoc', 'VERSION']
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
+end
+
+task :build => ["dbpool:build", "mysql_dbpool:build"]
+
+task :install do
+
+ `jruby -S gem install pkg/trinidad-dbpool-0.1.0.gem pkg/trinidad-mysql-dbpool-extension-0.1.0.gem --no-ri --no-rdoc`
+end
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
View
1 VERSION
@@ -0,0 +1 @@
+0.1.0
View
9 lib/trinidad-dbpool.rb
@@ -0,0 +1,9 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+require 'java'
+require 'rubygems'
+gem 'trinidad_jars'
+
+require 'trinidad/jars'
+require 'trinidad-dbpool/webapp_addon'
View
17 lib/trinidad-dbpool/webapp_addon.rb
@@ -0,0 +1,17 @@
+module Trinidad
+ class DbpoolWebAppAddon
+ def self.configure_internal(app_context, options)
+ options[:type] = "javax.sql.DataSource"
+
+ resource = Trinidad::Tomcat::ContextResource.new
+ resource.setAuth("Container")
+ resource.setName(options.delete('name'))
+ resource.setDescription(options.delete('description')) if options['description']
+ options.each do |key, value|
+ resource.setProperty(key.to_s, value.to_s)
+ end
+
+ resource
+ end
+ end
+end
View
12 lib/trinidad-mysql-dbpool-extension.rb
@@ -0,0 +1,12 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+$:.unshift(File.dirname(__FILE__) + '/../trinidad-libs')
+
+require 'java'
+require 'rubygems'
+require 'trinidad-dbpool'
+
+require 'mysql-connector-java-5.1.12-bin'
+
+require 'trinidad-mysql-dbpool-extension/mysql_webapp_addon'
View
20 lib/trinidad-mysql-dbpool-extension/mysql_webapp_addon.rb
@@ -0,0 +1,20 @@
+module Trinidad
+ class MysqlDbpoolWebAppAddon < DbpoolWebAppAddon
+ def self.configure(*args)
+ puts 'Configuring Mysql connection pool'
+ args = args.flatten
+ configure_internal(args[0], args[1], args[2])
+ end
+
+ def self.configure_internal(app_context, class_loader, options)
+ resource = DbpoolWebAppAddon.configure_internal(app_context, options)
+
+ mysql_driver_jar = File.dirname(__FILE__) + '/../../trinidad-libs/mysql-connector-java-5.1.12-bin.jar'
+ class_loader.addURL(java.io.File.new(mysql_driver_jar).to_url)
+
+ resource.setProperty("driverClassName", "com.mysql.jdbc.Driver")
+
+ app_context.naming_resources.add_resource(resource)
+ end
+ end
+end
View
BIN trinidad-libs/mysql-connector-java-5.1.12-bin.jar
Binary file not shown.

0 comments on commit 47fb2c5

Please sign in to comment.