List of usage examples for org.hibernate.hql.internal.ast QueryTranslatorImpl compile
@Override public void compile(Map replacements, boolean shallow) throws QueryException, MappingException
From source file:com.heimaide.server.common.persistence.BaseDao.java
License:Open Source License
/** * hql??sql?,?/* w w w . j av a 2 s . co m*/ * * @param hql ??hql? * @return ?sql?, null, ?getResultMsg()?? */ public String transHqlToSql(String hql) { // ??session // session SessionFactoryImpl sfi = (SessionFactoryImpl) sessionFactory; // Query? QueryTranslatorImpl queryTranslator = new QueryTranslatorImpl(hql, hql, Collections.EMPTY_MAP, sfi); queryTranslator.compile(Collections.EMPTY_MAP, false); // sql String sql = queryTranslator.getSQLString(); // session return sql; }
From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java
protected long getCount(Session session, String hql, Object[] params) throws QueryException { QueryTranslatorImpl queryTranslator = new QueryTranslatorImpl(hql, hql, Collections.EMPTY_MAP, (SessionFactoryImplementor) getSessionFactory()); queryTranslator.compile(Collections.EMPTY_MAP, false); String sql = queryTranslator.getSQLString(); String s = "select count(*) from (" + sql + ") t"; Query query = session.createSQLQuery(s); return (long) ((Number) initHqlParams(query, params).uniqueResult()).longValue(); }
From source file:org.n52.sos.ds.hibernate.util.HibernateHelper.java
License:Open Source License
/** * Get the SQL query string from HQL Query. * * @param query//from www.j a v a 2 s .c om * HQL query to convert to SQL * @return SQL query string from HQL */ public static String getSqlString(Query query, Session session) { final QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); SessionFactory sessionFactory = session.getSessionFactory(); final QueryTranslatorImpl qt = (QueryTranslatorImpl) ast.createQueryTranslator("id", query.getQueryString(), Maps.newHashMap(), (SessionFactoryImplementor) sessionFactory, null); qt.compile(null, false); return qt.getSQLString(); }