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

📄 holderinstantiator.java

📁 hibernate-3.1.3-all-src.zip 面向对象的访问数据库工具
💻 JAVA
字号:
//$Id: HolderInstantiator.java 6485 2005-04-22 18:05:58Z oneovthafew $
package org.hibernate.hql;

import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.hibernate.QueryException;

/**
 * @author Gavin King
 */
public final class HolderInstantiator {
	
	//TODO: have an interface and three different subclasses!
	
	private final Constructor constructor;
	private final boolean returnMaps;
	private final boolean returnLists; 
	private final String[] queryReturnAliases;
	
	public HolderInstantiator( 
			Constructor constructor, 
			boolean returnMaps, 
			boolean returnLists, 
			String[] queryReturnAliases
	) {
		this.constructor = constructor;
		this.returnLists = returnLists;
		this.returnMaps = returnMaps;
		this.queryReturnAliases = queryReturnAliases;
	}
	
	public boolean isRequired() {
		return constructor!=null || returnLists || returnMaps;
	}
	
	public Object instantiate(Object[] row) {
		if ( constructor != null ) {
				try {
					return constructor.newInstance( row );
				}
				catch ( Exception e ) {
					throw new QueryException( 
						"could not instantiate: " + 
						constructor.getDeclaringClass().getName(), 
						e );
				}
		}
		else if ( returnMaps ) {
				Map map = new HashMap();
				for ( int j = 0; j < row.length; j++ ) {
					map.put( queryReturnAliases[j], row[j] );
				}
				return map;
		}
		else if ( returnLists ) {
				return Arrays.asList(row);
		}
		else {
			return row;
		}
	}
	
}

⌨️ 快捷键说明

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