trinidad_dbpool 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 David Calavera
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,54 @@
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
+
11
+ == Usage
12
+
13
+ * Install the extension gem, ie: jruby -S gem install trinidad_mysql_dbpool_extension
14
+ * Configure the pool into the trinidad's configuration file, ie:
15
+
16
+ web_apps:
17
+ default:
18
+ extensions:
19
+ mysql_dbpool: # EXTENSION NAME AS KEY
20
+ jndi: 'jdbc/TestDB' # jndi name
21
+ username: 'root' # database username
22
+ password: 'root' # database password
23
+ url: 'jdbc:mysql://localhost:3306/javatest' # database url
24
+ maxActive: 100 # max nodes actives
25
+ maxIdle: 30 # max nodes idles
26
+ maxWait: 10000 # max nodes waiting
27
+
28
+ _jndi_, _username_, _password_ and _url_ are mandatory, while other
29
+ configuration options can be found here:
30
+
31
+ http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
32
+
33
+ http://commons.apache.org/dbcp/configuration.html
34
+
35
+ * Configure your rails application to use jndi into the config/database.yml
36
+
37
+ production:
38
+ adapter: jdbc
39
+ jndi: java:/comp/env/jdbc/TestDB
40
+ driver: com.mysql.jdbc.Driver
41
+
42
+ == Note on Patches/Pull Requests
43
+
44
+ * Fork the project.
45
+ * Make your feature addition or bug fix.
46
+ * Add tests for it. This is important so I don't break it in a
47
+ future version unintentionally.
48
+ * Commit, do not mess with rakefile, version, or history.
49
+ (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)
50
+ * Send me a pull request. Bonus points for topic branches.
51
+
52
+ == Copyright
53
+
54
+ Copyright (c) 2010 David Calavera. See LICENSE for details.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,12 @@
1
+
2
+ require 'java'
3
+ require 'rubygems'
4
+ gem 'trinidad_jars'
5
+
6
+ require 'trinidad'
7
+
8
+ require 'trinidad/jars'
9
+
10
+ require File.expand_path('../../trinidad-libs/tomcat-dbcp', __FILE__)
11
+
12
+ require 'trinidad_dbpool/webapp_extension'
@@ -0,0 +1,34 @@
1
+ module Trinidad
2
+ module Extensions
3
+ class DbpoolWebAppExtension < WebAppExtension
4
+ def configure(tomcat, app_context)
5
+ jndi = @options.delete(:jndi)
6
+ extension_name = jndi.gsub(/\//, '_')
7
+ url = @options.delete(:url)
8
+ url = protocol + url unless %r{^#{protocol}} =~ url
9
+ @options[:url] = url
10
+
11
+ resource = Trinidad::Tomcat::ContextResource.new
12
+ resource.setAuth(@options.delete(:auth)) if @options.has_key?(:auth)
13
+ resource.setName(jndi)
14
+ resource.setType("javax.sql.DataSource")
15
+ resource.setDescription(@options.delete(:description)) if @options.has_key?(:description)
16
+
17
+ @options.each do |key, value|
18
+ resource.setProperty(key.to_s, value.to_s)
19
+ end
20
+
21
+ resource.setProperty("driverClassName", driver_name)
22
+
23
+ app_context.naming_resources.add_resource(resource)
24
+ app_context.naming_resources = resource.naming_resources
25
+
26
+ resource_context = tomcat.addContext("/#{extension_name}", '.')
27
+ resource_context.naming_resources.addResource(resource)
28
+ resource_context.naming_resources = resource.naming_resources
29
+
30
+ resource
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'trinidad-libs'))
4
+
5
+ require 'trinidad_mysql_dbpool_extension'
6
+ require 'spec'
7
+
8
+ Spec::Runner.configure do |config|
9
+ config.mock_with :mocha
10
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Trinidad::Extensions::MysqlDbpoolWebAppExtension do
4
+ before(:each) do
5
+ @options = {
6
+ :url => 'jdbc:mysql://localhost:3306/test',
7
+ :jndi => 'jdbc/TestDB',
8
+ :maxIdle => 300
9
+ }
10
+ @extension = Trinidad::Extensions::MysqlDbpoolWebAppExtension.new(@options)
11
+ @context = Trinidad::Tomcat::StandardContext.new
12
+
13
+ @tomcat = mock
14
+ resource_context = mock
15
+ naming = mock
16
+
17
+ naming.stubs(:addResource)
18
+ resource_context.stubs(:naming_resources).returns(naming)
19
+ resource_context.stubs(:naming_resources=)
20
+ @tomcat.stubs(:addContext).returns(resource_context)
21
+ end
22
+
23
+ it "sets the mysql driver name as a resource property" do
24
+ resource = configure_extension
25
+ resource.getProperty('driverClassName').should == 'com.mysql.jdbc.Driver'
26
+ end
27
+
28
+ it "adds the resource to the tomcat standard context" do
29
+ configure_extension
30
+ @context.naming_resources.find_resource('jdbc/TestDB').should_not be_nil
31
+ end
32
+
33
+ it "adds properties to the resource" do
34
+ resource = configure_extension
35
+ resource.getProperty('maxIdle').should == '300'
36
+ end
37
+
38
+ it "adds the protocol if the url doesn't include it" do
39
+ @options[:url] = "localhost:3306/test_protocol"
40
+ extension = Trinidad::Extensions::MysqlDbpoolWebAppExtension.new(@options)
41
+ resource = extension.configure(@tomcat, @context)
42
+ resource.get_property('url').should == "jdbc:mysql://localhost:3306/test_protocol"
43
+ end
44
+
45
+ def configure_extension
46
+ @extension.configure(@tomcat, @context)
47
+ end
48
+ end
Binary file
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trinidad_dbpool
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - David Calavera
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-04 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: trinidad_jars
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 1
41
+ - 2
42
+ - 9
43
+ version: 1.2.9
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Addon to support database pools in Trinidad
47
+ email: calavera@apache.org
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ - VERSION
59
+ - lib/trinidad_dbpool.rb
60
+ - lib/trinidad_dbpool/webapp_extension.rb
61
+ - trinidad-libs/tomcat-dbcp.jar
62
+ has_rdoc: true
63
+ homepage: http://github.com/calavera/trinidad-dbpool
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.6
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Addon to support database pools in Trinidad
92
+ test_files:
93
+ - spec/spec_helper.rb
94
+ - spec/trinidad_mysql_dbpool_extension_spec.rb