Example usage for org.hibernate.engine.query.spi HQLQueryPlan HQLQueryPlan

List of usage examples for org.hibernate.engine.query.spi HQLQueryPlan HQLQueryPlan

Introduction

In this page you can find the example usage for org.hibernate.engine.query.spi HQLQueryPlan HQLQueryPlan.

Prototype

public HQLQueryPlan(String hql, boolean shallow, Map<String, Filter> enabledFilters,
        SessionFactoryImplementor factory) 

Source Link

Document

Constructs a HQLQueryPlan

Usage

From source file:com.blazebit.persistence.integration.hibernate.base.HibernateExtendedQuerySupport.java

License:Apache License

private HQLQueryPlan createQueryPlan(SessionFactoryImplementor sfi, Query query) {
    org.hibernate.Query hibernateQuery = query.unwrap(org.hibernate.Query.class);
    String queryString = hibernateQuery.getQueryString();
    return new HQLQueryPlan(queryString, false, Collections.EMPTY_MAP, sfi);
}

From source file:org.jboss.tools.hibernate4_0.QueryHelper.java

License:Open Source License

static String generateSQL(ExecutionContext executionContext, final SessionFactory sessionFactory,
        final String query) {

    if (StringHelper.isEmpty(query))
        return ""; //$NON-NLS-1$

    String result = (String) executionContext.execute(new ExecutionContext.Command() {
        public Object execute() {
            try {
                SessionFactoryImpl sfimpl = (SessionFactoryImpl) sessionFactory; // hack - to get to the actual queries..
                StringBuffer str = new StringBuffer(256);
                HQLQueryPlan plan = new HQLQueryPlan(query, false, Collections.EMPTY_MAP, sfimpl);

                QueryTranslator[] translators = plan.getTranslators();
                for (int i = 0; i < translators.length; i++) {
                    QueryTranslator translator = translators[i];
                    if (translator.isManipulationStatement()) {
                        str.append(HibernateConsoleMessages.DynamicSQLPreviewView_manipulation_of + i + ":"); //$NON-NLS-1$
                        Iterator<?> iterator = translator.getQuerySpaces().iterator();
                        while (iterator.hasNext()) {
                            Object qspace = iterator.next();
                            str.append(qspace);
                            if (iterator.hasNext()) {
                                str.append(", "); //$NON-NLS-1$
                            }/*  ww  w  . j a  va 2 s .  c  o  m*/
                        }

                    } else {
                        Type[] returnTypes = translator.getReturnTypes();
                        str.append(i + ": "); //$NON-NLS-1$
                        for (int j = 0; j < returnTypes.length; j++) {
                            Type returnType = returnTypes[j];
                            str.append(returnType.getName());
                            if (j < returnTypes.length - 1) {
                                str.append(", "); //$NON-NLS-1$
                            }
                        }
                    }
                    str.append("\n-----------------\n"); //$NON-NLS-1$
                    Iterator<?> sqls = translator.collectSqlStrings().iterator();
                    while (sqls.hasNext()) {
                        String sql = (String) sqls.next();
                        str.append(QLFormatHelper.formatForScreen(sql));
                        str.append("\n\n"); //$NON-NLS-1$
                    }
                }
                return str.toString();
            } catch (Throwable t) {
                StringBuffer msgs = new StringBuffer();

                Throwable cause = t;
                while (cause != null) {
                    msgs.append(t);
                    if (cause.getCause() == cause) {
                        cause = null;
                    } else {
                        cause = cause.getCause();
                        if (cause != null)
                            msgs.append(HibernateConsoleMessages.DynamicSQLPreviewView_caused_by);
                    }
                }
                return msgs.toString();
            }

        }
    });

    return result;
}