trinidad_dbpool 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,27 @@
1
+ == 0.4.2 (2012-12-22)
2
+
3
+ * updated tomcat-dbcp.jar to 7.0.32
4
+ * support multiple jar files (and globbing) with driver path
5
+ * trinidad_mssql_dbpool_extension jTDS jar updated to 1.3.0
6
+
7
+ == 0.4.1 (2012-11-29)
8
+
9
+ * updated driver jars for following :
10
+ - trinidad_mysql_dbpool_extension
11
+ - trinidad_postgresql_dbpool_extension
12
+ - trinidad_mssql_dbpool_extension
13
+ * added trinidad_sqlite_dbpool_extension
14
+
15
+ == 0.4.0 (2012-05-31)
16
+
17
+ * revised trinidad_generic_dbpool_extension :
18
+ - driver configuration option aliased as driverName
19
+ - new driverPath option for specifying driver jar in configuration
20
+ - allow driverName to be auto resolved when driverPath specified
21
+ * trinidad_postgresql_dbpool_extension with driver updated to 9.1-902
22
+ * trinidad_mysql_dbpool_extension with mysql-connector-j 5.1.20
23
+ * code cleanup, get rid of jeweler, update tomcat-dbcp.jar for trinidad_dbpool
24
+
1
25
  == 0.3.0 (2011-07-01)
2
26
 
