Java Code Examples for org.hibernate.hql.QueryTranslator#getSQLString()
The following examples show how to use
org.hibernate.hql.QueryTranslator#getSQLString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryTranslatorTestCase.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
protected void runClassicTranslator(String hql) throws Exception { SessionFactoryImplementor factory = getSessionFactoryImplementor(); Map replacements = new HashMap(); QueryTranslator oldQueryTranslator = null; try { QueryTranslatorFactory classic = new ClassicQueryTranslatorFactory(); oldQueryTranslator = classic.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, factory ); oldQueryTranslator.compile( replacements, false ); } catch ( Exception e ) { e.printStackTrace(); throw e; } String oldsql = oldQueryTranslator.getSQLString(); System.out.println( "HQL : " + hql ); System.out.println( "OLD SQL: " + oldsql ); }
Example 2
Source File: QueryUtil.java From ctsms with GNU Lesser General Public License v2.1 | 5 votes |
private static String hqlToSql(String hqlQueryText, SessionFactory sessionFactory) { if (hqlQueryText != null && hqlQueryText.trim().length() > 0 && sessionFactory != null) { final QueryTranslatorFactory translatorFactory = new ASTQueryTranslatorFactory(); final SessionFactoryImplementor factory = (SessionFactoryImplementor) sessionFactory; final QueryTranslator translator = translatorFactory .createQueryTranslator(hqlQueryText, hqlQueryText, Collections.EMPTY_MAP, factory); translator.compile(Collections.EMPTY_MAP, false); return translator.getSQLString(); } return null; }
Example 3
Source File: HibernateUtil.java From document-management-system with GNU General Public License v2.0 | 5 votes |
/** * HQL to SQL translator */ public static String toSql(String hql) { if (hql != null && hql.trim().length() > 0) { final QueryTranslatorFactory qtf = new ASTQueryTranslatorFactory(); final SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactory; final QueryTranslator translator = qtf.createQueryTranslator(hql, hql, Collections.EMPTY_MAP, sfi); translator.compile(Collections.EMPTY_MAP, false); return translator.getSQLString(); } return null; }
Example 4
Source File: QueryTranslatorTestCase.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private void checkSql(QueryTranslator oldQueryTranslator, QueryTranslator newQueryTranslator, String hql, boolean scalar, String sql) { String oldsql = oldQueryTranslator.getSQLString(); String newsql = newQueryTranslator.getSQLString(); System.out.println( "HQL : " + ASTPrinter.escapeMultibyteChars(hql) ); System.out.println( "OLD SQL: " + ASTPrinter.escapeMultibyteChars(oldsql) ); System.out.println( "NEW SQL: " + ASTPrinter.escapeMultibyteChars(newsql) ); if ( sql == null ) { // Check the generated SQL. ASTPrinter.escapeMultibyteChars( assertSQLEquals( "SQL is not the same as the old SQL (scalar=" + scalar + ")", oldsql, newsql ); } else { assertSQLEquals( "SQL is not the same as the expected SQL (scalar=" + scalar + ")", sql, newsql ); } }
Example 5
Source File: EJBQLTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
private void assertEjbqlEqualsHql(String ejbql, String hql) { QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sfi() ); queryTranslator.compile( Collections.EMPTY_MAP, true ); String hqlSql = queryTranslator.getSQLString(); queryTranslator = ast.createQueryTranslator( ejbql, ejbql, Collections.EMPTY_MAP, sfi() ); queryTranslator.compile( Collections.EMPTY_MAP, true ); String ejbqlSql = queryTranslator.getSQLString(); assertEquals( hqlSql, ejbqlSql ); }
Example 6
Source File: EJBQLTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
private String toSql(String hql) { QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); QueryTranslator queryTranslator = ast.createQueryTranslator( hql, hql, Collections.EMPTY_MAP, sfi() ); queryTranslator.compile( Collections.EMPTY_MAP, true ); return queryTranslator.getSQLString(); }