Search in sources :

Example 1 with IHQLQueryPlan

use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class QueryHelper method generateSQL.

public static String generateSQL(ExecutionContext executionContext, final ISessionFactory sessionFactory, final String query, final IService service) {
    // $NON-NLS-1$
    if (StringHelper.isEmpty(query))
        return "";
    String result = (String) executionContext.execute(new ExecutionContext.Command() {

        public Object execute() {
            try {
                StringBuffer str = new StringBuffer(256);
                IHQLQueryPlan plan = service.newHQLQueryPlan(query, false, sessionFactory);
                IQueryTranslator[] translators = plan.getTranslators();
                for (int i = 0; i < translators.length; i++) {
                    IQueryTranslator translator = translators[i];
                    if (translator.isManipulationStatement()) {
                        // $NON-NLS-1$
                        str.append(ConsoleMessages.DynamicSQLPreviewView_manipulation_of + i + ":");
                        Iterator<?> iterator = translator.getQuerySpaces().iterator();
                        while (iterator.hasNext()) {
                            Object qspace = iterator.next();
                            str.append(qspace);
                            // $NON-NLS-1$
                            if (iterator.hasNext()) {
                                str.append(", ");
                            }
                        }
                    } else {
                        IType[] returnTypes = translator.getReturnTypes();
                        // $NON-NLS-1$
                        str.append(i + ": ");
                        for (int j = 0; j < returnTypes.length; j++) {
                            IType returnType = returnTypes[j];
                            str.append(returnType.getName());
                            // $NON-NLS-1$
                            if (j < returnTypes.length - 1) {
                                str.append(", ");
                            }
                        }
                    }
                    // $NON-NLS-1$
                    str.append("\n-----------------\n");
                    Iterator<?> sqls = translator.collectSqlStrings().iterator();
                    while (sqls.hasNext()) {
                        String sql = (String) sqls.next();
                        str.append(QLFormatHelper.formatForScreen(sql));
                        // $NON-NLS-1$
                        str.append("\n\n");
                    }
                }
                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(ConsoleMessages.DynamicSQLPreviewView_caused_by);
                    }
                }
                return msgs.toString();
            }
        }
    });
    return result;
}
Also used : IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) IQueryTranslator(org.jboss.tools.hibernate.runtime.spi.IQueryTranslator) IType(org.jboss.tools.hibernate.runtime.spi.IType)

Example 2 with IHQLQueryPlan

use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newHQLQueryPlan.

@Override
public IHQLQueryPlan newHQLQueryPlan(String query, boolean shallow, ISessionFactory sessionFactory) {
    SessionFactoryImpl factory = (SessionFactoryImpl) ((IFacade) sessionFactory).getTarget();
    Map<String, Filter> enabledFilters = Collections.emptyMap();
    HQLQueryPlan queryPlan = new HQLQueryPlan(query, shallow, enabledFilters, factory);
    return facadeFactory.createHQLQueryPlan(queryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl)

Example 3 with IHQLQueryPlan

use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newHQLQueryPlan.

@Override
public IHQLQueryPlan newHQLQueryPlan(String query, boolean shallow, ISessionFactory sessionFactory) {
    SessionFactoryImpl factory = (SessionFactoryImpl) ((IFacade) sessionFactory).getTarget();
    Map<String, Filter> enabledFilters = Collections.emptyMap();
    HQLQueryPlan queryPlan = new HQLQueryPlan(query, shallow, enabledFilters, factory);
    return facadeFactory.createHQLQueryPlan(queryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl)

Example 4 with IHQLQueryPlan

use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newHQLQueryPlan.

@Override
public IHQLQueryPlan newHQLQueryPlan(String query, boolean shallow, ISessionFactory sessionFactory) {
    assert sessionFactory instanceof IFacade;
    SessionFactoryImpl factory = (SessionFactoryImpl) ((IFacade) sessionFactory).getTarget();
    Map<String, Filter> enabledFilters = Collections.emptyMap();
    HQLQueryPlan queryPlan = new HQLQueryPlan(query, shallow, enabledFilters, factory);
    return facadeFactory.createHQLQueryPlan(queryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) IFacade(org.jboss.tools.hibernate.runtime.common.IFacade) SessionFactoryImpl(org.hibernate.impl.SessionFactoryImpl)

Example 5 with IHQLQueryPlan

use of org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan in project jbosstools-hibernate by jbosstools.

the class ServiceImpl method newHQLQueryPlan.

@Override
public IHQLQueryPlan newHQLQueryPlan(String query, boolean shallow, ISessionFactory sessionFactory) {
    SessionFactoryImpl factory = (SessionFactoryImpl) ((IFacade) sessionFactory).getTarget();
    Map<String, Filter> enabledFilters = Collections.emptyMap();
    HQLQueryPlan queryPlan = new HQLQueryPlan(query, shallow, enabledFilters, factory);
    return facadeFactory.createHQLQueryPlan(queryPlan);
}
Also used : HQLQueryPlan(org.hibernate.engine.query.spi.HQLQueryPlan) IHQLQueryPlan(org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan) Filter(org.hibernate.Filter) ITableFilter(org.jboss.tools.hibernate.runtime.spi.ITableFilter) TableFilter(org.hibernate.cfg.reveng.TableFilter) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl)

Aggregations

IHQLQueryPlan (org.jboss.tools.hibernate.runtime.spi.IHQLQueryPlan)21 HQLQueryPlan (org.hibernate.engine.query.spi.HQLQueryPlan)16 Filter (org.hibernate.Filter)13 TableFilter (org.hibernate.cfg.reveng.TableFilter)13 ITableFilter (org.jboss.tools.hibernate.runtime.spi.ITableFilter)13 Test (org.junit.Test)12 SessionFactoryImpl (org.hibernate.internal.SessionFactoryImpl)10 Column (org.hibernate.mapping.Column)8 PrimaryKey (org.hibernate.mapping.PrimaryKey)8 RootClass (org.hibernate.mapping.RootClass)8 SimpleValue (org.hibernate.mapping.SimpleValue)8 Table (org.hibernate.mapping.Table)8 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)8 IColumn (org.jboss.tools.hibernate.runtime.spi.IColumn)8 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)8 IPrimaryKey (org.jboss.tools.hibernate.runtime.spi.IPrimaryKey)8 ITable (org.jboss.tools.hibernate.runtime.spi.ITable)8 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 File (java.io.File)4 FileWriter (java.io.FileWriter)4