Handling huge data with Biglistbox and Hibernate"

From Documentation
Line 11: Line 11:
 
In Jumper's [[Small Talks/2012/March/Handling a Trillion Data Using ZK|article]], the demo is using static data which size is one trillion. In most case, the data size is quite large beyond database server can handle. Therefore, I will use a BigTable in MySQL database with 100 columns and 22,000 data rows to create a sample project as following steps:
 
In Jumper's [[Small Talks/2012/March/Handling a Trillion Data Using ZK|article]], the demo is using static data which size is one trillion. In most case, the data size is quite large beyond database server can handle. Therefore, I will use a BigTable in MySQL database with 100 columns and 22,000 data rows to create a sample project as following steps:
 
<div style="padding-left: 10px">
 
<div style="padding-left: 10px">
==1. Prepare fake data in MySQL==
+
==Create a ZK project and integrate with Hibernate==
==2. Create a ZK project and integrate with Hibernate==
+
Please refer to the following documents:
==3. Modify ''MatrixModel'' from Jumper's demo==
+
*[[ZK_Installation_Guide/Quick_Start/Create_and_Run_Your_First_ZK_Application_with_Eclipse_and_ZK_Studio|Create and Run Your First ZK Application with Eclipse and ZK_Studio]]
==4. Results==
+
*[[ZK_Developer%27s_Reference/Integration/Hibernate|Integration with Hibernate]]
 +
==Prepare bean object and data access object==
 +
The BigTable bean:
 +
<source lang="java">
 +
public class BigTable implements Serializable {
 +
    private int _id;
 +
    private String _column1, _column2, _column3, _column4, _column5, _column6, _column7, _column8, _column9, _column10;
 +
    // omitted other members...
 +
 
 +
    // getters and setters
 +
}
 +
</source>
 +
The BigTable Data Access Object:
 +
<source lang="java">
 +
public class BigTableDAO {
 +
    private static final Log log = Log.lookup(BigTableDAO.class);
 +
   
 +
    public List<BigTable> findBetweenIds(int startId, int endId, boolean sortDir) {
 +
Session session = HibernateUtil.currentSession();
 +
List<BigTable> list = null;
 +
try {
 +
session.beginTransaction();
 +
String query = "SELECT b FROM BigTable b WHERE b.id BETWEEN :start AND :end ORDER BY b.id "
 +
+ (sortDir ? "asc" : "desc");
 +
Query q = session.createQuery(query);
 +
q.setInteger("start", startId);
 +
q.setInteger("end", endId);
 +
list = q.list();
 +
session.getTransaction().commit();
 +
} catch (HibernateException he) {
 +
log.error("get failed", he);
 +
}
 +
return list;
 +
}
 +
}
 +
</source>
 +
==Result==
 
</div>
 
</div>
  

Revision as of 07:51, 18 April 2012

DocumentationSmall Talks2012MayHandling huge data with Biglistbox and Hibernate
Handling huge data with Biglistbox and Hibernate

Author
Vincent Jian, Engineer, Potix Corporation
Date
May ?, 2012
Version
ZK 6.0.1, Hibernate 3.6.8

Introduction

In this article, Jumper Chen introduced a new component Biglistbox that can handle huge data and the performance has great improvement. In this article, I will demonstrate how to present huge data from database with Hibernate.

Huge data in Biglistbox

In Jumper's article, the demo is using static data which size is one trillion. In most case, the data size is quite large beyond database server can handle. Therefore, I will use a BigTable in MySQL database with 100 columns and 22,000 data rows to create a sample project as following steps:

Create a ZK project and integrate with Hibernate

Please refer to the following documents:

Prepare bean object and data access object

The BigTable bean:

public class BigTable implements Serializable {
    private int _id;
    private String _column1, _column2, _column3, _column4, _column5, _column6, _column7, _column8, _column9, _column10;
    // omitted other members...

    // getters and setters
}

The BigTable Data Access Object:

public class BigTableDAO {
    private static final Log log = Log.lookup(BigTableDAO.class);
    
    public List<BigTable> findBetweenIds(int startId, int endId, boolean sortDir) {
		Session session = HibernateUtil.currentSession();
		List<BigTable> list = null;
		try {
			session.beginTransaction();
			String query = "SELECT b FROM BigTable b WHERE b.id BETWEEN :start AND :end ORDER BY b.id "
					+ (sortDir ? "asc" : "desc");
			Query q = session.createQuery(query);
			q.setInteger("start", startId);
			q.setInteger("end", endId);
			list = q.list();
			session.getTransaction().commit();
		} catch (HibernateException he) {
			log.error("get failed", he);
		}
		return list;
	}
}

Result

Conclusion

Download

Reference


Comments



Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.