【Java开源代码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了Java开源代码-AbstractScrollableResults.java的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
//$Id: AbstractScrollableResults.java 7469 2005-07-14 13:12:19Z steveebersole $
package org.hibernate.impl;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.PreparedStatement;
import java.
sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.ScrollableResults;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.exception.JDBCExceptionHelper;
import org.hibernate.hql.HolderInstantiator;
import org.hibernate.loader.Loader;
import org.hibernate.type.Type;
/**
* Implementation of the <tt>ScrollableResults</tt> interface
*
* @author Steve Ebersole
*/
public abstract class AbstractScrollableResults implements ScrollableResults {
private final ResultSet resultSet;
private final PreparedStatement ps;
private final SessionImplementor session;
private final Loader loader;
private final QueryParameters queryParameters;
private final Type[] types;
private HolderInstantiator holderInstantiator;
public AbstractScrollableResults(
ResultSet rs,
PreparedStatement ps,
SessionImplementor sess,
Loader loader,
QueryParameters queryParameters,
Type[] types,
HolderInstantiator holderInstantiator) throws MappingException {
this.resultSet=rs;
this.ps=ps;
this.session = sess;
this.loader = loader;
this.queryParameters = queryParameters;
this.types = types;
this.holderInstantiator = holderInstantiator!=null && holderInstantiator.isRequired()
? holderInstantiator
: null;
}
protected abstract Object[] getCurrentRow();
protected ResultSet getResultSet() {
return resultSet;
}
protected PreparedStatement getPs() {
return ps;
}
protected SessionImplementor getSession() {
return session;
}
protected Loader getLoader() {
return loader;
}
protected QueryParameters getQueryParameters() {
return queryParameters;
}
protected Type[] getTypes() {
return types;
}
protected HolderInstantiator getHolderInstantiator() {
return holderInstantiator;
}
public final void close() throws HibernateException {
try {
// not absolutely necessary, but does help with aggressive release
session.getBatcher().closeQueryStatement(ps, resultSet);
}
catch (SQLException sqle) {
throw JDBCExceptionHelper.convert(
session.getFactory().getSQLExceptionConverter(),
sqle,
"could not close results"
);
}
}
public final Object[] get() throws HibernateException {
return getCurrentRow();
}
public final Object get(int col) throws HibernateException {
return getCurrentRow()[col];
}
/**
* Check that the requested type is compatible with the result type, and
* return the column value. This version makes sure the the classes
* are identical.
*
* @param col the column
* @param returnType a "final" type
*/
protected final Object getFinal(int col, Type returnType) throws HibernateException {
if ( holderInstantiator!=null ) {
throw new HibernateException("query specifies a holder class");
}
if ( returnType.getReturnedClass()==types[col].getReturnedClass() ) {
return get(col);
}
else {
return throwInvalidColumnTypeException(col, types[col], returnType);
}
}
/**
* Check that the requested type is compatible with the result type, and
* return the column value. This version makes sure the the classes
* are "assignable".
*
* @param col the column
* @param returnType any type
*/
protected final Object getNonFinal(int col, Type returnType) throws HibernateException {
if ( holderInstantiator!=null ) {
throw new HibernateException("query specifies a holder class");
}
if ( returnType.getReturnedClass().isAssignableFrom( types[col].getReturnedClass() ) ) {
return get(col);
}
else {
return throwInvalidColumnTypeException(col, types[col], returnType);
}
}
public final BigDecimal getBigDecimal(int col) throws HibernateException {
return (BigDecimal) getFinal(col, Hibernate.B