trinidad_mysql_dbpool_extension 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,3 @@
1
+ require 'trinidad_dbpool'
2
+ require File.expand_path('../../trinidad-libs/mysql-connector-java-5.1.12-bin', __FILE__)
3
+ require 'trinidad_mysql_dbpool_extension/mysql_webapp_extension'
@@ -0,0 +1,13 @@
1
+ module Trinidad
2
+ module Extensions
3
+ class MysqlDbpoolWebAppExtension < DbpoolWebAppExtension
4
+ def driver_name
5
+ 'com.mysql.jdbc.Driver'
6
+ end
7
+
8
+ def protocol
9
+ 'jdbc:mysql://'
10
+ end
11
+ end
12
+ end
13
+ 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
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trinidad_mysql_dbpool_extension
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_dbpool
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
+ - !ruby/object:Gem::Dependency
47
+ name: mocha
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ version_requirements: *id003
58
+ description: Addon to support MySql database pools in Trinidad
59
+ email: calavera@apache.org
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files:
65
+ - LICENSE
66
+ - README.rdoc
67
+ files:
68
+ - LICENSE
69
+ - README.rdoc
70
+ - VERSION
71
+ - lib/trinidad_mysql_dbpool_extension.rb
72
+ - lib/trinidad_mysql_dbpool_extension/mysql_webapp_extension.rb
73
+ - trinidad-libs/mysql-connector-java-5.1.12-bin.jar
74
+ has_rdoc: true
75
+ homepage: http://github.com/calavera/trinidad-dbpool
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.6
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Addon to support MySql database pools in Trinidad
104
+ test_files:
105
+ - spec/spec_helper.rb
106
+ - spec/trinidad_mysql_dbpool_extension_spec.rb