Skip to content

Commit

Permalink
A few miscellaneous fixes:
Browse files Browse the repository at this point in the history
1. Java 8 compatibility for now - see changes in JdbcUrlUtils
2. Change POM version to 1.00.RC2-SNAPSHOT
  • Loading branch information
mikebell90 committed Jan 19, 2022
1 parent c2e4b1a commit 33cf006
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
OpenTable Embedded PostgreSQL Component
=======================================

Note: This library requires Java 11+.
Note: This library requires Java 8+.

Allows embedding PostgreSQL into Java application code, using Docker containers.
Excellent for allowing you to unit
Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@

<groupId>com.opentable.components</groupId>
<artifactId>otj-pg-embedded</artifactId>
<version>1.0.1.RC1-SNAPSHOT</version>
<version>1.0.0.RC2-SNAPSHOT</version>
<description>Embedded PostgreSQL driver</description>

<properties>
<project.build.targetJdk>11</project.build.targetJdk>
<basepom.test.timeout>1800</basepom.test.timeout>
<basepom.oss.skip-scala-doc>true</basepom.oss.skip-scala-doc>
<basepom.check.skip-javadoc>false</basepom.check.skip-javadoc>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
*/
package com.opentable.db.postgres.embedded;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

final class JdbcUrlUtils {

Expand Down Expand Up @@ -50,17 +51,17 @@ static int getPort(final String url) {
* @return Modified Url
* @throws URISyntaxException If Url violates RFC&nbsp;2396
*/
static String addUsernamePassword(final String url, final String userName, final String password) throws URISyntaxException {
static String addUsernamePassword(final String url, final String userName, final String password) throws URISyntaxException, UnsupportedEncodingException {
final URI uri = URI.create(url.substring(JDBC_URL_PREFIX.length()));
final Map<String, String> params = new HashMap<>(
Optional.ofNullable(uri.getQuery())
.stream()
.map(Stream::of).orElse(Stream.empty())// Hack around the fact Optional.Stream requires Java 9+.
.flatMap(par -> Arrays.stream(par.split("&")))
.map(part -> part.split("="))
.filter(part -> part.length > 1)
.collect(Collectors.toMap(part -> part[0], part -> part[1])));
params.put("user", URLEncoder.encode(userName, StandardCharsets.UTF_8));
params.put("password", URLEncoder.encode(password, StandardCharsets.UTF_8));
params.put("user", URLEncoder.encode(userName, "UTF-8")); // Use the old form for Java 8 compatibility.
params.put("password", URLEncoder.encode(password, "UTF-8"));
return JDBC_URL_PREFIX + new URI(uri.getScheme(),
uri.getUserInfo(),
uri.getHost(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.opentable.db.postgres.embedded;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -100,7 +101,7 @@ public String createDatabase() throws SQLException {
}
try {
return JdbcUrlUtils.addUsernamePassword(info.getUrl(), info.getUser(), info.getPassword());
} catch (URISyntaxException e) {
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new SQLException(e);
}
}
Expand Down

2 comments on commit 33cf006

@opentable-devops
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Architecture Team / Java TC Platform / otj-pg-embedded / PR Build Build ???.164/merge.123 is now running

@opentable-devops
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity Architecture Team / Java TC Platform / otj-pg-embedded / PR Build Build 1.0.0.RC2-SNAPSHOT.164/merge.123 outcome was SUCCESS
Summary: Tests passed: 13, ignored: 2 Build time: 00:02:01

Please sign in to comment.