From 29d48022537e3f7e66780c4f5ca10bd1becad350 Mon Sep 17 00:00:00 2001 From: Mark Simundson Date: Wed, 20 May 2015 18:36:29 -0500 Subject: [PATCH 1/7] Adding choice to use stand-alone PostgreSQL instances --- .../commons/embeddeddb/EmbeddedDB.java | 3 +- embeddeddb/pom.xml | 1 + embeddeddb/postgresql/pom.xml | 45 ++++++++++ .../postgresql/PostgreSQLStandaloneDB.java | 83 +++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 embeddeddb/postgresql/pom.xml create mode 100644 embeddeddb/postgresql/src/main/java/org/killbill/commons/embeddeddb/postgresql/PostgreSQLStandaloneDB.java diff --git a/embeddeddb/common/src/main/java/org/killbill/commons/embeddeddb/EmbeddedDB.java b/embeddeddb/common/src/main/java/org/killbill/commons/embeddeddb/EmbeddedDB.java index 2020fd49..422c69b4 100644 --- a/embeddeddb/common/src/main/java/org/killbill/commons/embeddeddb/EmbeddedDB.java +++ b/embeddeddb/common/src/main/java/org/killbill/commons/embeddeddb/EmbeddedDB.java @@ -37,7 +37,8 @@ public abstract class EmbeddedDB { public enum DBEngine { GENERIC, MYSQL, - H2 + H2, + POSTGRESQL } // Not final to allow more flexible implementers diff --git a/embeddeddb/pom.xml b/embeddeddb/pom.xml index f37abb3f..c99d5304 100644 --- a/embeddeddb/pom.xml +++ b/embeddeddb/pom.xml @@ -29,5 +29,6 @@ common h2 mysql + postgresql diff --git a/embeddeddb/postgresql/pom.xml b/embeddeddb/postgresql/pom.xml new file mode 100644 index 00000000..d414bd72 --- /dev/null +++ b/embeddeddb/postgresql/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + + killbill-embeddeddb + org.kill-bill.commons + 0.4-SNAPSHOT + ../pom.xml + + killbill-embeddeddb-postgresql + Kill Bill library of embedded dbs: PostgreSQL + + + org.kill-bill.commons + killbill-embeddeddb-common + ${project.version} + + + org.postgresql + postgresql + 9.4-1201-jdbc41 + + + org.slf4j + slf4j-api + + + diff --git a/embeddeddb/postgresql/src/main/java/org/killbill/commons/embeddeddb/postgresql/PostgreSQLStandaloneDB.java b/embeddeddb/postgresql/src/main/java/org/killbill/commons/embeddeddb/postgresql/PostgreSQLStandaloneDB.java new file mode 100644 index 00000000..05544e47 --- /dev/null +++ b/embeddeddb/postgresql/src/main/java/org/killbill/commons/embeddeddb/postgresql/PostgreSQLStandaloneDB.java @@ -0,0 +1,83 @@ +/* + * Copyright 2010-2013 Ning, Inc. + * Copyright 2014-2015 Groupon, Inc + * Copyright 2014-2015 The Billing Project, LLC + * + * The Billing Project 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 org.killbill.commons.embeddeddb.postgresql; + +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; + +import javax.sql.DataSource; + +import org.killbill.commons.embeddeddb.GenericStandaloneDB; +import org.postgresql.ds.PGSimpleDataSource; + +/** + * Delegates to a real PostgreSQL database. This can be used for debugging. + */ +public class PostgreSQLStandaloneDB extends GenericStandaloneDB { + + protected PGSimpleDataSource dataSource; + + public PostgreSQLStandaloneDB(final String databaseName, final String username, final String password) { + this(databaseName, username, password, "jdbc:postgresql://localhost:5432/" + databaseName); + } + + public PostgreSQLStandaloneDB(final String databaseName, final String username, final String password, final String jdbcConnectionString) { + super(databaseName, username, password, jdbcConnectionString); + } + + @Override + public DBEngine getDBEngine() { + return DBEngine.POSTGRESQL; + } + + @Override + public void initialize() throws IOException { + super.initialize(); + dataSource = new PGSimpleDataSource(); + dataSource.setDatabaseName(databaseName); + dataSource.setUser(username); + dataSource.setPassword(password); + dataSource.setUrl(jdbcConnectionString); + } + + @Override + public void refreshTableNames() throws IOException { + final String query = String.format("select table_name from information_schema.tables where table_schema = '%s' and table_type = 'BASE TABLE';", databaseName); + try { + executeQuery(query, new ResultSetJob() { + @Override + public void work(final ResultSet resultSet) throws SQLException { + allTables.clear(); + while (resultSet.next()) { + allTables.add(resultSet.getString(1)); + } + } + }); + } catch (final SQLException e) { + throw new IOException(e); + } + } + + @Override + public DataSource getDataSource() throws IOException { + return dataSource; + } + +} From cfed19d889a21191928dc0fc47e44e8d758b6991 Mon Sep 17 00:00:00 2001 From: Mark Simundson Date: Fri, 22 May 2015 18:46:15 -0500 Subject: [PATCH 2/7] Columns that are dates must be sent as dates --- .../commons/jdbi/argument/LocalDateArgumentFactory.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java b/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java index a3bd7d1f..69915aaf 100644 --- a/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java +++ b/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java @@ -47,7 +47,9 @@ public LocalDateArgument(final LocalDate value) { @Override public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException { - if (value != null) { + if (value != null && "PostgreSQL".equalsIgnoreCase(ctx.getConnection().getMetaData().getDatabaseProductName())) { + statement.setDate(position, new java.sql.Date(value.toDate().getTime())); + } else if (value != null) { // ISO8601 format statement.setString(position, value.toString()); } else { From b93ba60a3488b2e9ed8f96451d7f3101d23efe9a Mon Sep 17 00:00:00 2001 From: Mark Simundson Date: Wed, 27 May 2015 12:01:57 -0500 Subject: [PATCH 3/7] Generalize the sending of date parameters --- .../commons/jdbi/argument/LocalDateArgumentFactory.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java b/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java index 69915aaf..5f96147f 100644 --- a/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java +++ b/jdbi/src/main/java/org/killbill/commons/jdbi/argument/LocalDateArgumentFactory.java @@ -47,13 +47,10 @@ public LocalDateArgument(final LocalDate value) { @Override public void apply(final int position, final PreparedStatement statement, final StatementContext ctx) throws SQLException { - if (value != null && "PostgreSQL".equalsIgnoreCase(ctx.getConnection().getMetaData().getDatabaseProductName())) { + if (value != null) { statement.setDate(position, new java.sql.Date(value.toDate().getTime())); - } else if (value != null) { - // ISO8601 format - statement.setString(position, value.toString()); } else { - statement.setNull(position, Types.VARCHAR); + statement.setNull(position, Types.DATE); } } From 3f38c822698dd2d52d59a9f39fc556ae44aa6fce Mon Sep 17 00:00:00 2001 From: David Concha Date: Thu, 28 May 2015 20:32:16 -0500 Subject: [PATCH 4/7] updating parent --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 33954bf5..a269d4a4 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ killbill-oss-parent org.kill-bill.billing - 0.11 + 0.13-SNAPSHOT org.kill-bill.commons killbill-commons From e356393fc18918815f733e42f4a8243a189ef5d7 Mon Sep 17 00:00:00 2001 From: marksimu Date: Tue, 2 Jun 2015 09:42:44 -0700 Subject: [PATCH 5/7] Add new DataSourceProvider --- .../commons/jdbi/guice/DataSourceProvider.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jdbi/src/main/java/org/killbill/commons/jdbi/guice/DataSourceProvider.java b/jdbi/src/main/java/org/killbill/commons/jdbi/guice/DataSourceProvider.java index b4a088d4..f89e4064 100644 --- a/jdbi/src/main/java/org/killbill/commons/jdbi/guice/DataSourceProvider.java +++ b/jdbi/src/main/java/org/killbill/commons/jdbi/guice/DataSourceProvider.java @@ -51,7 +51,7 @@ public class DataSourceProvider implements Provider { @VisibleForTesting static enum DatabaseType { - GENERIC, MYSQL, H2 + GENERIC, MYSQL, H2, POSTGRESQL } @Inject @@ -286,6 +286,14 @@ private void parseJDBCUrl() { if (driverClassName == null) { driverClassName = "org.h2.Driver"; } + } else if ("postgresql".equals(uri.getScheme())) { + databaseType = DatabaseType.POSTGRESQL; + if (dataSourceClassName == null) { + dataSourceClassName = "org.postgresql.ds.PGSimpleDataSource"; + } + if (driverClassName == null) { + driverClassName = "org.postgresql.Driver"; + } } else { databaseType = DatabaseType.GENERIC; } From b53e8a1f3a5db57d02536ec443d63e928a7a5a22 Mon Sep 17 00:00:00 2001 From: David Concha Date: Wed, 24 Jun 2015 18:04:42 -0500 Subject: [PATCH 6/7] preparing release build --- .gitignore | 4 +++- pom.xml | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d1da0865..9c00bc41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ *.idea *.iml - +*.project +*.classpath *.class +.settings # Package Files # *.jar diff --git a/pom.xml b/pom.xml index a269d4a4..6a748c1b 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ killbill-oss-parent org.kill-bill.billing - 0.13-SNAPSHOT + 0.13.3 org.kill-bill.commons killbill-commons From 692b57c46dd172153e1c36d9793b4546df427a97 Mon Sep 17 00:00:00 2001 From: lvieira-rl Date: Wed, 4 Jun 2025 12:41:13 -0300 Subject: [PATCH 7/7] [RLSEC-3540] Upgrade MySQL connector --- jdbi/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/jdbi/pom.xml b/jdbi/pom.xml index f384e2e2..b54cc22e 100644 --- a/jdbi/pom.xml +++ b/jdbi/pom.xml @@ -74,6 +74,7 @@ mysql mysql-connector-java + 5.1.49 test