trinidad_generic_dbpool_extension 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,17 @@
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
+
1
15
  == 0.4.0 (2012-05-31)
2
16
 
3
17
  * revised trinidad_generic_dbpool_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.
@@ -1,24 +1,42 @@
1
- require 'pathname'
2
-
3
1
  module Trinidad
4
2
  module Extensions
5
3
  class GenericDbpoolWebAppExtension < DbpoolWebAppExtension
6
- def driver_name
7
- if driver_path = @driver_path
8
- unless File.exist?(driver_path)
9
- driver_path = "#{driver_path}.jar" if driver_path[-4..-1] != '.jar'
4
+
5
+ def driver_path(first = nil)
6
+ path = @driver_path || []
7
+ first ? path.first : path
8
+ end
9
+
10
+ def driver_path=(path)
11
+ path = ( path || '' ).split(':') # : PATH separator
12
+ path.map! do |jar|
13
+ jars = Dir.glob(jar)
14
+ if jars.empty? # normalize .jar ext
15
+ jar = "#{jar}.jar" if jar[-4..-1] != '.jar'
16
+ jar
17
+ else
18
+ jars
10
19
  end
11
- driver_path = Pathname.new(driver_path).realpath.to_s
12
- if File.exist?(driver_path)
13
- url = java.net.URL.new "jar:file://#{driver_path}!/META-INF/services/java.sql.Driver"
20
+ end
21
+ path.flatten!
22
+ @driver_path = path
23
+ end
24
+
25
+ def driver_name
26
+ return @driver_name if defined? @driver_name
27
+ driver_path.find do |path|
28
+ path = java.io.File.new(path).absolute_path
29
+ if File.exist?(path)
30
+ url = java.net.URL.new "jar:file://#{path}!/META-INF/services/java.sql.Driver"
14
31
  begin
15
32
  reader = java.io.InputStreamReader.new( url.openStream )
16
- return java.io.BufferedReader.new( reader ).readLine
33
+ return @driver_name = java.io.BufferedReader.new( reader ).readLine
17
34
  rescue java.io.FileNotFoundException
35
+ false
18
36
  end
19
37
  end
20
38
  end
21
- nil
39
+ @driver_name = nil
22
40
  end
23
41
 
24
42
  def protocol
@@ -26,11 +44,22 @@ module Trinidad
26
44
  end
27
45
 
28
46
  protected
47
+
29
48
  def create_resource tomcat, app_context, options
30
- @driver_path = options.delete(:driverPath)
31
- require @driver_path if @driver_path
49
+ path = options.delete(:driverPath) || options.delete(:driver_path)
50
+ self.driver_path = path if path
51
+ if path && driver_path.empty?
52
+ warn "no driver matched with specified :driverPath = #{path.inspect}"
53
+ else
54
+ load_driver
55
+ end
32
56
  super
33
57
  end
58
+
59
+ def load_driver
60
+ driver_path.each { |jar| load jar }
61
+ end
62
+
34
63
  end
35
64
  end
36
65
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trinidad_generic_dbpool_extension
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
  - Patrick Cheng
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-05-31 00:00:00 Z
14
+ date: 2012-12-22 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: trinidad_dbpool
@@ -55,15 +55,15 @@ executables: []
55
55
  extensions: []
56
56
 
57
57
  extra_rdoc_files:
58
+ - README.md
59
+ - History.txt
58
60
  - LICENSE
59
- - README.rdoc
60
61
  files:
61
62
  - lib/trinidad_generic_dbpool_extension.rb
62
63
  - lib/trinidad_generic_dbpool_extension/generic_webapp_extension.rb
64
+ - README.md
63
65
  - History.txt
64
66
  - LICENSE
65
- - README.rdoc
66
- - Rakefile
67
67
  homepage: http://github.com/trinidad/trinidad_dbpool_extension
68
68
  licenses: []
69
69
 
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  requirements: []
88
88
 
89
89
  rubyforge_project:
90
- rubygems_version: 1.8.15
90
+ rubygems_version: 1.8.24
91
91
  signing_key:
92
92
  specification_version: 3
93
93
  summary: Addon to support generic database pools in Trinidad
