Details
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/AdminResource.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/AdminResource.java
index 18099f0..c85f49f 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/AdminResource.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/AdminResource.java
@@ -1,6 +1,6 @@
/*
- * Copyright 2014-2017 Groupon, Inc
- * Copyright 2014-2017 The Billing Project, LLC
+ * Copyright 2014-2018 Groupon, Inc
+ * Copyright 2014-2018 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
@@ -17,6 +17,7 @@
package org.killbill.billing.jaxrs.resources;
+import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
@@ -300,8 +301,13 @@ public class AdminResource extends JaxRsResourceBase {
generator.close();
} finally {
// In case the client goes away (IOException), make sure to close the underlying DB connection
- while (iterator.hasNext()) {
- iterator.next();
+ if (tags instanceof Closeable) {
+ ((Closeable) tags).close();
+ } else {
+ // TODO 0.20.x (https://github.com/killbill/killbill/issues/558)
+ while (iterator.hasNext()) {
+ iterator.next();
+ }
}
}
}
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/JaxRsResourceBase.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/JaxRsResourceBase.java
index c00297a..2273a83 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/JaxRsResourceBase.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/JaxRsResourceBase.java
@@ -1,7 +1,7 @@
/*
* Copyright 2010-2013 Ning, Inc.
- * Copyright 2014-2015 Groupon, Inc
- * Copyright 2014-2015 The Billing Project, LLC
+ * Copyright 2014-2018 Groupon, Inc
+ * Copyright 2014-2018 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
@@ -18,6 +18,7 @@
package org.killbill.billing.jaxrs.resources;
+import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
@@ -335,8 +336,13 @@ public abstract class JaxRsResourceBase implements JaxrsResource {
generator.close();
} finally {
// In case the client goes away (IOException), make sure to close the underlying DB connection
- while (iterator.hasNext()) {
- iterator.next();
+ if (entities instanceof Closeable) {
+ ((Closeable) entities).close();
+ } else {
+ // TODO 0.20.x (https://github.com/killbill/killbill/issues/558)
+ while (iterator.hasNext()) {
+ iterator.next();
+ }
}
}
}
diff --git a/util/src/main/java/org/killbill/billing/util/entity/DefaultPagination.java b/util/src/main/java/org/killbill/billing/util/entity/DefaultPagination.java
index bdd5e16..7ea60aa 100644
--- a/util/src/main/java/org/killbill/billing/util/entity/DefaultPagination.java
+++ b/util/src/main/java/org/killbill/billing/util/entity/DefaultPagination.java
@@ -1,7 +1,9 @@
/*
* Copyright 2010-2013 Ning, Inc.
+ * Copyright 2014-2018 Groupon, Inc
+ * Copyright 2014-2018 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:
*
@@ -16,6 +18,8 @@
package org.killbill.billing.util.entity;
+import java.io.Closeable;
+import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -25,7 +29,7 @@ import javax.annotation.Nullable;
import com.google.common.collect.ImmutableList;
// Assumes the original offset starts at zero.
-public class DefaultPagination<T> implements Pagination<T> {
+public class DefaultPagination<T> implements Pagination<T>, Closeable {
private final Long currentOffset;
private final Long limit;
@@ -75,6 +79,18 @@ public class DefaultPagination<T> implements Pagination<T> {
}
@Override
+ public void close() throws IOException {
+ if (delegateIterator instanceof Closeable) {
+ // Always the case with the current implementation (delegateIterator is a org.skife.jdbi.v2.ResultIterator)
+ ((Closeable) delegateIterator).close();
+ } else {
+ while (delegateIterator.hasNext()) {
+ delegateIterator.next();
+ }
+ }
+ }
+
+ @Override
public Iterator<T> iterator() {
return delegateIterator;
}