trinidad_dbpool 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f93eef63246340486ea0ecca09eb0d944cc9ca7
4
- data.tar.gz: 3ec1c314d6ea8046125d506cfa364629248fffa6
3
+ metadata.gz: ec58e3883b1b9311357eb67855850c9c533e84de
4
+ data.tar.gz: 86a73ec4c26494de2034379f39161a8a2f518c05
5
5
  SHA512:
6
- metadata.gz: 846038f43082dbcb7e5f190921227284869a078062ecbe4185ca81dc3d1b20d9074404d42f9e9d180fa6193b1bfe7486f8171c0521b3b8a40bc5b457b40b6573
7
- data.tar.gz: d334c5d8ecd37cf8b9b8ae7ef910b7eb86525e63d55051ca8b855988a1516cd78d19f3661cd24e1c03a9822fe160bcb79c814e23feb5b96e6c941b044acb1e7a
6
+ metadata.gz: fe405ecd57e9dfdd2b6091822e9744f829ef2e6ed4889a19b03acfcb1331e4df3c836b6072bcb612ffc228430ce5ac9b377a688886d0d330dc80a7dcd706d2de
7
+ data.tar.gz: 80ae0a6d5be2b5776de2892da161bc582b3612b934c3238df68275508f2a2a01daeb82735cf1ecb85111be0408f33a870b17fd2774ffeac1e52abcc3fd4d4c5a
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Team Trinidad and contributors http://github.com/trinidad
1
+ Copyright (c) 2014 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
data/README.md CHANGED
@@ -30,8 +30,8 @@ http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
30
30
  default:
31
31
  extensions:
32
32
  mysql_dbpool: # EXTENSION NAME AS KEY
33
- jndi: 'jdbc/MySampleDB' # name (linked with database.yml)
34
- url: 'localhost:3306/sample' # database URL (or full jdbc: URL)
33
+ name: jdbc/MySampleDB # name (linked with database.yml)
34
+ url: localhost:3306/sample # database URL (or full jdbc: URL)
35
35
  username: root
36
36
  password: root
37
37
  maxActive: 100 # maximum number of connections managed by the pool
@@ -39,9 +39,9 @@ http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html
39
39
  maxWait: 10000 # ms the pool waits for a connection to be returned