data/README.rdoc DELETED
@@ -1,93 +0,0 @@
1
- = trinidad-dbpool
2
-
3
- Trinidad extensions to support database connection pooling on top of the
4
- underlying Apache Tomcat container.
5
-
6
- Please note, that such pools are usually configured as "global" and thus
7
- shareable by multiple applications deployed on to of Trinidad server.
8
-
9
- == Available Pools
10
-
11
- * MySQL (trinidad_mysql_dbpool_extension)
12
- * PostgreSQL (trinidad_postgresql_dbpool_extension)
13
- * MS-SQL (trinidad_mssql_dbpool_extension) using (unofficial) jTDS driver
14
- * Oracle (trinidad_oracle_dbpool_extension)
15
- * Generic (trinidad_generic_dbpool_extension) in case your DB ain't supported
16
-
17
- == Usage
18
-
19
- * Install the gem e.g. `jruby -S gem install trinidad_mysql_dbpool_extension`
20
- * Configure the pool with Trinidad's configuration file e.g. :
21
-
22
- web_apps:
23
- default:
24
- extensions:
25
- mysql_dbpool: # EXTENSION NAME AS KEY
26
- jndi: 'jdbc/TestDB' # JNDI name
27
- username: 'root' # database username
28
- password: 'root' # database password
29
- url: 'localhost:3306/javatest' # database URL (or full jdbc: URL)
30
- maxActive: 100 # max nodes actives
31
- maxIdle: 30 # max nodes idles
32
- maxWait: 10000 # max nodes waiting
33
-
34
- _jndi_, _username_, _password_ and _url_ are mandatory,
35
- while other supported configuration options might be found here:
36
-
37
- http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
38
-
39
- http://commons.apache.org/dbcp/configuration.html
40
-
41
- * Configure your rails application to use JNDI into the config/database.yml
42
-
43
- production:
44
- adapter: jdbc
45
- jndi: java:/comp/env/jdbc/TestDB
46
- driver: com.mysql.jdbc.Driver # JDBC driver is mandatory here
47
-
48
- == Generic Pool
49
-
50
- If there's no "official" pool for your database, or would like to use a
51
- different version of a JDBC driver for a supported Trinidad pool, this allows
52
- you to completely customize a pool.
53
-
54
- NOTE: You will need a JDBC driver for your database, check the driver DB if
55
- unsure about how to get one http://developers.sun.com/product/jdbc/drivers
56
-
57
- Sample configuration for a DB2 database :
58
-
59
- ---
60
- extensions:
61
- generic_dbpool: # EXTENSION NAME AS KEY
62
- jndi: 'jdbc/MyDB' # JNDI name
63
- url: 'jdbc:db2://127.0.0.1:50000/MYDB' # specify full jdbc: URL
64
- username: 'mydb' # database username
65
- password: 'pass' # database password
66
- driverPath: '/opt/IBM/DB2/db2jcc4.jar' # leave out if it's on class-path
67
- driverName: com.ibm.db2.jcc.DB2Driver # might resolve from driverPath
68
-
69
- Beyond standard configuration options there's 2 specific options here :
70
-
71
- * _driverPath_ should be a path to your JDBC driver archive, if you're using a
72
- --libs jar folder with trinidad, might leave that out but make sure it's on
73
- the class-path for each and every deployed application that requires it.
74
-
75
- Also in case driverPath: is ommited you'll need to specify a driverName: !
76
-
77
- * _driverName_ the class name implementing the JDBC driver interface, if you're
78
- not sure check the .jar for a META-INF/services/java.sql.Driver file. If
79
- present that file contains the class-name and you might leave driverName:
80
- blank if you specified the jar path using driverPath: but you're going still
81
- going to need the driver name in your database.yml
82
-
83
- == Note on Patches/Pull Requests
84
-
85
- * Fork the project.
86
- * Make your feature addition or bug fix.
87
- * Add tests for it. This is important so I don't break it in a
88
- future version unintentionally.
89
- * Send me a pull request. Bonus points for topic branches.
90
-
91
- == Copyright
92
-
93
- Copyright (c) 2010-2012 David Calavera. See LICENSE for details.
data/Rakefile DELETED
@@ -1,75 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- def build(gem)
5
- mkdir_p 'pkg'
6
- sh "gem build #{gem}.gemspec"
7
- mv Dir["#{gem}*.gem"].last, 'pkg'
8
- end
9
-
10
- def release(gem, version = nil)
11
- unless `git branch` =~ /^\* master$/
12
- raise "must be on master to release !"
13
- end
14
-
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]
27
- end
28
-
29
- sh "git tag #{gem}-#{version}"
30
- sh "git push origin master --tags"
31
- sh "gem push #{gem_file}"
32
- end
33
-
34
- all_gems = %W{
35
- dbpool
36
- generic_dbpool_extension
37
- mysql_dbpool_extension
38
- postgresql_dbpool_extension
39
- mssql_dbpool_extension
40
- oracle_dbpool_extension
41
- }
42
- all_gems.map! { |gem| "trinidad_#{gem}" }
43
- all_gems.each do |gem_name|
44
- namespace gem_name do
45
- desc "Build the #{gem_name} gem"
46
- task :build do
47
- build(gem_name)
48
- end
49
- desc "Release the #{gem_name} gem"
50
- task :release => :build do
51
- release(gem_name)
52
- end
53
- end
54
- end
55
-
56
- {
57
- :build => 'Build all connection pool gems',
58
- :release => 'Release all connection pool gems'
59
- }.each do |t, d|
60
- desc d
61
- task t => all_gems.map { |name| "#{name}:#{t}" } # e.g. mysql_dbpool:build
62
- end
63
-
64
- desc "Clear out all built .gem files"
65
- task :clear do
66
- FileUtils.rm Dir["*.gem"]
67
- FileUtils.rm_r Dir["pkg/*"] if File.exist?("pkg")
68
- end
69
-
70
- require 'rspec/core/rake_task'
71
- RSpec::Core::RakeTask.new(:spec) do |spec|
72
- spec.rspec_opts = ['--color', "--format documentation"]
73
- end
74
-
75
- task :default => :spec