Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions coverage-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,25 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<version>${netty.version}</version>
</dependency>

<dependency>
<groupId>com.impossibl.pgjdbc-ng</groupId>
<artifactId>pgjdbc-ng</artifactId>
<version>0.7.1</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</exclusion>
</exclusions>
</dependency>

</dependencies>

</project>
7 changes: 7 additions & 0 deletions jooby-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
<artifactId>HikariCP</artifactId>
</dependency>

<dependency>
<groupId>com.impossibl.pgjdbc-ng</groupId>
<artifactId>pgjdbc-ng</artifactId>
<version>0.7.1</version>
<optional>true</optional>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.impossibl.postgres.jdbc;

import java.net.InetSocketAddress;

import com.impossibl.postgres.jdbc.ConnectionUtil.ConnectionSpecifier;

// Hack documented here: https://github.com/impossibl/pgjdbc-ng/issues/323
public class PGDataSourceWithUrl extends PGDataSource {

private String url;

public String getUrl() {
return url;
}

public void setUrl(final String url) {
this.url = url;
ConnectionSpecifier specifier = ConnectionUtil.parseURL(url);
setDatabase(specifier.getDatabase());
InetSocketAddress address = specifier.getAddresses().get(0);
setHost(address.getHostString());
setPort(address.getPort());
}

}
5 changes: 1 addition & 4 deletions jooby-jdbc/src/main/java/org/jooby/jdbc/Jdbc.java
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,7 @@ private HikariConfig hikariConfig(final String url, final String key, final Stri
dataSourceClassName = props.getProperty("dataSource.dataSourceClassName");
props.setProperty("dataSourceClassName", dataSourceClassName);
}
if (Strings.isNullOrEmpty(dataSourceClassName)) {
// Hack old drivers without a setUrl method (pgsql)
props.put("jdbcUrl", url);
}

// remove dataSourceClassName under dataSource
props.remove("dataSource.dataSourceClassName");
// set pool name
Expand Down
8 changes: 2 additions & 6 deletions jooby-jdbc/src/main/resources/org/jooby/jdbc/jdbc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,15 @@ databases {
# url => jdbc:pgsql://<server>[:<port>]/<database>
###############################################################################################
pgsql {
# empty bc dataSource.setUrl missing
# dataSourceClassName = com.impossibl.postgres.jdbc.PGDataSource
dataSourceClassName = ""
dataSourceClassName = com.impossibl.postgres.jdbc.PGDataSourceWithUrl
}

###############################################################################################
# postgresql
# url => jdbc:postgresql://host:port/database
###############################################################################################
postgresql {
# empty bc dataSource.setUrl missing
# dataSourceClassName = org.postgresql.ds.PGSimpleDataSource
dataSourceClassName = ""
dataSourceClassName = org.postgresql.ds.PGSimpleDataSource
}

###############################################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.impossibl.postgres.jdbc;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class PGDataSourceWithUrlTest {

@Test
public void setUrl() {
PGDataSourceWithUrl ds = new PGDataSourceWithUrl();
ds.setUrl("jdbc:pgsql://server/database");
assertEquals("server", ds.getHost());
assertEquals(5432, ds.getPort());
assertEquals("database", ds.getDatabase());
assertEquals("jdbc:pgsql://server/database", ds.getUrl());
}

@Test
public void setUrlPort() {
PGDataSourceWithUrl ds = new PGDataSourceWithUrl();
ds.setUrl("jdbc:pgsql://server:1234/database");
assertEquals("server", ds.getHost());
assertEquals(1234, ds.getPort());
assertEquals("database", ds.getDatabase());
}
}
15 changes: 4 additions & 11 deletions jooby-jdbc/src/test/java/org/jooby/jdbc/JdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,12 @@ public void pgsql() throws Exception {
.resolve();

new MockUnit(Env.class, Config.class, Binder.class)
.expect(props("", "jdbc:pgsql://server/database",
"pgsql.database", null, "", false))
.expect(
props("com.impossibl.postgres.jdbc.PGDataSourceWithUrl", "jdbc:pgsql://server/database",
"pgsql.database", null, "", false))
.expect(hikariConfig())
.expect(hikariDataSource())
.expect(serviceKey("database"))
.expect(unit -> {
Properties props = unit.get(Properties.class);
expect(props.put("jdbcUrl", url)).andReturn(null);
})
.expect(onStop)
.run(unit -> {
new Jdbc().configure(unit.get(Env.class), dbconf, unit.get(Binder.class));
Expand All @@ -544,15 +541,11 @@ public void postgresql() throws Exception {
.resolve();

new MockUnit(Env.class, Config.class, Binder.class)
.expect(props("", "jdbc:postgresql://server/database",
.expect(props("org.postgresql.ds.PGSimpleDataSource", "jdbc:postgresql://server/database",
"postgresql.database", null, "", false))
.expect(hikariConfig())
.expect(hikariDataSource())
.expect(serviceKey("database"))
.expect(unit -> {
Properties props = unit.get(Properties.class);
expect(props.put("jdbcUrl", url)).andReturn(null);
})
.expect(onStop)
.run(unit -> {
new Jdbc().configure(unit.get(Env.class), dbconf, unit.get(Binder.class));
Expand Down
6 changes: 6 additions & 0 deletions jooby-netty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<version>${netty.version}</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<version>${netty.version}</version>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</artifactId>
Expand Down