hucpa 0.2.5-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.irbrc +2 -0
- data/.rspec +2 -0
- data/.rubocop.yml +42 -0
- data/CHANGELOG.md +27 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile +12 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +89 -0
- data/LICENSE.txt +21 -0
- data/README.md +179 -0
- data/Rakefile +10 -0
- data/circle.yml +17 -0
- data/docker-compose.yml +22 -0
- data/hucpa.gemspec +29 -0
- data/lib/HikariCP-2.6.1.jar +0 -0
- data/lib/hucpa.rb +7 -0
- data/lib/hucpa/configuration.rb +117 -0
- data/lib/hucpa/connection_pool.rb +34 -0
- data/lib/slf4j-api-1.7.24.jar +0 -0
- data/lib/slf4j-nop-1.7.24.jar +0 -0
- data/lib/tasks/ci.rake +8 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 87b647f8c1e1b11c83c37ba2158ed1629e5046aa
|
4
|
+
data.tar.gz: 483cccecfc3040cf408294a391cbd6cfc2eea074
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9d82dab5d87d8a5bf8e669cb328bcfd4e27356f0da75fab77676862f01a6e2a77fd9d8438ba8da81d797eac8015e990886ab341d64edc7ba6e8cc1d10885f671
|
7
|
+
data.tar.gz: 52e8c0ac904cfd21f86c5f5befa0ef7f47b6b11a23349788176ac1370495af9b0a474ea86aab08822a3a064ba92746fedf135eeb89235e06106e9c7acb007cdd
|
data/.gitignore
ADDED
data/.irbrc
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
Documentation:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/BlockLength:
|
8
|
+
Max: 32
|
9
|
+
Exclude:
|
10
|
+
- "spec/**/*.rb"
|
11
|
+
|
12
|
+
Metrics/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Style/AndOr:
|
16
|
+
EnforcedStyle: conditionals
|
17
|
+
|
18
|
+
Style/Encoding:
|
19
|
+
EnforcedStyle: when_needed
|
20
|
+
|
21
|
+
Style/FrozenStringLiteralComment:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/IndentHash:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/PercentLiteralDelimiters:
|
28
|
+
PreferredDelimiters:
|
29
|
+
"%i": "[]"
|
30
|
+
"%I": "[]"
|
31
|
+
"%w": "[]"
|
32
|
+
"%W": "[]"
|
33
|
+
|
34
|
+
Style/RedundantSelf:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/SignalException:
|
38
|
+
Enabled: true
|
39
|
+
EnforcedStyle: semantic
|
40
|
+
|
41
|
+
Style/StringLiterals:
|
42
|
+
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
## 0.2.5
|
2
|
+
|
3
|
+
* upgraded `HikariCP` to `2.6.1`
|
4
|
+
|
5
|
+
## 0.2.4
|
6
|
+
|
7
|
+
* bring back updated `slf4j-nop` jar
|
8
|
+
|
9
|
+
## 0.2.3
|
10
|
+
|
11
|
+
* do not include `slf4j-nop` jar
|
12
|
+
|
13
|
+
## 0.2.2
|
14
|
+
|
15
|
+
* fixed setting `database_name` configuration option
|
16
|
+
|
17
|
+
## 0.2.1
|
18
|
+
|
19
|
+
* fixed importing `HikariCP` jars
|
20
|
+
|
21
|
+
## 0.2.0
|
22
|
+
|
23
|
+
* upgraded `HikariCP` to `2.6.0`
|
24
|
+
|
25
|
+
## 0.1.0
|
26
|
+
|
27
|
+
* initial release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hucpa (0.2.5-java)
|
5
|
+
dry-validation (~> 0.10)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.3.0)
|
11
|
+
concurrent-ruby (1.0.5-java)
|
12
|
+
diff-lcs (1.3)
|
13
|
+
docile (1.1.5)
|
14
|
+
dry-configurable (0.6.2)
|
15
|
+
concurrent-ruby (~> 1.0)
|
16
|
+
dry-container (0.6.0)
|
17
|
+
concurrent-ruby (~> 1.0)
|
18
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
19
|
+
dry-core (0.2.4)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
dry-equalizer (0.2.0)
|
22
|
+
dry-logic (0.4.1)
|
23
|
+
dry-container (~> 0.2, >= 0.2.6)
|
24
|
+
dry-core (~> 0.2)
|
25
|
+
dry-equalizer (~> 0.2)
|
26
|
+
dry-types (0.9.4)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
dry-configurable (~> 0.1)
|
29
|
+
dry-container (~> 0.3)
|
30
|
+
dry-core (~> 0.2, >= 0.2.1)
|
31
|
+
dry-equalizer (~> 0.2)
|
32
|
+
dry-logic (~> 0.4, >= 0.4.0)
|
33
|
+
inflecto (~> 0.0.0, >= 0.0.2)
|
34
|
+
dry-validation (0.10.5)
|
35
|
+
concurrent-ruby (~> 1.0)
|
36
|
+
dry-configurable (~> 0.1, >= 0.1.3)
|
37
|
+
dry-core (~> 0.2, >= 0.2.1)
|
38
|
+
dry-equalizer (~> 0.2)
|
39
|
+
dry-logic (~> 0.4, >= 0.4.0)
|
40
|
+
dry-types (~> 0.9, >= 0.9.0)
|
41
|
+
inflecto (0.0.2)
|
42
|
+
jdbc-postgres (9.4.1206)
|
43
|
+
json (2.0.3-java)
|
44
|
+
parser (2.4.0.0)
|
45
|
+
ast (~> 2.2)
|
46
|
+
powerpack (0.1.1)
|
47
|
+
rainbow (2.2.1)
|
48
|
+
rake (12.0.0)
|
49
|
+
rspec (3.5.0)
|
50
|
+
rspec-core (~> 3.5.0)
|
51
|
+
rspec-expectations (~> 3.5.0)
|
52
|
+
rspec-mocks (~> 3.5.0)
|
53
|
+
rspec-core (3.5.4)
|
54
|
+
rspec-support (~> 3.5.0)
|
55
|
+
rspec-expectations (3.5.0)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.5.0)
|
58
|
+
rspec-mocks (3.5.0)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.5.0)
|
61
|
+
rspec-support (3.5.0)
|
62
|
+
rubocop (0.47.1)
|
63
|
+
parser (>= 2.3.3.1, < 3.0)
|
64
|
+
powerpack (~> 0.1)
|
65
|
+
rainbow (>= 1.99.1, < 3.0)
|
66
|
+
ruby-progressbar (~> 1.7)
|
67
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
68
|
+
ruby-progressbar (1.8.1)
|
69
|
+
simplecov (0.13.0)
|
70
|
+
docile (~> 1.1.0)
|
71
|
+
json (>= 1.8, < 3)
|
72
|
+
simplecov-html (~> 0.10.0)
|
73
|
+
simplecov-html (0.10.0)
|
74
|
+
unicode-display_width (1.1.3)
|
75
|
+
|
76
|
+
PLATFORMS
|
77
|
+
java
|
78
|
+
|
79
|
+
DEPENDENCIES
|
80
|
+
bundler (~> 1.13)
|
81
|
+
hucpa!
|
82
|
+
jdbc-postgres (~> 9.4)
|
83
|
+
rake (~> 12.0)
|
84
|
+
rspec (~> 3.5)
|
85
|
+
rubocop (~> 0)
|
86
|
+
simplecov (~> 0)
|
87
|
+
|
88
|
+
BUNDLED WITH
|
89
|
+
1.14.6
|
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,179 @@
|
|
1
|
+
# Hucpa
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/tomekw/hucpa/badges/gpa.svg)](https://codeclimate.com/github/tomekw/hucpa) [![Gem Version](https://badge.fury.io/rb/hucpa.svg)](https://badge.fury.io/rb/hucpa) [![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
|
+
Please note the project support only JRuby (tested with 9.1.8.0+) on Java 8.
|
9
|
+
|
10
|
+
The public API is subject to change before version `1.0.0`.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "hucpa"
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install hucpa
|
27
|
+
|
28
|
+
## Configuration options
|
29
|
+
|
30
|
+
See [HikariCP Documentation](https://github.com/brettwooldridge/HikariCP#configuration-knobs-baby) for a detailed description.
|
31
|
+
Not all HikariCP-defined configuration options are currently supported. To add support for infrequently used options please
|
32
|
+
raise an issue or file a pull request.
|
33
|
+
|
34
|
+
| Option | Required | Default value | Notes |
|
35
|
+
| ----------------------- | :------: | ------------- | ----------------------------------------------------------------------- |
|
36
|
+
| `adapter` | Yes(1) | - | Symbol |
|
37
|
+
| `auto_commit` | No | `true` | Boolean |
|
38
|
+
| `connection_test_query` | No | - | String |
|
39
|
+
| `connection_timeout` | No | `30_000` | Integer, greater than or equal to 250, in miliseconds |
|
40
|
+
| `database_name` | No | - | String |
|
41
|
+
| `idle_timeout` | No | `600_000` | Integer, 0 (disabled) or greater than or equal to 10000, in miliseconds |
|
42
|
+
| `jdbc_url` | Yes(1) | - | String |
|
43
|
+
| `max_lifetime` | No | `1_800_000` | Integer, 0 (disabled) or greater than or equal to 30000, in miliseconds |
|
44
|
+
| `maximum_pool_size` | No | `10` | Integer, greater than or equal to 1 |
|
45
|
+
| `minimum_idle` | No | `10` | Integer, greater than or equal to 1 |
|
46
|
+
| `password` | Yes | - | String |
|
47
|
+
| `pool_name` | No | - | String |
|
48
|
+
| `server_name` | No | - | String |
|
49
|
+
| `username` | Yes | - | String |
|
50
|
+
|
51
|
+
`(1)` - either `adapter` or `jdbc_url` has to be provided.
|
52
|
+
|
53
|
+
## Supported adapters and corresponding datasource class names
|
54
|
+
|
55
|
+
| Adapter | Datasource class name |
|
56
|
+
| ---------------- | -------------------------------------------------- |
|
57
|
+
| `db2` | `com.ibm.db2.jcc.DB2SimpleDataSource` |
|
58
|
+
| `derby` | `org.apache.derby.jdbc.ClientDataSource` |
|
59
|
+
| `fdbsql` | `com.foundationdb.sql.jdbc.ds.FDBSimpleDataSource` |
|
60
|
+
| `firebird` | `org.firebirdsql.pool.FBSimpleDataSource` |
|
61
|
+
| `h2` | `org.h2.jdbcx.JdbcDataSource` |
|
62
|
+
| `hsqldb` | `org.hsqldb.jdbc.JDBCDataSource` |
|
63
|
+
| `mariadb` | `org.mariadb.jdbc.MySQLDataSource` |
|
64
|
+
| `mysql` | `com.mysql.jdbc.jdbc2.optional.MysqlDataSource` |
|
65
|
+
| `oracle` | `oracle.jdbc.pool.OracleDataSource` |
|
66
|
+
| `pgjdbc_ng` | `com.impossibl.postgres.jdbc.PGDataSource` |
|
67
|
+
| `postgresql` | `org.postgresql.ds.PGSimpleDataSource` |
|
68
|
+
| `sqlite` | `org.sqlite.JDBC` |
|
69
|
+
| `sqlserver_jtds` | `net.sourceforge.jtds.jdbcx.JtdsDataSource` |
|
70
|
+
| `sqlserver` | `com.microsoft.sqlserver.jdbc.SQLServerDataSource` |
|
71
|
+
| `sybase` | `com.sybase.jdbcx.SybDataSource` |
|
72
|
+
|
73
|
+
## Usage
|
74
|
+
|
75
|
+
Install the database driver, for PostgreSQL:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
gem "jdbc-postgres"
|
79
|
+
```
|
80
|
+
|
81
|
+
Load the the database driver if needed, for PostgreSQL:
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
require "jdbc/postgres"
|
85
|
+
Jdbc::Postgres.load_driver
|
86
|
+
```
|
87
|
+
|
88
|
+
Configure the connection pool:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
# Using the adapter option
|
92
|
+
options = {
|
93
|
+
adapter: :postgresql,
|
94
|
+
database_name: "hucpa",
|
95
|
+
password: "hucpa",
|
96
|
+
server_name: "postgres",
|
97
|
+
username: "hucpa"
|
98
|
+
}
|
99
|
+
|
100
|
+
# Using the jdbc_url option
|
101
|
+
options = {
|
102
|
+
jdbc_url: "jdbc:postgresql://postgres/hucpa",
|
103
|
+
password: "hucpa",
|
104
|
+
username: "hucpa"
|
105
|
+
}
|
106
|
+
|
107
|
+
connection_pool = Hucpa::ConnectionPool.new(options)
|
108
|
+
```
|
109
|
+
|
110
|
+
Use the connection pool with the `with_connection` API:
|
111
|
+
|
112
|
+
|
113
|
+
```ruby
|
114
|
+
answer = connection_pool.with_connection do |connection|
|
115
|
+
result_set =
|
116
|
+
connection
|
117
|
+
.create_statement
|
118
|
+
.execute_query("SELECT 42 AS answer")
|
119
|
+
|
120
|
+
result_set.next and result_set.get_int("answer")
|
121
|
+
end
|
122
|
+
|
123
|
+
answer
|
124
|
+
=> 42
|
125
|
+
```
|
126
|
+
|
127
|
+
Or use the connection pool with the "classic" API:
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
datasource = connection_pool.open
|
131
|
+
|
132
|
+
# Explicitly obtain the DB connection
|
133
|
+
connection = datasource.connection
|
134
|
+
|
135
|
+
result_set =
|
136
|
+
connection
|
137
|
+
.create_statement
|
138
|
+
.execute_query("SELECT 42 AS answer")
|
139
|
+
|
140
|
+
answer = result_set.next and result_set.get_int("answer")
|
141
|
+
|
142
|
+
# Explicitly release the DB connection
|
143
|
+
connection.close
|
144
|
+
|
145
|
+
answer
|
146
|
+
=> 42
|
147
|
+
```
|
148
|
+
|
149
|
+
Close the connection pool:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
connection_pool.close
|
153
|
+
```
|
154
|
+
|
155
|
+
## Development
|
156
|
+
|
157
|
+
Build the Docker image:
|
158
|
+
|
159
|
+
$ docker-compose build
|
160
|
+
|
161
|
+
Create services:
|
162
|
+
|
163
|
+
$ docker-compose create
|
164
|
+
|
165
|
+
Run specs:
|
166
|
+
|
167
|
+
$ docker-compose run --rm app rspec spec
|
168
|
+
|
169
|
+
Run console:
|
170
|
+
|
171
|
+
$ docker-compose run --rm app irb
|
172
|
+
|
173
|
+
## Contributing
|
174
|
+
|
175
|
+
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.
|
176
|
+
|
177
|
+
## License
|
178
|
+
|
179
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,17 @@
|
|
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 rubocop
|
17
|
+
- docker run --net=host --env DATABASE_HOST=localhost --rm tomekw/hucpa rspec spec
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
+
- ${HOME}/.gem:/root/.gem:rw
|
13
|
+
postgres:
|
14
|
+
environment:
|
15
|
+
POSTGRES_USER: hucpa
|
16
|
+
POSTGRES_PASSWORD: hucpa
|
17
|
+
image: postgres:9.6.2
|
18
|
+
volumes:
|
19
|
+
- postgres:/var/lib/postgresql/data
|
20
|
+
volumes:
|
21
|
+
postgres:
|
22
|
+
driver: local
|
data/hucpa.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
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.2.5"
|
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 = "java"
|
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]
|
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 "rubocop", "~> 0"
|
28
|
+
spec.add_development_dependency "simplecov", "~> 0"
|
29
|
+
end
|
Binary file
|
data/lib/hucpa.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require "dry-validation"
|
2
|
+
|
3
|
+
module Hucpa
|
4
|
+
class Configuration
|
5
|
+
java_import com.zaxxer.hikari.HikariConfig
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@options = options
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_hikari_config
|
12
|
+
fail ArgumentError, 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
|
+
}.freeze
|
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_name=(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
|
+
module Hucpa
|
2
|
+
class ConnectionPool
|
3
|
+
java_import com.zaxxer.hikari.HikariDataSource
|
4
|
+
|
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
|
19
|
+
conn = datasource.connection
|
20
|
+
|
21
|
+
yield 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
|
Binary file
|
Binary file
|
data/lib/tasks/ci.rake
ADDED
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hucpa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.5
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Tomek Wałkuski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-06 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: rubocop
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
name: simplecov
|
104
|
+
prerelease: false
|
105
|
+
type: :development
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email: ja@jestem.tw
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files: []
|
116
|
+
files:
|
117
|
+
- ".gitignore"
|
118
|
+
- ".irbrc"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- CHANGELOG.md
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Dockerfile
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- circle.yml
|
130
|
+
- docker-compose.yml
|
131
|
+
- hucpa.gemspec
|
132
|
+
- lib/HikariCP-2.6.1.jar
|
133
|
+
- lib/hucpa.rb
|
134
|
+
- lib/hucpa/configuration.rb
|
135
|
+
- lib/hucpa/connection_pool.rb
|
136
|
+
- lib/slf4j-api-1.7.24.jar
|
137
|
+
- lib/slf4j-nop-1.7.24.jar
|
138
|
+
- lib/tasks/ci.rake
|
139
|
+
homepage: https://github.com/tomekw/hucpa
|
140
|
+
licenses:
|
141
|
+
- MIT
|
142
|
+
metadata: {}
|
143
|
+
post_install_message:
|
144
|
+
rdoc_options: []
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
requirements: []
|
158
|
+
rubyforge_project:
|
159
|
+
rubygems_version: 2.6.8
|
160
|
+
signing_key:
|
161
|
+
specification_version: 4
|
162
|
+
summary: JRuby wrapper to HikariCP - JDBC connection pool
|
163
|
+
test_files: []
|