Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test with Hibernate

  • Loading branch information...
commit 20916fa3e6355e1083910bab8118718a1b9c0981 1 parent 51eab3b
@poetix poetix authored
View
30 pom.xml
@@ -47,6 +47,36 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.5.1-Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <version>3.5.6-Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>3.12.1.GA</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.6.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.2</version>
View
37 src/test/java/com/youdevise/hsd/HSQLDBIntegrationTest.java
@@ -8,6 +8,11 @@
import java.sql.Statement;
import java.util.Date;
+import org.hibernate.ScrollMode;
+import org.hibernate.ScrollableResults;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -113,6 +118,36 @@ public boolean handle(EnumIndexedCursor<Fields> cursor) {
Date after = new Date();
System.out.println(String.format("Traversed 1000000 records in %s milliseconds using anonymous inner class", after.getTime() - before.getTime()));
}
+
+
+ @Test public void
+ hibernate_is_slow() {
+ AnnotationConfiguration cfg = new AnnotationConfiguration();
+ cfg.addPackage("com.youdevise.hsd")
+ .addAnnotatedClass(MyPersistable.class)
+ .setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect")
+ .setProperty("hibernate.jdbc.use_scrollable_resultset", "true");
+ SessionFactory factory = cfg.buildSessionFactory();
+ Session session = factory.openSession(connection);
+
+ ScrollableResults results = session.createQuery("SELECT p FROM MyPersistable p")
+ .setReadOnly(true)
+ .setCacheable(false)
+ .scroll(ScrollMode.FORWARD_ONLY);
+
+ Date before = new Date();
+ while (results.next()) {
+ MyPersistable persistable = (MyPersistable) results.get()[0];
+ if (persistable.getName().equals("Zalgo")) {
+ throw new RuntimeException("He comes!");
+ }
+ }
+ Date after = new Date();
+ System.out.println(String.format("Traversed 1000000 records in %s milliseconds using Hibernate", after.getTime() - before.getTime()));
+
+ results.close();
+ session.close();
+ }
private CursorHandlingTraverser<Fields> getMethodDispatchingCursorHandler(MethodBasedHandler handler) throws NoSuchMethodException {
Method method = MethodBasedHandler.class.getMethod("handle", Integer.TYPE, String.class);
@@ -123,7 +158,7 @@ public boolean handle(EnumIndexedCursor<Fields> cursor) {
}
private <E extends Enum<E>> boolean executeTestQuery(EnumIndexedCursorTraverser<E> traverser, Class<E> enumClass) throws SQLException, NoSuchMethodException {
- Statement statement = connection.createStatement();
+ Statement statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
try {
ResultSet resultSet = statement.executeQuery("SELECT id, name FROM test");
try {
View
21 src/test/java/com/youdevise/hsd/MyPersistable.java
@@ -0,0 +1,21 @@
+package com.youdevise.hsd;
+
+import java.io.Serializable;
+
+@javax.persistence.Entity
+@javax.persistence.Table(name="test")
+public class MyPersistable implements Serializable {
+ private static final long serialVersionUID = -7033663517388449709L;
+
+ @javax.persistence.Id
+ @javax.persistence.Column(name="ID")
+ private int id;
+ @javax.persistence.Column(name="NAME")
+ private String name;
+
+ public int getId() { return id; }
+
+ public String getName() { return name; }
+ public void setName(String newName) { name = newName; }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.