diff --git a/src/main/java/com/avaje/ebeaninternal/server/query/CQuery.java b/src/main/java/com/avaje/ebeaninternal/server/query/CQuery.java index 03db92941..4053925b9 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/query/CQuery.java +++ b/src/main/java/com/avaje/ebeaninternal/server/query/CQuery.java @@ -363,6 +363,7 @@ public class CQuery implements DbReadContext, CancelableQuery { if (forwardOnlyHint) { // Use forward only hints for large resultset processing (Issue 56, MySql specific) pstmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + pstmt.setFetchSize(Integer.MIN_VALUE); } else { pstmt = conn.prepareStatement(sql); } diff --git a/src/test/java/com/avaje/tests/model/carwheeltruck/TTruck.java b/src/test/java/com/avaje/tests/model/carwheeltruck/TTruck.java index d8f413fd7..babe2df8e 100644 --- a/src/test/java/com/avaje/tests/model/carwheeltruck/TTruck.java +++ b/src/test/java/com/avaje/tests/model/carwheeltruck/TTruck.java @@ -1,5 +1,6 @@ package com.avaje.tests.model.carwheeltruck; +import javax.persistence.Column; import javax.persistence.DiscriminatorColumn; import javax.persistence.DiscriminatorValue; import javax.persistence.Entity; @@ -12,6 +13,7 @@ import javax.persistence.InheritanceType; @DiscriminatorValue("truck") public class TTruck extends TCar { + @Column(name="truckLoad") Long load; public Long getLoad() { diff --git a/src/test/java/com/avaje/tests/query/other/TestFindIterateHeapDump.java b/src/test/java/com/avaje/tests/query/other/TestFindIterateHeapDump.java new file mode 100644 index 000000000..69947e578 --- /dev/null +++ b/src/test/java/com/avaje/tests/query/other/TestFindIterateHeapDump.java @@ -0,0 +1,125 @@ +package com.avaje.tests.query.other; + +import java.io.File; +import java.lang.management.ManagementFactory; + +import javax.management.MBeanServer; + +import org.junit.Ignore; +import org.junit.Test; + +import com.avaje.ebean.BaseTestCase; +import com.avaje.ebean.Ebean; +import com.avaje.ebean.EbeanServer; +import com.avaje.ebean.QueryIterator; +import com.avaje.ebean.Transaction; +import com.avaje.tests.model.basic.EBasic; +import com.sun.management.HotSpotDiagnosticMXBean; + +@SuppressWarnings("restriction") +public class TestFindIterateHeapDump extends BaseTestCase { + + // All that heap dumping code from : + // https://blogs.oracle.com/sundararajan/entry/programmatically_dumping_heap_from_java + private static final String HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic"; + + /** + * field to store the hotspot diagnostic MBean + */ + private static volatile HotSpotDiagnosticMXBean hotspotMBean; + + /** + * Ignore this test generally - run it manually against MySQL specifically for Issue #56. + */ + @Ignore + @Test + public void test() { + + EbeanServer server = Ebean.getServer(null); + + Transaction transaction = server.beginTransaction(); + try { + transaction.setBatchMode(true); + transaction.setBatchSize(20); + for (int i = 0; i < 10000; i++) { + EBasic dumbModel = new EBasic(); + dumbModel.setName("Hello"); + server.save(dumbModel); + } + transaction.commit(); + + } finally { + transaction.end(); + } + + QueryIterator iterate = server.find(EBasic.class).findIterate(); + iterate.hashCode(); + try { + + // Intentionally not iterating through the iterator to + + // try { + // while (iterate.hasNext()) { + // EBasic eBasic = iterate.next(); + // eBasic.getDescription(); + // } + // } finally { + // iterate.close(); + // } + + String fileName = "heap-dump6.snapshot"; + + File file = new File(fileName); + if (file.exists()) + file.delete(); + + dumpHeap(fileName, true); + + } finally { + iterate.close(); + } + + } + + static void dumpHeap(String fileName, boolean live) { + // initialize hotspot diagnostic MBean + initHotspotMBean(); + try { + hotspotMBean.dumpHeap(fileName, live); + } catch (RuntimeException re) { + throw re; + } catch (Exception exp) { + throw new RuntimeException(exp); + } + } + + /** + * initialize the hotspot diagnostic MBean field + */ + private static void initHotspotMBean() { + if (hotspotMBean == null) { + synchronized (TestFindIterateHeapDump.class) { + if (hotspotMBean == null) { + hotspotMBean = getHotspotMBean(); + } + } + } + } + + /** + * get the hotspot diagnostic MBean from the ManagementFactory. + */ + private static HotSpotDiagnosticMXBean getHotspotMBean() { + try { + MBeanServer server = ManagementFactory.getPlatformMBeanServer(); + HotSpotDiagnosticMXBean bean = ManagementFactory.newPlatformMXBeanProxy(server, HOTSPOT_BEAN_NAME, + HotSpotDiagnosticMXBean.class); + return bean; + } catch (RuntimeException re) { + throw re; + } catch (Exception exp) { + throw new RuntimeException(exp); + } + } + +}