use of org.hibernate.internal.CriteriaImpl 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