40
40
  ```
41
41
 
42
- **jndi**, **url** are mandatory (as well **username** and **password** if your
43
- database server + driver requires authentication), while other supported
44
- configuration options might be found here in Tomcat's JDBC pool documentation :
42
+ **name** (aliased as **jndi**), **url** are mandatory (as well **username** and
43
+ **password** if your database server + driver requires authentication), while
44
+ the other supported options might be found in Tomcat's JDBC pool documentation :
45
45
 
46
46
  http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html#Common_Attributes
47
47
 
@@ -113,5 +113,5 @@ Beyond standard configuration options there's 2 specific options here :
113
113
 
114
114
  ## Copyright
115
115
 
116
- Copyright (c) 2013 [Team Trinidad](https://github.com/trinidad).
116
+ Copyright (c) 2016 [Team Trinidad](https://github.com/trinidad).
117
117
  See LICENSE (http://en.wikipedia.org/wiki/MIT_License) for details.
data/Rakefile CHANGED
@@ -50,57 +50,69 @@ all_gems.each do |gem_name|
50
50
 
51
51
  end
52
52
 
53
+ unless Bundler::GemHelper.method_defined?(:release_gem)
54
+ Bundler::GemHelper.send :define_method, :release_gem do
55
+ guard_clean
56
+ tag_version unless already_tagged?
57
+ built_gem_path = build_gem
58
+ rubygem_push(built_gem_path) if gem_push?
59
+ end
60
+ Bundler::GemHelper.send :define_method, :install_gem do
61
+ built_gem_path = build_gem
62
+ install_gem(built_gem_path)
63
+ end
64
+ end
65
+
53
66
  namespace :all do
54
67
  desc "Build all gems into the pkg directory"
55
68
  task 'build' => all_gems.map { |gem_name| "#{gem_name}:build" }
56
69
 
57
70
  desc "Build and install all gems into system gems"
58
71
  task 'install' => all_gems.map { |gem_name| "#{gem_name}:install" }
59
- end
60
72
 
61
- namespace :'tomcat-dbcp' do
73
+ task 'release' => all_gems.map { |gem_name| "#{gem_name}:release" }
74
+ end
62
75
 
63
- TOMCAT_MAVEN_REPO = 'http://repo2.maven.org/maven2/org/apache/tomcat'
76
+ ['tomcat-jdbc', 'tomcat-dbcp'].each do |tomcat_pool|
64
77
 
65
- TRINIDAD_LIBS = File.expand_path('./trinidad-libs', File.dirname(__FILE__))
78
+ namespace tomcat_pool do
66
79
 
67
- dbcp_jar = "tomcat-dbcp.jar"
80
+ tomcat_maven_repo = 'http://repo2.maven.org/maven2/org/apache/tomcat'
81
+ trinidad_libs = File.expand_path('trinidad-libs', File.dirname(__FILE__))
68
82
 
69
- task :download, :version do |_, args| # rake tomcat-dbcp:download[7.0.41]
70
- version = args[:version]
83
+ tomcat_pool_jar = "#{tomcat_pool}.jar"
71
84
 
72
- dbcp_uri = "#{TOMCAT_MAVEN_REPO}/tomcat-dbcp/#{version}/tomcat-dbcp-#{version}.jar"
85
+ task :download, :version do |_, args| # rake tomcat-jdbc:download[7.0.54]
86
+ version = args[:version]
73
87
 
74
- require 'open-uri'; require 'tmpdir'
88
+ uri = "#{tomcat_maven_repo}/#{tomcat_pool}/#{version}/#{tomcat_pool}-#{version}.jar"
75
89
 
76
- temp_dir = File.join(Dir.tmpdir, (Time.now.to_f * 1000).to_i.to_s)
77
- FileUtils.mkdir temp_dir
90
+ require 'open-uri'; require 'tmpdir'
78
91
 
79
- downloads = Hash.new
80
- downloads[dbcp_jar] = dbcp_uri
92
+ temp_dir = File.join(Dir.tmpdir, (Time.now.to_f * 1000).to_i.to_s)
93
+ FileUtils.mkdir temp_dir
81
94
 
82
- Dir.chdir(temp_dir) do
83
- FileUtils.mkdir TRINIDAD_LIBS unless File.exist?(TRINIDAD_LIBS)
84
- downloads.each do |jar, uri|
95
+ Dir.chdir(temp_dir) do
85
96
  puts "downloading #{uri}"
86
97
  file = open(uri)
87
- FileUtils.cp file.path, File.join(TRINIDAD_LIBS, jar)
98
+ FileUtils.cp file.path, File.join(trinidad_libs, tomcat_pool_jar)
88
99
  end
100
+
101
+ FileUtils.rm_r temp_dir
89
102
  end
90
103
 
91
- FileUtils.rm_r temp_dir
92
- end
104
+ task :check do
105
+ jar_path = File.join(trinidad_libs, tomcat_pool_jar)
106
+ unless File.exist?(jar_path)
107
+ Rake::Task["#{tomcat_pool}:download"].invoke
108
+ end
109
+ end
93
110
 
94
- task :check do
95
- jar_path = File.join(TRINIDAD_LIBS, dbcp_jar)
96
- unless File.exist?(jar_path)
97
- Rake::Task['tomcat-jndi:download'].invoke
111
+ task :clear do
112
+ jar_path = File.join(trinidad_libs, tomcat_pool_jar)
113
+ rm jar_path if File.exist?(jar_path)
98
114
  end
99
- end
100
115
 
101
- task :clear do
102
- jar_path = File.join(TRINIDAD_LIBS, dbcp_jar)
103
- rm jar_path if File.exist?(jar_path)
104
116
  end
105
117
 
106
118
  end
@@ -1,7 +1,121 @@
1
1
  require 'java'
2
-
3
- require 'trinidad'
4
2
  require 'trinidad/jars'
5
3
  load File.expand_path('../../trinidad-libs/tomcat-jdbc.jar', __FILE__)
6
4
 
7
- require 'trinidad_dbpool/webapp_extension'
5
+ module Trinidad
6
+ module DBPool
7
+ class << self
8
+
9
+ def create_resource(context, options, protocol = nil)
10
+ name = options.delete(:name) || options.delete(:jndi); url = options.delete(:url)
11
+ if ! url.start_with?('jdbc:') && protocol
12
+ url = "#{protocol}#{url}" unless url.start_with?(protocol)
13
+ end
14
+
15
+ resource_factory = options.key?(:factory) ? options.delete(:factory) :
16
+ 'org.apache.tomcat.jdbc.pool.DataSourceFactory'
17
+ if ( pool = options.delete(:pool) ) && pool.to_s != 'jdbc' # pool: 'dbcp'
18
+ begin
19
+ load File.expand_path("../../trinidad-libs/tomcat-#{pool}.jar", __FILE__)
20
+ resource_factory = nil
21
+ rescue LoadError
22
+ context.logger.warn "The `pool: #{pool}` option is not supported, please remove it"
23
+ else
24
+ context.logger.info "Using deprecated `pool: #{pool}` configuration option, consider removing it"
25
+ end
26
+ end
27
+
28
+ driver = options.delete(:driver) || options.delete(:driverName) || options.delete(:driver_name)
29
+
30
+ context.logger.debug "Using JDBC URL: #{url.inspect} for #{name}"
31
+
32
+ # <Resource name="jdbc/MyDB"
33
+ # auth="Container"
34
+ # type="javax.sql.DataSource"
35
+ # url="jdbc:mysql://localhost:3306/mydb"
36
+ # driverClassName="com.mysql.jdbc.Driver"
37
+ # maxActive="100" maxIdle="30" maxWait="10000"
38
+ # username="root" password="secret" />
39
+ resource = Trinidad::Tomcat::ContextResource.new
40
+ resource.set_auth(options.delete(:auth)) if options.key?(:auth)
41
+ resource.set_description(options.delete(:description)) if options.key?(:description)
42
+ resource.set_name(name)
43
+ resource.set_type(options.delete(:type) || 'javax.sql.DataSource')
44
+ resource.set_property('factory', resource_factory) if resource_factory
45
+ resource.set_property('driverClassName', driver)
46
+ resource.set_property('url', url)
47
+ camelizer = supported_properties_camelizer
48
+ options.each do |key, value|
49
+ resource.set_property(camelizer[key.to_s], value.to_s)
50
+ end
51
+
52
+ yield(resource) if block_given?
53
+
54
+ context.naming_resources.add_resource(resource)
55
+ context.naming_resources = resource.naming_resources
56
+
57
+ resource
58
+ end
59
+
60
+ private
61
+
62
+ def supported_properties_camelizer
63
+ hash = Hash.new { |hash, key| simple_camelize(key) }
64
+
65
+ # Common Attributes :
66
+
67
+ hash['username'] = 'username'
68
+ hash['password'] = 'password'
69
+ hash['driver_class_name'] = 'driverClassName'
70
+
71
+ hash['default_auto_commit'] = 'defaultAutoCommit'
72
+ hash['default_read_only'] = 'defaultReadOnly'
73
+ hash['default_transaction_isolation'] = 'defaultTransactionIsolation'
74
+ hash['default_catalog'] = 'defaultCatalog'
75
+
76
+ hash['max_active'] = 'maxActive'
77
+ hash['max_idle'] = 'maxIdle'
78
+ hash['min_idle'] = 'minIdle'
79
+ hash['initial_size'] = 'initialSize'
80
+ hash['max_wait'] = 'maxWait'
81
+
82
+ hash['test_on_borrow'] = 'testOnBorrow'
83
+ hash['test_on_return'] = 'testOnReturn'
84
+ hash['test_while_idle'] = 'testWhileIdle'
85
+
86
+ hash['validation_query'] = 'validationQuery'
87
+ hash['validation_query_timeout'] = 'validationQueryTimeout'
88
+
89
+ #
90
+
91
+ hash['log_abandoned'] = 'logAbandoned'
92
+ hash['remove_abandoned'] = 'removeAbandoned'
93
+ hash['remove_abandoned_timeout'] = 'removeAbandonedTimeout'
94
+
95
+ hash['connection_properties'] = 'connectionProperties'
96
+
97
+ # Tomcat JDBC pool only :
98
+
99
+ hash['init_sql'] = 'initSQL'
100
+ hash['validation_interval'] = 'validationInterval'
101
+ hash['jmx_enabled'] = 'jmxEnabled'
102
+ hash['fair_queue'] = 'fairQueue'
103
+ hash['abandon_when_percentage_full'] = 'abandonWhenPercentageFull'
104
+
105
+ hash['max_age'] = 'maxAge'
106
+ hash['suspect_timeout'] = 'suspectTimeout'
107
+ hash['rollback_on_return'] = 'rollbackOnReturn'
108
+ hash['commit_on_return'] = 'commitOnReturn'
109
+ hash['alternate_username_allowed'] = 'alternateUsernameAllowed'
110
+
111
+ hash
112
+ end
113
+
114
+ def simple_camelize(string)
115
+ return string unless string.index('_')
116
+ string.gsub(/_([a-z\d]*)/i) { $1.capitalize }
117
+ end
118
+
119
+ end
120
+ end
121
+ end
@@ -1,3 +1,5 @@
1
+ require 'trinidad'
2
+
1
3
  module Trinidad
