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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations