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

📄 entityloader.java

📁 用Java实现的23个常用设计模式源代码
💻 JAVA
字号:
//$Id: EntityLoader.java,v 1.19.2.6 2003/10/12 13:11:18 oneovthafew Exp $package net.sf.hibernate.loader;import java.io.Serializable;import java.sql.ResultSet;import java.sql.SQLException;import java.util.List;import net.sf.hibernate.HibernateException;import net.sf.hibernate.MappingException;import net.sf.hibernate.engine.SessionFactoryImplementor;import net.sf.hibernate.engine.SessionImplementor;import net.sf.hibernate.persister.Loadable;import net.sf.hibernate.type.Type;/** * Load an entity using outerjoin fetching to fetch associated entities.<br> * <br> * The <tt>ClassPersister</tt> must implement <tt>Loadable</tt>. For other entities, * create a customized subclass of <tt>Loader</tt>. *  * @see SimpleEntityLoader * @author Gavin King */public class EntityLoader extends AbstractEntityLoader implements UniqueEntityLoader {		private final Type uniqueKeyType;	private final boolean batchLoader;		public EntityLoader(Loadable persister, int batchSize, SessionFactoryImplementor factory) throws MappingException {		this( persister, persister.getIdentifierColumnNames(), persister.getIdentifierType(), batchSize, factory );	}		public EntityLoader(Loadable persister, String[] uniqueKey, Type uniqueKeyType, int batchSize, SessionFactoryImplementor factory) throws MappingException {		super(persister, factory);				this.uniqueKeyType = uniqueKeyType;				String whereString = whereString( getAlias(), uniqueKey, batchSize ).toString();		renderStatement(whereString, factory);				postInstantiate();				batchLoader = batchSize > 1;	}		public Object load(SessionImplementor session, Serializable id, Object optionalObject) throws HibernateException, SQLException {		return load(session, id, optionalObject, id);	}		public Object loadByUniqueKey(SessionImplementor session, Serializable id) throws HibernateException, SQLException {		return load(session, id, null, null);	}		private Object load(SessionImplementor session, Serializable id, Object optionalObject, Serializable optionalId) throws HibernateException, SQLException {		List list = loadEntity(session, id, uniqueKeyType, optionalObject, optionalId);		if ( list.size()==1 ) {			return list.get(0);		}		else if ( list.size()==0 ) {			return null;		}		else {			if ( getCollectionOwner()>-1 ) {				return list.get(0);			}			else {				throw new HibernateException( 					"More than one row with the given identifier was found: " + 					id + 					", for class: " + 					getPersister().getClassName() 				);			}		}	}	protected Object getResultColumnOrRow(		Object[] row,		ResultSet rs,		SessionImplementor session)		throws SQLException, HibernateException {		return row[row.length-1];	}	protected boolean isSingleRowLoader() {		return !batchLoader;	}}

⌨️ 快捷键说明

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