⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 limitinclausedemo.java

📁 hibernate_tutorial经典教程
💻 JAVA
字号:
/* * Created on Mar 18, 2005 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */package tutorial.dev.tree;import java.io.Serializable;import java.sql.Connection;import java.util.ArrayList;import java.util.List;import net.sf.hibernate.HibernateException;import net.sf.hibernate.Session;import net.sf.hibernate.SessionFactory;import net.sf.hibernate.Transaction;import net.sf.hibernate.cfg.Configuration;import net.sf.hibernate.expression.Expression;/** * @author pascal * * To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */public class LimitInClauseDemo {	public static void main(String[] args) {		try {			new LimitInClauseDemo();		} catch(HibernateException he) {			he.printStackTrace();		}	}	public LimitInClauseDemo() throws HibernateException {	Configuration config = new Configuration();	// add the classes you want to persist	// make sure the mapping files are on the classpath	config.addClass(Friend.class);		SessionFactory sf = config.buildSessionFactory();	Session sess = sf.openSession();	Transaction tx = null;		List ids = new ArrayList();		/*	try {		tx = sess.beginTransaction();		long start = System.currentTimeMillis(); 		for (int i = 0; i < 200000; i++) {						Serializable s = sess.save(new Friend("friend " + i));						//ids.add(s);			if (i % 1000 == 0) {				long now = System.currentTimeMillis();				System.out.println("at " + i);								System.out.println("Took: " + ((now - start) / 1000));				System.out.println("Free: " + Runtime.getRuntime().freeMemory() / 1024);				sess.flush();				start = now;			}		}		tx.commit();	} catch (HibernateException he) {	    if (tx!=null) tx.rollback();	    throw he;	} finally {	    sess.close();	}	*/	sess = sf.openSession();	tx = null;			try {		tx = sess.beginTransaction();		ids = sess.createQuery("select f.id from " + Friend.class.getName() +" as f")		.list();		List a = sess.createCriteria(Friend.class)			.add(Expression.in("id", ids))			.list();		System.out.println(a.size());		tx.commit();	} catch (HibernateException he) {	    if (tx!=null) tx.rollback();	    throw he;	} finally {	    sess.close();	}				}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -