hucpa 0.1.0-jruby

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61ca80545c3fbd8a1632756a8bdf01dd3d8dfb5c
4
+ data.tar.gz: d9e0b7947b9c0ef484793fa9cb8b82734ff890fd
5
+ SHA512:
6
+ metadata.gz: aad3f89dc593fdfcfdfdc95f1966f7f754cc1ca5424609b55d4c65c69eb25739e7fc7a94646158e9d97486751f4217ea81a01c0d2f11a02c42e798c083e5cd75
7
+ data.tar.gz: c17eb2ad739ab89417e7b422b8eda9272dfd0d5de176f7b206b3fa51356bd824f76306a18df6f7b6379d47e5849afd39285b7600c35eef42b9c462f34679bc4d
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.irbrc ADDED
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift("lib")
2
+ require "hucpa"
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ja AT jestem DOT tw. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Dockerfile ADDED
@@ -0,0 +1,12 @@
1
+ FROM jruby:9.1.7.0-jre-alpine
2
+
3
+ RUN apk --update --no-cache add git openssh && \
4
+ mkdir /hucpa
5
+
6
+ WORKDIR /hucpa
7
+
8
+ COPY hucpa.gemspec Gemfile Gemfile.lock ./
9
+
10
+ RUN gem install bundler -v 1.13.7 && bundle
11
+
12
+ COPY . ./
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hucpa (0.1.0-java)
5
+ dry-validation (~> 0.10)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ concurrent-ruby (1.0.4-java)
11
+ diff-lcs (1.3)
12
+ docile (1.1.5)
13
+ dry-configurable (0.5.0)
14
+ concurrent-ruby (~> 1.0)
15
+ dry-container (0.6.0)
16
+ concurrent-ruby (~> 1.0)
17
+ dry-configurable (~> 0.1, >= 0.1.3)
18
+ dry-core (0.2.3)
19
+ concurrent-ruby (~> 1.0)
20
+ dry-equalizer (0.2.0)
21
+ dry-logic (0.4.0)
22
+ dry-container (~> 0.2, >= 0.2.6)
23
+ dry-core (~> 0.1)
24
+ dry-equalizer (~> 0.2)
25
+ dry-types (0.9.3)
26
+ concurrent-ruby (~> 1.0)
27
+ dry-configurable (~> 0.1)
28
+ dry-container (~> 0.3)
29
+ dry-core (~> 0.2, >= 0.2.1)
30
+ dry-equalizer (~> 0.2)
31
+ dry-logic (~> 0.4, >= 0.4.0)
32
+ inflecto (~> 0.0.0, >= 0.0.2)
33
+ dry-validation (0.10.5)
34
+ concurrent-ruby (~> 1.0)
35
+ dry-configurable (~> 0.1, >= 0.1.3)
36
+ dry-core (~> 0.2, >= 0.2.1)
37
+ dry-equalizer (~> 0.2)
38
+ dry-logic (~> 0.4, >= 0.4.0)
39
+ dry-types (~> 0.9, >= 0.9.0)
40
+ inflecto (0.0.2)
41
+ jdbc-postgres (9.4.1206)
42
+ json (2.0.3-java)
43
+ rake (12.0.0)
44
+ rspec (3.5.0)
45
+ rspec-core (~> 3.5.0)
46
+ rspec-expectations (~> 3.5.0)
47
+ rspec-mocks (~> 3.5.0)
48
+ rspec-core (3.5.4)
49
+ rspec-support (~> 3.5.0)
50
+ rspec-expectations (3.5.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.5.0)
53
+ rspec-mocks (3.5.0)
54
+ diff-lcs (>= 1.2.0, < 2.0)
55
+ rspec-support (~> 3.5.0)
56
+ rspec-support (3.5.0)
57
+ simplecov (0.12.0)
58
+ docile (~> 1.1.0)
59
+ json (>= 1.8, < 3)
60
+ simplecov-html (~> 0.10.0)
61
+ simplecov-html (0.10.0)
62
+
63
+ PLATFORMS
64
+ java
65
+
66
+ DEPENDENCIES
67
+ bundler (~> 1.13)
68
+ hucpa!
69
+ jdbc-postgres (~> 9.4)
70
+ rake (~> 12.0)
71
+ rspec (~> 3.5)
72
+ simplecov (~> 0)
73
+
74
+ BUNDLED WITH
75
+ 1.13.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Tomek Wałkuski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # Hucpa
2
+
3
+ [![Code Climate](https://codeclimate.com/github/tomekw/hucpa/badges/gpa.svg)](https://codeclimate.com/github/tomekw/hucpa) [![Test Coverage](https://codeclimate.com/github/tomekw/hucpa/badges/coverage.svg)](https://codeclimate.com/github/tomekw/hucpa/coverage) [![CircleCI](https://circleci.com/gh/tomekw/hucpa.svg?style=svg)](https://circleci.com/gh/tomekw/hucpa)
4
+
5
+ A JRuby wrapper to [HikariCP](https://github.com/brettwooldridge/HikariCP) - "zero-overhead" production ready JDBC connection pool.
6
+ This is / will be a part of a bigger effort, like a dedicated library to use SQL and / or ActiveRecord integration.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem "hucpa"
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install hucpa
23
+
24
+ ## Configuration options
25
+
26
+ See [HikariCP Documentation](https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby) for a detailed description.
27
+ Not all HikariCP-defined configuration options are currently supported. To add support for infrequently used options please
28
+ raise an issue or file a pull request.
29
+
30
+ | Option | Required | Default value | Notes |
31
+ | ----------------------- | :------: | ------------- | ----------------------------------------------------------------------- |
32
+ | `adapter` | Yes(1) | - | Symbol |
33
+ | `auto_commit` | No | `true` | Boolean |
34
+ | `connection_test_query` | No | - | String |
35
+ | `connection_timeout` | No | `30_000` | Integer, greater than or equal to 250, in miliseconds |
36
+ | `database_name` | No | - | String |
37
+ | `idle_timeout` | No | `600_000` | Integer, 0 (disabled) or greater than or equal to 10000, in miliseconds |
38
+ | `jdbc_url` | Yes(1) | - | String |
39
+ | `max_lifetime` | No | `1_800_000` | Integer, 0 (disabled) or greater than or equal to 30000, in miliseconds |
40
+ | `maximum_pool_size` | No | `10` | Integer, greater than or equal to 1 |
41
+ | `minimum_idle` | No | `10` | Integer, greater than or equal to 1 |
42
+ | `password` | Yes | - | String |
43
+ | `pool_name` | No | - | String |
44
+ | `server_name` | No | - | String |
45
+ | `username` | Yes | - | String |
46
+
47
+ `(1)` - either `adapter` or `jdbc_url` has to be provided.
48
+
49
+ ## Supported adapters and corresponding datasource class names
50
+
51
+ | Adapter | Datasource class name |
52
+ | ---------------- | -------------------------------------------------- |
53
+ | `db2` | `com.ibm.db2.jcc.DB2SimpleDataSource` |
54
+ | `derby` | `org.apache.derby.jdbc.ClientDataSource` |
55
+ | `fdbsql` | `com.foundationdb.sql.jdbc.ds.FDBSimpleDataSource` |
56
+ | `firebird` | `org.firebirdsql.pool.FBSimpleDataSource` |
57
+ | `h2` | `org.h2.jdbcx.JdbcDataSource` |
58
+ | `hsqldb` | `org.hsqldb.jdbc.JDBCDataSource` |
59
+ | `mariadb` | `org.mariadb.jdbc.MySQLDataSource` |
60
+ | `mysql` | `com.mysql.jdbc.jdbc2.optional.MysqlDataSource` |
61
+ | `oracle` | `oracle.jdbc.pool.OracleDataSource` |
62
+ | `pgjdbc_ng` | `com.impossibl.postgres.jdbc.PGDataSource` |
63
+ | `postgresql` | `org.postgresql.ds.PGSimpleDataSource` |
64
+ | `sqlite` | `org.sqlite.JDBC` |
65
+ | `sqlserver_jtds` | `net.sourceforge.jtds.jdbcx.JtdsDataSource` |
66
+ | `sqlserver` | `com.microsoft.sqlserver.jdbc.SQLServerDataSource` |
67
+ | `sybase` | `com.sybase.jdbcx.SybDataSource` |
68
+
69
+ ## Usage
70
+
71
+ Install the database driver, for PostgreSQL:
72
+
73
+ ```ruby
74
+ gem "jdbc-postgres"
75
+ ```
76
+
77
+ Load the the database driver if needed, for PostgreSQL:
78
+
79
+ ```ruby
80
+ require "jdbc/postgres"
81
+ Jdbc::Postgres.load_driver
82
+ ```
83
+
84
+ Configure the connection pool:
85
+
86
+ ```ruby
87
+ # Using the adapter option
88
+ options = {
89
+ adapter: :postgresql,
90
+ database_name: "hucpa",
91
+ password: "hucpa",
92
+ server_name: "postgres",
93
+ username: "hucpa"
94
+ }
95
+
96
+ # Using the jdbc_url option
97
+ options = {
98
+ jdbc_url: "jdbc:postgresql://postgres/hucpa",
99
+ password: "hucpa",
100
+ username: "hucpa"
101
+ }
102
+
103
+ connection_pool = Hucpa::ConnectionPool.new(options)
104
+ ```
105
+
106
+ Use the connection pool with the `with_connection` API:
107
+
108
+
109
+ ```ruby
110
+ answer = connection_pool.with_connection do |connection|
111
+ result_set =
112
+ connection
113
+ .create_statement
114
+ .execute_query("SELECT 42 AS answer")
115
+
116
+ result_set.next and result_set.get_int("answer")
117
+ end
118
+
119
+ answer
120
+ => 42
121
+ ```
122
+
123
+ Or use the connection pool with the "classic" API:
124
+
125
+ ```ruby
126
+ datasource = connection_pool.open
127
+
128
+ # Explicitly obtain the DB connection
129
+ connection = datasource.connection
130
+
131
+ result_set =
132
+ connection
133
+ .create_statement
134
+ .execute_query("SELECT 42 AS answer")
135
+
136
+ answer = result_set.next and result_set.get_int("answer")
137
+
138
+ # Explicitly release the DB connection
139
+ connection.close
140
+
141
+ answer
142
+ => 42
143
+ ```
144
+
145
+ Close the connection pool:
146
+
147
+ ```ruby
148
+ connection_pool.close
149
+
150
+ ```
151
+
152
+ ## Development
153
+
154
+ Build the Docker image:
155
+
156
+ $ docker-compose build
157
+
158
+ Create services:
159
+
160
+ $ docker-compose create
161
+
162
+ Run specs:
163
+
164
+ $ docker-compose run --rm app rspec spec
165
+
166
+ Run console:
167
+
168
+ $ docker-compose run --rm app irb
169
+
170
+ ## Contributing
171
+
172
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tomekw/hucpa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
173
+
174
+ ## License
175
+
176
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/circle.yml ADDED
@@ -0,0 +1,16 @@
1
+ machine:
2
+ services:
3
+ - docker
4
+
5
+ database:
6
+ override:
7
+ - psql -U ubuntu -c "CREATE USER hucpa WITH PASSWORD 'hucpa'"
8
+ - psql -U ubuntu -c "CREATE DATABASE hucpa OWNER hucpa"
9
+
10
+ dependencies:
11
+ override:
12
+ - docker build --rm=false -t tomekw/hucpa .
13
+
14
+ test:
15
+ override:
16
+ - docker run --net=host --env DATABASE_HOST=localhost --rm tomekw/hucpa rspec spec
@@ -0,0 +1,21 @@
1
+ version: "2"
2
+ services:
3
+ app:
4
+ build: .
5
+ depends_on:
6
+ - postgres
7
+ environment:
8
+ JRUBY_OPTS: --debug
9
+ volumes:
10
+ - .:/hucpa
11
+ - ${HOME}/.ssh:/root/.ssh:ro
12
+ postgres:
13
+ environment:
14
+ POSTGRES_USER: hucpa
15
+ POSTGRES_PASSWORD: hucpa
16
+ image: postgres:9.6.1
17
+ volumes:
18
+ - postgres:/var/lib/postgresql/data
19
+ volumes:
20
+ postgres:
21
+ driver: local
data/hucpa.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "hucpa"
6
+ spec.version = "0.1.0"
7
+ spec.authors = ["Tomek Wałkuski"]
8
+ spec.email = "ja@jestem.tw"
9
+
10
+ spec.summary = "JRuby wrapper to HikariCP - JDBC connection pool"
11
+ spec.homepage = "https://github.com/tomekw/hucpa"
12
+ spec.license = "MIT"
13
+
14
+ spec.platform = "jruby"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.require_paths = %w[lib vendor]
20
+
21
+ spec.add_dependency "dry-validation", "~> 0.10"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "jdbc-postgres", "~> 9.4"
25
+ spec.add_development_dependency "rake", "~> 12.0"
26
+ spec.add_development_dependency "rspec", "~> 3.5"
27
+ spec.add_development_dependency "simplecov", "~> 0"
28
+ end
@@ -0,0 +1,117 @@
1
+ require "dry-validation"
2
+
3
+ import com.zaxxer.hikari.HikariConfig
4
+
5
+ module Hucpa
6
+ class Configuration
7
+ def initialize(options)
8
+ @options = options
9
+ end
10
+
11
+ def to_hikari_config
12
+ raise ArgumentError.new(validation_errors) if validation.failure?
13
+
14
+ HikariConfiguration.new.tap do |config|
15
+ CONFIGURATION_OPTIONS.each do |option|
16
+ option_setter = "#{option}="
17
+ option_value = send(option)
18
+
19
+ if config.respond_to?(option_setter) && !option_value.nil?
20
+ config.public_send(option_setter, option_value)
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :options
29
+
30
+ ADAPTERS = {
31
+ db2: "com.ibm.db2.jcc.DB2SimpleDataSource",
32
+ derby: "org.apache.derby.jdbc.ClientDataSource",
33
+ fdbsql: "com.foundationdb.sql.jdbc.ds.FDBSimpleDataSource",
34
+ firebird: "org.firebirdsql.pool.FBSimpleDataSource",
35
+ h2: "org.h2.jdbcx.JdbcDataSource",
36
+ hsqldb: "org.hsqldb.jdbc.JDBCDataSource",
37
+ mariadb: "org.mariadb.jdbc.MySQLDataSource",
38
+ mysql: "com.mysql.jdbc.jdbc2.optional.MysqlDataSource",
39
+ oracle: "oracle.jdbc.pool.OracleDataSource",
40
+ pgjdbc_ng: "com.impossibl.postgres.jdbc.PGDataSource",
41
+ postgresql: "org.postgresql.ds.PGSimpleDataSource",
42
+ sqlite: "org.sqlite.JDBC",
43
+ sqlserver: "com.microsoft.sqlserver.jdbc.SQLServerDataSource",
44
+ sqlserver_jtds: "net.sourceforge.jtds.jdbcx.JtdsDataSource",
45
+ sybase: "com.sybase.jdbcx.SybDataSource"
46
+ }
47
+ private_constant :ADAPTERS
48
+
49
+ VALIDATION_SCHEMA = Dry::Validation.Schema do
50
+ configure do
51
+ def self.messages
52
+ super.merge(
53
+ en: {
54
+ errors: {
55
+ :"adapter/jdbc_url options" => "are invalid. Either adapter or jdbc_url must be filled"
56
+ }
57
+ }
58
+ )
59
+ end
60
+ end
61
+
62
+ required(:password).filled(:str?)
63
+ required(:username).filled(:str?)
64
+
65
+ optional(:adapter).filled(included_in?: ADAPTERS.keys)
66
+ optional(:jdbc_url).filled(:str?)
67
+
68
+ optional(:auto_commit).filled(:bool?)
69
+ optional(:connection_test_query).filled(:str?)
70
+ optional(:connection_timeout).filled(:int?, gteq?: 250)
71
+ optional(:database_name).filled(:str?)
72
+ optional(:idle_timeout).filled { int? & (eql?(0) | gteq?(10_000)) }
73
+ optional(:max_lifetime).filled { int? & (eql?(0) | gteq?(30_000)) }
74
+ optional(:maximum_pool_size).filled(:int?, gteq?: 1)
75
+ optional(:minimum_idle).filled(:int?, gteq?: 1)
76
+ optional(:pool_name).filled(:str?)
77
+ optional(:server_name).filled(:str?)
78
+
79
+ rule(:"adapter/jdbc_url options" => %i[adapter jdbc_url]) do |adapter, jdbc_url|
80
+ adapter.filled? ^ jdbc_url.filled?
81
+ end
82
+ end
83
+ private_constant :VALIDATION_SCHEMA
84
+
85
+ CONFIGURATION_OPTIONS = VALIDATION_SCHEMA.rules.keys
86
+ private_constant :CONFIGURATION_OPTIONS
87
+
88
+ class HikariConfiguration < HikariConfig
89
+ def adapter=(value)
90
+ self.data_source_class_name = ADAPTERS.fetch(value)
91
+ end
92
+
93
+ def database=(value)
94
+ self.data_source_properties["databaseName"] = value
95
+ end
96
+
97
+ def server_name=(value)
98
+ self.data_source_properties["serverName"] = value
99
+ end
100
+ end
101
+ private_constant :HikariConfiguration
102
+
103
+ CONFIGURATION_OPTIONS.each do |param|
104
+ define_method(param) do
105
+ options.fetch(param, nil)
106
+ end
107
+ end
108
+
109
+ def validation
110
+ @validation ||= VALIDATION_SCHEMA.call(options)
111
+ end
112
+
113
+ def validation_errors
114
+ validation.messages(full: true).values.flatten.join(", ")
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,34 @@
1
+ import com.zaxxer.hikari.HikariDataSource
2
+
3
+ module Hucpa
4
+ class ConnectionPool
5
+ def initialize(options)
6
+ @options = options
7
+ @hikari_config = Configuration.new(options).to_hikari_config
8
+ end
9
+
10
+ def open
11
+ datasource
12
+ end
13
+
14
+ def close
15
+ datasource.close
16
+ end
17
+
18
+ def with_connection(&block)
19
+ conn = datasource.connection
20
+
21
+ block.call(conn)
22
+ ensure
23
+ conn.close
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :hikari_config, :options
29
+
30
+ def datasource
31
+ @datasource ||= HikariDataSource.new(hikari_config)
32
+ end
33
+ end
34
+ end
data/lib/hucpa.rb ADDED
@@ -0,0 +1,7 @@
1
+ Dir["vendor/*"].each { |f| require File.join(Dir.pwd, f) }
2
+
3
+ require "hucpa/configuration"
4
+ require "hucpa/connection_pool"
5
+
6
+ module Hucpa
7
+ end
Binary file
Binary file
Binary file
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hucpa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: jruby
6
+ authors:
7
+ - Tomek Wałkuski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.10'
19
+ name: dry-validation
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.13'
33
+ name: bundler
34
+ prerelease: false
35
+ type: :development
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '9.4'
47
+ name: jdbc-postgres
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '9.4'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '12.0'
61
+ name: rake
62
+ prerelease: false
63
+ type: :development
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.5'
75
+ name: rspec
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.5'
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ name: simplecov
90
+ prerelease: false
91
+ type: :development
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email: ja@jestem.tw
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".irbrc"
105
+ - ".rspec"
106
+ - CODE_OF_CONDUCT.md
107
+ - Dockerfile
108
+ - Gemfile
109
+ - Gemfile.lock
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - circle.yml
114
+ - docker-compose.yml
115
+ - hucpa.gemspec
116
+ - lib/hucpa.rb
117
+ - lib/hucpa/configuration.rb
118
+ - lib/hucpa/connection_pool.rb
119
+ - vendor/HikariCP-2.5.1.jar
120
+ - vendor/slf4j-api-1.7.21.jar
121
+ - vendor/slf4j-nop-1.7.21.jar
122
+ homepage: https://github.com/tomekw/hucpa
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ - vendor
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.8
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: JRuby wrapper to HikariCP - JDBC connection pool
147
+ test_files: []