2
4
  module Extensions
3
5
  class DbpoolWebAppExtension < WebAppExtension
@@ -5,7 +7,7 @@ module Trinidad
5
7
  def configure(tomcat, context)
6
8
  case @options
7
9
  when Hash
8
- [create_resource(tomcat, context, @options)]
10
+ [ create_resource(tomcat, context, @options) ]
9
11
  when Array
10
12
  @options.map { |opts| create_resource tomcat, context, opts }
11
13
  end
@@ -14,52 +16,27 @@ module Trinidad
14
16
  protected
15
17
 
16
18
  def create_resource tomcat, context, options
17
- jndi, url = options.delete(:jndi), options.delete(:url)
18
- url = protocol + url unless %r{^#{protocol}} =~ url
19
- options[:url] = url
20
-
21
- resource_factory = options.key?(:factory) ? options.delete(:factory) :
22
- 'org.apache.tomcat.jdbc.pool.DataSourceFactory'
23
- if pool = options.delete(:pool) # pool: dbcp (backwards compatibility)
24
- begin
25
- load File.expand_path("../../../trinidad-libs/tomcat-#{pool}.jar", __FILE__)
26
- resource_factory = nil
27
- rescue LoadError
28
- context.logger.warn "The `pool: #{pool}` option is not supported, please remove it"
29
- else
30
- context.logger.info "Using deprecated `pool: #{pool}` configuration option, consider removing it"
31
- end
32
- end
33
-
34
19
  load_driver
35
20
 
36
- driver_name = options.delete(:driver) || options.delete(:driverName) ||
37
- self.driver_name
21
+ options[:driver] ||= options.delete(:driverName) ||
22
+ options.delete(:driver_name) || self.driver_name
38
23
 
39
- # <Resource name="jdbc/MyDB"
40
- # auth="Container"
41
- # type="javax.sql.DataSource"
42
- # url="jdbc:mysql://localhost:3306/mydb"
43
- # driverClassName="com.mysql.jdbc.Driver"
44
- # maxActive="100" maxIdle="30" maxWait="10000"
45
- # username="root" password="secret" />
46
- resource = Trinidad::Tomcat::ContextResource.new
47
- resource.set_auth(options.delete(:auth)) if options.key?(:auth)
48
- resource.set_description(options.delete(:description)) if options.key?(:description)
49
- resource.set_name(jndi)
50
- resource.set_type(options.delete(:type) || 'javax.sql.DataSource')
51
- resource.set_property('factory', resource_factory) if resource_factory
52
- resource.set_property('driverClassName', driver_name)
53
- options.each { |key, value| resource.set_property(key.to_s, value.to_s) }
54
-
55
- context.naming_resources.add_resource(resource)
56
- context.naming_resources = resource.naming_resources
24
+ if properties = options.delete(:properties) || connection_properties
25
+ if properties.is_a?(String)
26
+ options['connectionProperties'] ||= properties
27
+ else # format: prop1=value1;prop2=value2
28
+ url_params = properties.map { |key, value| "#{key}=#{value}" }
29
+ options['connectionProperties'] ||= url_params.join(';')
30
+ end
31
+ end
57
32
 
58
- resource
33
+ Trinidad::DBPool.create_resource(context, options, protocol)
59
34
  end
60
35
 
61
36
  def load_driver; end
62
37
 
38
+ def connection_properties; end
39
+
63
40
  end
64
41
  end
65
42
  end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trinidad_dbpool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Calavera
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-11 00:00:00.000000000 Z
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: trinidad_jars
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: 1.2.4
20
14
  requirement: !ruby/object:Gem::Requirement
21
15
  requirements:
22
- - - '>='
16
+ - - ">="
23
17
  - !ruby/object:Gem::Version
24
18
  version: 1.2.4
19
+ name: trinidad_jars
25
20
  prerelease: false
26
21
  type: :runtime
27
- - !ruby/object:Gem::Dependency
28
- name: rspec
29
22
  version_requirements: !ruby/object:Gem::Requirement
30
23
  requirements:
31
- - - ~>
24
+ - - ">="
32
25
  - !ruby/object:Gem::Version
33
- version: '2.10'
26
+ version: 1.2.4
27
+ - !ruby/object:Gem::Dependency
34
28
  requirement: !ruby/object:Gem::Requirement
35
29
  requirements:
36
- - - ~>
30
+ - - "~>"
37
31
  - !ruby/object:Gem::Version
38
32
  version: '2.10'
33
+ name: rspec
39
34
  prerelease: false
40
35
  type: :development
41
- - !ruby/object:Gem::Dependency
42
- name: mocha
43
36
  version_requirements: !ruby/object:Gem::Requirement
44
37
  requirements:
45
- - - '>='
38
+ - - "~>"
46
39
  - !ruby/object:Gem::Version
47
- version: '0.10'
40
+ version: '2.10'
41
+ - !ruby/object:Gem::Dependency
48
42
  requirement: !ruby/object:Gem::Requirement
49
43
  requirements:
50
- - - '>='
44
+ - - ">="
51
45
  - !ruby/object:Gem::Version
52
46
  version: '0.10'
47
+ name: mocha
53
48
  prerelease: false
54
49
  type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
55
  description: Addon to support database pools in Trinidad
56
56
  email: calavera@apache.org
57
57
  executables: []
@@ -62,14 +62,14 @@ extra_rdoc_files:
62
62
  - LICENSE
63
63
  - Rakefile
64
64
  files:
65
+ - History.txt
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
65
69
  - lib/trinidad_dbpool.rb
66
70
  - lib/trinidad_dbpool/webapp_extension.rb
67
71
  - trinidad-libs/tomcat-dbcp.jar
68
72
  - trinidad-libs/tomcat-jdbc.jar
69
- - README.md
70
- - History.txt
71
- - LICENSE
72
- - Rakefile
73
73
  homepage: http://github.com/trinidad/trinidad_dbpool_extension
74
74
  licenses: []
75
75
  metadata: {}
@@ -79,17 +79,17 @@ require_paths:
79
79
  - lib
80
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.1.9
92
+ rubygems_version: 2.4.8
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Addon to support database pools in Trinidad