use of org.jboss.tools.hibernate.runtime.spi.IQueryTranslator 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.IQueryTranslator in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateQueryTranslator.
@Test
public void testCreateQueryTranslator() {
QueryTranslator queryTranslator = (QueryTranslator) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { QueryTranslator.class }, new TestInvocationHandler());
IQueryTranslator facade = facadeFactory.createQueryTranslator(queryTranslator);
Assert.assertSame(queryTranslator, ((IFacade) facade).getTarget());
}
use of org.jboss.tools.hibernate.runtime.spi.IQueryTranslator in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateQueryTranslator.
@Test
public void testCreateQueryTranslator() {
QueryTranslator queryTranslator = (QueryTranslator) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { QueryTranslator.class }, new TestInvocationHandler());
IQueryTranslator facade = facadeFactory.createQueryTranslator(queryTranslator);
Assert.assertSame(queryTranslator, ((IFacade) facade).getTarget());
}
use of org.jboss.tools.hibernate.runtime.spi.IQueryTranslator in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateQueryTranslator.
@Test
public void testCreateQueryTranslator() {
QueryTranslator queryTranslator = (QueryTranslator) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { QueryTranslator.class }, new TestInvocationHandler());
IQueryTranslator facade = facadeFactory.createQueryTranslator(queryTranslator);
Assert.assertSame(queryTranslator, ((IFacade) facade).getTarget());
}
use of org.jboss.tools.hibernate.runtime.spi.IQueryTranslator in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateQueryTranslator.
@Test
public void testCreateQueryTranslator() {
QueryTranslator queryTranslator = (QueryTranslator) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { QueryTranslator.class }, new TestInvocationHandler());
IQueryTranslator facade = facadeFactory.createQueryTranslator(queryTranslator);
Assert.assertSame(queryTranslator, ((IFacade) facade).getTarget());
}
Aggregations