killbill-uncached
Changes
util/pom.xml 5(+5 -0)
Details
util/pom.xml 5(+5 -0)
diff --git a/util/pom.xml b/util/pom.xml
index 81502d4..f1616a7 100644
--- a/util/pom.xml
+++ b/util/pom.xml
@@ -74,6 +74,11 @@
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
+ <groupId>com.ning</groupId>
+ <artifactId>compress-lzf</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>com.samskivert</groupId>
<artifactId>jmustache</artifactId>
</dependency>
diff --git a/util/src/main/java/org/killbill/billing/util/export/dao/DatabaseExportDao.java b/util/src/main/java/org/killbill/billing/util/export/dao/DatabaseExportDao.java
index 1f37627..0f99263 100644
--- a/util/src/main/java/org/killbill/billing/util/export/dao/DatabaseExportDao.java
+++ b/util/src/main/java/org/killbill/billing/util/export/dao/DatabaseExportDao.java
@@ -16,6 +16,7 @@
package org.killbill.billing.util.export.dao;
+import java.sql.Blob;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -160,6 +161,17 @@ public class DatabaseExportDao {
try {
while (iterator.hasNext()) {
final Map<String, Object> row = iterator.next();
+
+ for (final String k : row.keySet()) {
+ final Object value = row.get(k);
+ // For h2, transform a JdbcBlob into a byte[]
+ // See also LowerToCamelBeanMapper
+ if (value instanceof Blob) {
+ final Blob blob = (Blob) value;
+ row.put(k, blob.getBytes(0, (int) blob.length()));
+ }
+ }
+
out.write(row);
}
} finally {
diff --git a/util/src/test/java/org/killbill/billing/util/export/dao/TestDatabaseExportDao.java b/util/src/test/java/org/killbill/billing/util/export/dao/TestDatabaseExportDao.java
index e9b497f..01fe087 100644
--- a/util/src/test/java/org/killbill/billing/util/export/dao/TestDatabaseExportDao.java
+++ b/util/src/test/java/org/killbill/billing/util/export/dao/TestDatabaseExportDao.java
@@ -1,7 +1,9 @@
/*
- * Copyright 2010-2012 Ning, Inc.
+ * Copyright 2010-2013 Ning, Inc.
+ * Copyright 2014-2017 Groupon, Inc
+ * Copyright 2014-2017 The Billing Project, LLC
*
- * Ning licenses this file to you under the Apache License, version 2.0
+ * 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:
*
@@ -30,6 +32,8 @@ import org.killbill.billing.util.UtilTestSuiteWithEmbeddedDB;
import org.killbill.billing.util.api.DatabaseExportOutputStream;
import org.killbill.billing.util.validation.dao.DatabaseSchemaDao;
+import com.ning.compress.lzf.LZFEncoder;
+
public class TestDatabaseExportDao extends UtilTestSuiteWithEmbeddedDB {
@Test(groups = "slow")
@@ -48,6 +52,7 @@ public class TestDatabaseExportDao extends UtilTestSuiteWithEmbeddedDB {
final Date updatedDate = new Date(382910622000L);
final String updatedBy = UUID.randomUUID().toString().substring(0, 4);
+ final byte[] properties = LZFEncoder.encode(new byte[] { 'c', 'a', 'f', 'e' });
final String tableNameA = "test_database_export_dao_a";
final String tableNameB = "test_database_export_dao_b";
dbi.withHandle(new HandleCallback<Void>() {
@@ -56,6 +61,7 @@ public class TestDatabaseExportDao extends UtilTestSuiteWithEmbeddedDB {
handle.execute("drop table if exists " + tableNameA);
handle.execute("create table " + tableNameA + "(record_id serial unique," +
"a_column char default 'a'," +
+ "blob_column mediumblob," +
"account_record_id bigint /*! unsigned */ not null," +
"tenant_record_id bigint /*! unsigned */ not null default 0," +
"primary key(record_id));");
@@ -65,8 +71,8 @@ public class TestDatabaseExportDao extends UtilTestSuiteWithEmbeddedDB {
"account_record_id bigint /*! unsigned */ not null," +
"tenant_record_id bigint /*! unsigned */ not null default 0," +
"primary key(record_id));");
- handle.execute("insert into " + tableNameA + " (account_record_id, tenant_record_id) values (?, ?)",
- internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
+ handle.execute("insert into " + tableNameA + " (blob_column, account_record_id, tenant_record_id) values (?, ?, ?)",
+ properties, internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
handle.execute("insert into " + tableNameB + " (account_record_id, tenant_record_id) values (?, ?)",
internalCallContext.getAccountRecordId(), internalCallContext.getTenantRecordId());
@@ -83,8 +89,8 @@ public class TestDatabaseExportDao extends UtilTestSuiteWithEmbeddedDB {
Assert.assertEquals(newDump, "-- accounts record_id|id|external_key|email|name|first_name_length|currency|billing_cycle_day_local|payment_method_id|time_zone|locale|address1|address2|company_name|city|state_or_province|country|postal_code|phone|migrated|is_notified_for_invoices|created_date|created_by|updated_date|updated_by|tenant_record_id\n" +
String.format("%s|%s||%s|%s|%s||||||||||||||false|%s|%s|%s|%s|%s|%s", internalCallContext.getAccountRecordId(), accountId, accountEmail, accountName, firstNameLength,
isNotifiedForInvoices, "1970-05-24T18:33:02.000+0000", createdBy, "1982-02-18T20:03:42.000+0000", updatedBy, internalCallContext.getTenantRecordId()) + "\n" +
- "-- " + tableNameA + " record_id|a_column|account_record_id|tenant_record_id\n" +
- "1|a|" + internalCallContext.getAccountRecordId() + "|" + internalCallContext.getTenantRecordId() + "\n" +
+ "-- " + tableNameA + " record_id|a_column|blob_column|account_record_id|tenant_record_id\n" +
+ "1|a|WlYAAARjYWZl|" + internalCallContext.getAccountRecordId() + "|" + internalCallContext.getTenantRecordId() + "\n" +
"-- " + tableNameB + " record_id|b_column|account_record_id|tenant_record_id\n" +
"1|b|" + internalCallContext.getAccountRecordId() + "|" + internalCallContext.getTenantRecordId() + "\n");