3
27
  * Oracle connection pool extension
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2012 David Calavera
1
+ Copyright (c) 2012 Team Trinidad and contributors http://github.com/trinidad
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -18,3 +18,8 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ == JDBC Driver
23
+
24
+ Included JDBC drivers are most likely distributed under different terms than
25
+ those above, please make sure you understand your driver's license terms.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # Trinidad Database Pool
2
+
3
+ A bunch of Trinidad extensions to support database connection pooling on top of
4
+ the underlying Apache Tomcat container (using Tomcat's JDBC Connection Pool).
5
+
6
+ Please note, that such pools are usually configured as "global" and thus
7
+ shareable by multiple applications deployed on to of the Trinidad server.
8
+
9
+ Also most Java issues caused by JDBC drivers packaged with the application (e.g.
10
+ `java.lang.UnsatisfiedLinkError` with SQLite3's JDBC driver) that JRuby inherits
11
+ should go away when database connections are managed externally.
12
+
13
+ http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
14
+
15
+ ## Available Pools
16
+
17
+ * MySQL (trinidad_mysql_dbpool_extension)
18
+ * PostgreSQL (trinidad_postgresql_dbpool_extension)
19
+ * SQLite (trinidad_sqlite_dbpool_extension)
20
+ * MS-SQL (trinidad_mssql_dbpool_extension) using (unofficial) jTDS driver
21
+ * Oracle (trinidad_oracle_dbpool_extension)
22
+ * Generic (trinidad_generic_dbpool_extension) in case your DB ain't supported
23
+
24
+ ## Usage
25
+
26
+ * Install the gem e.g. `jruby -S gem install trinidad_mysql_dbpool_extension`
27
+ * Configure the pool with Trinidad's configuration file e.g. :
28
+
29
+ ```yml
30
+ web_apps:
31
+ default:
32
+ extensions:
33
+ mysql_dbpool: # EXTENSION NAME AS KEY
34
+ jndi: 'jdbc/TestDB' # name (linked with database.yml)
35
+ url: 'localhost:3306/javatest' # database URL (or full jdbc: URL)
36
+ username: 'root' # database username
37
+ password: 'root' # database password
38
+ maxActive: 100 # max nodes actives
39
+ maxIdle: 30 # max nodes idles
40
+ maxWait: 10000 # max nodes waiting
41
+ ```
42
+
43
+ **jndi**, **url** are mandatory (as well **username** and **password** if your
44
+ database server + driver requires authentication), while other supported
45
+ configuration options might be found here in Tomcat's "datasource" how-to:
46
+
47
+ http://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html
48
+
49
+ http://commons.apache.org/dbcp/configuration.html
50
+
51
+ If you happen to be using *SQLite* on production you'll need an absolute path :
52
+
53
+ ```yml
54
+ extensions:
55
+ sqlite_dbpool:
56
+ jndi: jdbc/FileDB
57
+ url: <%= File.expand_path('db/production.db') %>
58
+ ```
59
+
60
+ * Configure the (Rails) application to use JNDI with *config/database.yml*
61
+
62
+ ```yml
63
+ production:
64
+ adapter: jdbc # it will detect the adapter spec e.g. `ArJdbc::MySQL`
65
+ jndi: java:/comp/env/jdbc/TestDB
66
+ # (Java) JDBC driver class name is detected for built-in adapters that
67
+ # activerecord-jdbc-adapter supports, specify for a "generic" adapter
68
+ #driver: com.mysql.jdbc.Driver
69
+ ```
70
+
71
+ do not forget to delete **pool** setup part since there's no need for it ...
72
+
73
+ ## Generic Pool
74
+
75
+ If there's no "official" pool for your database, or would like to use a
76
+ different version of a JDBC driver for a supported Trinidad pool, this allows
77
+ you to completely customize a pool.
78
+
79
+ NOTE: You will need a JDBC driver for your database, check the driver DB if
80
+ unsure about how to get one http://developers.sun.com/product/jdbc/drivers
81
+
82
+ Sample configuration for a DB2 database :
83
+
84
+ ```yml
85
+ ---
86
+ extensions:
87
+ generic_dbpool: # EXTENSION NAME AS KEY
88
+ jndi: 'jdbc/MyDB' # JNDI name
89
+ url: 'jdbc:db2://127.0.0.1:50000/MYDB' # specify full jdbc: URL
90
+ username: 'mydb' # database username
91
+ password: 'pass' # database password
92
+ driverPath: '/opt/IBM/DB2/db2jcc4.jar' # leave out if on class-path
93
+ driverName: com.ibm.db2.jcc.DB2Driver # resolved from driverPath jar
94
+ ```
95
+
96
+ Beyond standard configuration options there's 2 specific options here :
97
+
98
+ * **driverPath** should be a path to your JDBC driver archive, might leave that
99
+ out but make sure it's on the (shared) class-path for each and every deployed
100
+ application that requires it. You might specify multiple jars using the
101
+ `Dir.glob` syntax or by separating paths using the `:` separator.
102
+
103
+ Also in case *driverPath* is omitted you'll need to specify a *driverName* !
104
+
105
+ * **driverName** the class name implementing the JDBC driver interface, if
106
+ you're not sure check the .jar for a META-INF/services/java.sql.Driver file.
107
+ If present that file contains the class-name and you might leave *driverName*
108
+ blank if you specified the jar path using *driverPath* but you're going still
109
+ going to need the driver name in your *database.yml*
110
+
111
+ ## Copyright
112
+
113
+ Copyright (c) 2012 [Team Trinidad](https://github.com/trinidad).
114
+ See LICENSE (http://en.wikipedia.org/wiki/MIT_License) for details.
data/Rakefile CHANGED
@@ -1,68 +1,107 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ begin
2
+ require 'bundler/gem_helper'
3
+ rescue LoadError => e
4
+ require('rubygems') && retry
5
+ raise e
6
+ end
7
+
8
+ task :default => :spec
3
9
 
4
- def build(gem)
5
- mkdir_p 'pkg'
6
- sh "gem build #{gem}.gemspec"
7
- mv Dir["#{gem}*.gem"].last, 'pkg'
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new(:spec) do |spec|
12
+ spec.rspec_opts = ['--color', "--format documentation"]
8
13
  end
9
14
 
10
- def release(gem, version = nil)
11
- unless `git branch` =~ /^\* master$/
12
- raise "must be on master to release !"
15
+ desc "Clear out all built (pkg/* and *.gem) artifacts"
16
+ task :clear do
17
+ rm Dir["*.gem"]
18
+ rm_r Dir["pkg/*"] if File.exist?("pkg")
19
+ end
20
+ task :clean => :clear
21
+
22
+ all_gems = %W{
23
+ dbpool
24
+ generic_dbpool_extension
25
+ mysql_dbpool_extension
26
+ postgresql_dbpool_extension
27
+ sqlite_dbpool_extension
28
+ mssql_dbpool_extension
29
+ oracle_dbpool_extension
30
+ }.map { |gem| "trinidad_#{gem}" }
31
+
32
+ all_gems.each do |gem_name|
33
+
34
+ gem_helper = Bundler::GemHelper.new(Dir.pwd, gem_name)
35
+ def gem_helper.version_tag
36
+ "#{name}-#{version}" # override "v#{version}"
13
37
  end
38
+ version = gem_helper.send(:version)
39
+ version_tag = gem_helper.version_tag
14
40
 
15
- if version
16
- unless gem_file = Dir.glob("pkg/#{gem}-#{version}.gem").first
17
- raise "#{gem}-#{version}.gem not build !"
18
- end
19
- else
20
- unless gem_file = Dir.glob("pkg/#{gem}*").sort.last
21
- raise "#{gem}*.gem not build !"
22
- end
23
- unless match = gem_file.match(/.*?\-(\d\.\d\.\d)\.gem/)
24
- raise "version number not matched from: #{gem_file}"
25
- end
26
- version = match[1]
41
+ namespace gem_name do
42
+ desc "Build #{gem_name}-#{version}.gem into the pkg directory"
43
+ task('build') { gem_helper.build_gem }
44
+
45
+ desc "Build and install #{gem_name}-#{version}.gem into system gems"
46
+ task('install') { gem_helper.install_gem }
47
+
48
+ desc "Create tag #{version_tag} and build and push #{gem_name}-#{version}.gem to Rubygems"
49
+ task('release') { gem_helper.release_gem }
27
50
  end
28
51
 
29
- sh "git tag #{gem}-#{version}"
30
- sh "git push origin master --tags"
31
- sh "gem push #{gem_file}"
32
52
  end
33
53
 
34
- all_gems = %W{ dbpool mysql_dbpool_extension postgresql_dbpool_extension mssql_dbpool_extension oracle_dbpool_extension }
35
- all_gems.map! { |gem| "trinidad_#{gem}" }
36
- all_gems.each do |gem_name|
37
- namespace gem_name do
38
- desc "Build the #{gem_name} gem"
39
- task :build do
40
- build(gem_name)
54
+ namespace :all do
55
+ desc "Build all gems into the pkg directory"
56
+ task 'build' => all_gems.map { |gem_name| "#{gem_name}:build" }
57
+
58
+ desc "Build and install all gems into system gems"
59
+ task 'install' => all_gems.map { |gem_name| "#{gem_name}:install" }
60
+ end
61
+
62
+ namespace :'tomcat-dbcp' do
63
+
64
+ TOMCAT_MAVEN_REPO = 'http://repo2.maven.org/maven2/org/apache/tomcat'
65
+
66
+ TRINIDAD_LIBS = File.expand_path('./trinidad-libs', File.dirname(__FILE__))
67
+
68
+ dbcp_jar = "tomcat-dbcp.jar"
69
+
70
+ task :download, :version do |_, args|
71
+ version = [ args[:version] ]
72
+
73
+ dbcp_uri = "#{TOMCAT_MAVEN_REPO}/tomcat-dbcp/#{version}/tomcat-dbcp-#{version}.jar"
74
+
75
+ require 'open-uri'; require 'tmpdir'
76
+
77
+ temp_dir = File.join(Dir.tmpdir, (Time.now.to_f * 1000).to_i.to_s)
78
+ FileUtils.mkdir temp_dir
79
+
80
+ downloads = Hash.new
81
+ downloads[dbcp_jar] = dbcp_uri
82
+
83
+ Dir.chdir(temp_dir) do
84
+ FileUtils.mkdir TRINIDAD_LIBS unless File.exist?(TRINIDAD_LIBS)
85
+ downloads.each do |jar, uri|
86
+ puts "downloading #{uri}"
87
+ file = open(uri)
88
+ FileUtils.cp file.path, File.join(TRINIDAD_LIBS, jar)
89
+ end
41
90
  end
42
- desc "Release the #{gem_name} gem"
43
- task :release => :build do
44
- release(gem_name)
91
+
92
+ FileUtils.rm_r temp_dir
93
+ end
94
+
95
+ task :check do
96
+ jar_path = File.join(TRINIDAD_LIBS, dbcp_jar)
97
+ unless File.exist?(jar_path)
98
+ Rake::Task['tomcat-jndi:download'].invoke
45
99
  end
46
100
  end
47
- end
48
101
 
49
- {
50
- :build => 'Build all connection pool gems',
51
- :release => 'Release all connection pool gems'
52
- }.each do |t, d|
53
- desc d
54
- task t => all_gems.map { |name| "#{name}:#{t}" } # e.g. mysql_dbpool:build
55
- end
102
+ task :clear do
103
+ jar_path = File.join(TRINIDAD_LIBS, dbcp_jar)
104
+ rm jar_path if File.exist?(jar_path)
105
+ end
56
106
 
57
- desc "Clear out all built .gem files"
58
- task :clear do
59
- FileUtils.rm Dir["*.gem"]
60
- FileUtils.rm_r Dir["pkg/*"] if File.exist?("pkg")
61
107
  end
62
-
63
- require 'rspec/core/rake_task'
64
- RSpec::Core::RakeTask.new(:spec) do |spec|
65
- spec.rspec_opts = ['--color', "--format documentation"]
66
- end
67
-
68
- task :default => :spec
@@ -2,6 +2,6 @@ require 'java'
2
2
 
3
3
  require 'trinidad'
4
4
  require 'trinidad/jars'
5
- require File.expand_path('../../trinidad-libs/tomcat-dbcp', __FILE__)
5
+ load File.expand_path('../../trinidad-libs/tomcat-dbcp.jar', __FILE__)
6
6
 
7
7
  require 'trinidad_dbpool/webapp_extension'
@@ -10,21 +10,29 @@ module Trinidad
10
10
  end
11
11
  end
12
12
 
13
- private
14
- def create_resource tomcat, app_context, opts
15
- jndi, url = opts.delete(:jndi), opts.delete(:url)
13
+ protected
14
+ def create_resource tomcat, app_context, options
15
+ jndi, url = options.delete(:jndi), options.delete(:url)
16
16
  url = protocol + url unless %r{^#{protocol}} =~ url
17
- opts[:url] = url
18
-
19
- driver_name = opts.delete(:driver) || self.driver_name
17
+ options[:url] = url
20
18
 
19
+ driver_name = options.delete(:driver) || options.delete(:driverName) ||
20
+ self.driver_name
21
+
22
+ # <Resource name="jdbc/MyDB"
23
+ # auth="Container"
24
+ # type="javax.sql.DataSource"
25
+ # url="jdbc:mysql://localhost:3306/mydb"
26
+ # driverClassName="com.mysql.jdbc.Driver"
27
+ # maxActive="100" maxIdle="30" maxWait="10000"
28
+ # username="root" password="secret" />
21
29
  resource = Trinidad::Tomcat::ContextResource.new
22
- resource.set_auth(opts.delete(:auth)) if opts.has_key?(:auth)
23
- resource.set_description(opts.delete(:description)) if opts.has_key?(:description)
30
+ resource.set_auth(options.delete(:auth)) if options.has_key?(:auth)
31
+ resource.set_description(options.delete(:description)) if options.has_key?(:description)
24
32
  resource.set_name(jndi)
25
33
  resource.set_type('javax.sql.DataSource')
26
34
 
27
- opts.each { |key, value| resource.set_property(key.to_s, value.to_s) }
35
+ options.each { |key, value| resource.set_property(key.to_s, value.to_s) }
28
36
  resource.set_property('driverClassName', driver_name)
29
37
 
30
38
  app_context.naming_resources.add_resource(resource)
Binary file
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trinidad_dbpool
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.4.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Calavera
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-31 00:00:00 Z
13
+ date: 2012-12-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: trinidad_jars
@@ -52,15 +52,17 @@ executables: []
52
52
  extensions: []
53
53
 
54
54
  extra_rdoc_files:
55
+ - README.md
56
+ - History.txt
55
57
  - LICENSE
56
- - README.rdoc
58
+ - Rakefile
57
59
  files:
58
60
  - lib/trinidad_dbpool.rb
59
61
  - lib/trinidad_dbpool/webapp_extension.rb
60
62
  - trinidad-libs/tomcat-dbcp.jar
63
+ - README.md
61
64
  - History.txt
62
65
  - LICENSE
63
- - README.rdoc
64
66
  - Rakefile
65
67
  homepage: http://github.com/trinidad/trinidad_dbpool_extension
66
68
  licenses: []
@@ -85,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
87
  requirements: []
86
88
 
87
89
  rubyforge_project:
88
- rubygems_version: 1.8.15
90
+ rubygems_version: 1.8.24
89
91
  signing_key:
90
92
  specification_version: 3
91
93
  summary: Addon to support database pools in Trinidad
data/README.rdoc DELETED
@@ -1,56 +0,0 @@
1
- = trinidad-dbpool
2
-
3
- Trinidad extensions to support database connection pools configured into the Apache Tomcat
4
- container.
5
-
6
- == Pools supported
7
-
8
- * MySql (trinidad_mysql_dbpool_extension)
9
- * PostgreSQL (trinidad_postgresql_dbpool_extension)
10
- * Mssql (trinidad_mssql_dbpool_extension)
11
- * Oracle (trinidad_oracle_dbpool_extension)
12
-
13
- == Usage
14
-
15
- * Install the extension gem, ie: jruby -S gem install trinidad_mysql_dbpool_extension
16
- * Configure the pool into the trinidad's configuration file, ie:
17
-
18
- web_apps:
19
- default:
20
- extensions:
21
- mysql_dbpool: # EXTENSION NAME AS KEY
22
- jndi: 'jdbc/TestDB' # jndi name
23
- username: 'root' # database username
24
- password: 'root' # database password
25
- url: 'jdbc:mysql://localhost:3306/javatest' # database url
26
- maxActive: 100 # max nodes actives
27
- maxIdle: 30 # max nodes idles
28
- maxWait: 10000 # max nodes waiting
29
-
30
- _jndi_, _username_, _password_ and _url_ are mandatory, while other
31
- configuration options can be found here:
32
-
33
- http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
34
-
35
- http://commons.apache.org/dbcp/configuration.html
36
-
37
- * Configure your rails application to use jndi into the config/database.yml
38
-
39
- production:
40
- adapter: jdbc
41
- jndi: java:/comp/env/jdbc/TestDB
42
- driver: com.mysql.jdbc.Driver # jdbc driver is mandatory
43
-
44
- == Note on Patches/Pull Requests
45
-
46
- * Fork the project.
47
- * Make your feature addition or bug fix.
48
- * Add tests for it. This is important so I don't break it in a
49
- future version unintentionally.
50
- * Commit, do not mess with rakefile, version, or history.
51
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
52
- * Send me a pull request. Bonus points for topic branches.
53
-
54
- == Copyright
55
-
56
- Copyright (c) 2010 David Calavera. See LICENSE for details.