use of org.hibernate.loader.criteria.CriteriaLoader in project hibernate-orm by hibernate.
the class SessionImpl method scroll.
@Override
public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode) {
// TODO: Is this guaranteed to always be CriteriaImpl?
CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
checkOpenOrWaitingForAutoClose();
checkTransactionSynchStatus();
String entityName = criteriaImpl.getEntityOrClassName();
CriteriaLoader loader = new CriteriaLoader(getOuterJoinLoadable(entityName), getFactory(), criteriaImpl, entityName, getLoadQueryInfluencers());
autoFlushIfRequired(loader.getQuerySpaces());
dontFlushFromFind++;
try {
return loader.scroll(this, scrollMode);
} finally {
delayedAfterCompletion();
dontFlushFromFind--;
}
}
use of org.hibernate.loader.criteria.CriteriaLoader in project hibernate-orm by hibernate.
the class StatelessSessionImpl method list.
@Override
@SuppressWarnings({ "unchecked" })
public List list(Criteria criteria) throws HibernateException {
// TODO: Is this guaranteed to always be CriteriaImpl?
CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
checkOpen();
String[] implementors = getFactory().getMetamodel().getImplementors(criteriaImpl.getEntityOrClassName());
int size = implementors.length;
CriteriaLoader[] loaders = new CriteriaLoader[size];
for (int i = 0; i < size; i++) {
loaders[i] = new CriteriaLoader(getOuterJoinLoadable(implementors[i]), getFactory(), criteriaImpl, implementors[i], getLoadQueryInfluencers());
}
List results = Collections.EMPTY_LIST;
boolean success = false;
try {
for (int i = 0; i < size; i++) {
final List currentResults = loaders[i].list(this);
currentResults.addAll(results);
results = currentResults;
}
success = true;
} finally {
afterOperation(success);
}
temporaryPersistenceContext.clear();
return results;
}
use of org.hibernate.loader.criteria.CriteriaLoader in project hibernate-orm by hibernate.
the class StatelessSessionImpl method scroll.
@Override
public ScrollableResultsImplementor scroll(Criteria criteria, ScrollMode scrollMode) {
// TODO: Is this guaranteed to always be CriteriaImpl?
CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
checkOpen();
String entityName = criteriaImpl.getEntityOrClassName();
CriteriaLoader loader = new CriteriaLoader(getOuterJoinLoadable(entityName), getFactory(), criteriaImpl, entityName, getLoadQueryInfluencers());
return loader.scroll(this, scrollMode);
}
use of org.hibernate.loader.criteria.CriteriaLoader in project hibernate-orm by hibernate.
the class SessionImpl method list.
@Override
public List list(Criteria criteria) throws HibernateException {
// TODO: Is this guaranteed to always be CriteriaImpl?
CriteriaImpl criteriaImpl = (CriteriaImpl) criteria;
if (criteriaImpl.getMaxResults() != null && criteriaImpl.getMaxResults() == 0) {
return Collections.EMPTY_LIST;
}
final NaturalIdLoadAccess naturalIdLoadAccess = this.tryNaturalIdLoadAccess(criteriaImpl);
if (naturalIdLoadAccess != null) {
// EARLY EXIT!
return Arrays.asList(naturalIdLoadAccess.load());
}
checkOpenOrWaitingForAutoClose();
// checkTransactionSynchStatus();
String[] implementors = getFactory().getMetamodel().getImplementors(criteriaImpl.getEntityOrClassName());
int size = implementors.length;
CriteriaLoader[] loaders = new CriteriaLoader[size];
Set spaces = new HashSet();
for (int i = 0; i < size; i++) {
loaders[i] = new CriteriaLoader(getOuterJoinLoadable(implementors[i]), getFactory(), criteriaImpl, implementors[i], getLoadQueryInfluencers());
spaces.addAll(loaders[i].getQuerySpaces());
}
autoFlushIfRequired(spaces);
List results = Collections.EMPTY_LIST;
dontFlushFromFind++;
boolean success = false;
try {
for (int i = 0; i < size; i++) {
final List currentResults = loaders[i].list(this);
currentResults.addAll(results);
results = currentResults;
}
success = true;
} finally {
dontFlushFromFind--;
afterOperation(success);
delayedAfterCompletion();
}
return results;
}
use of org.hibernate.loader.criteria.CriteriaLoader in project midpoint by Evolveum.
the class HibernateToSqlTranslator method toSql.
/**
* Do not use in production code! Only for testing purposes only. Used for example during query engine upgrade.
* Method provides translation from hibernate {@link Criteria} to plain SQL string query.
*
* @param criteria
* @return SQL string, null if criteria parameter was null.
*/
public static String toSql(Criteria criteria) {
if (criteria == null) {
return null;
}
try {
CriteriaImpl c;
if (criteria instanceof CriteriaImpl) {
c = (CriteriaImpl) criteria;
} else {
CriteriaImpl.Subcriteria subcriteria = (CriteriaImpl.Subcriteria) criteria;
c = (CriteriaImpl) subcriteria.getParent();
}
SessionImpl s = (SessionImpl) c.getSession();
SessionFactoryImplementor factory = s.getSessionFactory();
String[] implementors = factory.getImplementors(c.getEntityOrClassName());
CriteriaLoader loader = new CriteriaLoader((OuterJoinLoadable) factory.getEntityPersister(implementors[0]), factory, c, implementors[0], s.getLoadQueryInfluencers());
Field f = OuterJoinLoader.class.getDeclaredField("sql");
f.setAccessible(true);
return (String) f.get(loader);
} catch (Exception ex) {
throw new SystemException(ex.getMessage(), ex);
}
}
Aggregations