org.hibernate.loader.criteria.CriteriaLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate Show documentation
Show all versions of hibernate Show documentation
Relational Persistence for Java
//$Id: CriteriaLoader.java 11321 2007-03-20 11:51:09Z [email protected] $
package org.hibernate.loader.criteria;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.QueryException;
import org.hibernate.ScrollMode;
import org.hibernate.ScrollableResults;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.QueryParameters;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.impl.CriteriaImpl;
import org.hibernate.loader.OuterJoinLoader;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.persister.entity.Lockable;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.Type;
/**
* A Loader for Criteria queries. Note that criteria queries are
* more like multi-object load()s than like HQL queries.
*
* @author Gavin King
*/
public class CriteriaLoader extends OuterJoinLoader {
//TODO: this class depends directly upon CriteriaImpl,
// in the impl package ... add a CriteriaImplementor
// interface
//NOTE: unlike all other Loaders, this one is NOT
// multithreaded, or cacheable!!
private final CriteriaQueryTranslator translator;
private final Set querySpaces;
private final Type[] resultTypes;
//the user visible aliases, which are unknown to the superclass,
//these are not the actual "physical" SQL aliases
private final String[] userAliases;
public CriteriaLoader(
final OuterJoinLoadable persister,
final SessionFactoryImplementor factory,
final CriteriaImpl criteria,
final String rootEntityName,
final Map enabledFilters)
throws HibernateException {
super(factory, enabledFilters);
translator = new CriteriaQueryTranslator(
factory,
criteria,
rootEntityName,
CriteriaQueryTranslator.ROOT_SQL_ALIAS
);
querySpaces = translator.getQuerySpaces();
CriteriaJoinWalker walker = new CriteriaJoinWalker(
persister,
translator,
factory,
criteria,
rootEntityName,
enabledFilters
);
initFromWalker(walker);
userAliases = walker.getUserAliases();
resultTypes = walker.getResultTypes();
postInstantiate();
}
public ScrollableResults scroll(SessionImplementor session, ScrollMode scrollMode)
throws HibernateException {
QueryParameters qp = translator.getQueryParameters();
qp.setScrollMode(scrollMode);
return scroll(qp, resultTypes, null, session);
}
public List list(SessionImplementor session)
throws HibernateException {
return list( session, translator.getQueryParameters(), querySpaces, resultTypes );
}
protected Object getResultColumnOrRow(Object[] row, ResultTransformer transformer, ResultSet rs, SessionImplementor session)
throws SQLException, HibernateException {
final Object[] result;
final String[] aliases;
if ( translator.hasProjection() ) {
Type[] types = translator.getProjectedTypes();
result = new Object[types.length];
String[] columnAliases = translator.getProjectedColumnAliases();
for ( int i=0; i