} else {
QbeEngineInstance engineInstance = this.getEngineInstance();
QueryCatalogue queryCatalogue = engineInstance.getQueryCatalogue();
query = queryCatalogue.getQuery(lookupQuery);
if(query == null) {
throw new SpagoBIEngineServiceException(getActionName(), "Impossible to retrive custom query [" + lookupQuery + "] from catalogue");
}
}
statement = getDataSource().createStatement( query );
statement.setParameters( getEnv() );
String jpaQueryStr = statement.getQueryString();
//String sqlQuery = statement.getSqlQueryString();
logger.debug("Executable query (HQL/JPQL): [" + jpaQueryStr+ "]");
//logger.debug("Executable query (SQL): [" + sqlQuery + "]");
try {
logger.debug("Executing query ...");
dataSet = QbeDatasetFactory.createDataSet(statement);
dataSet.setAbortOnOverflow(true);
Map userAttributes = new HashMap();
UserProfile profile = (UserProfile)this.getEnv().get(EngineConstants.ENV_USER_PROFILE);
Iterator it = profile.getUserAttributeNames().iterator();
while(it.hasNext()) {
String attributeName = (String)it.next();
Object attributeValue = profile.getUserAttribute(attributeName);
userAttributes.put(attributeName, attributeValue);
}
dataSet.addBinding("attributes", userAttributes);
dataSet.addBinding("parameters", this.getEnv());
dataSet.loadData();
dataStore = dataSet.getDataStore();
Assert.assertNotNull(dataStore, "The dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
} catch (Exception e) {
logger.debug("Query execution aborted because of an internal exceptian");
SpagoBIEngineServiceException exception;
String message;
message = "An error occurred in " + getActionName() + " service while executing query: [" + statement.getQueryString() + "]";
exception = new SpagoBIEngineServiceException(getActionName(), message, e);
exception.addHint("Check if the query is properly formed: [" + statement.getQueryString() + "]");
exception.addHint("Check connection configuration");
exception.addHint("Check the qbe jar file");
throw exception;
}
logger.debug("Query executed succesfully");
resultNumber = (Integer)dataStore.getMetaData().getProperty("resultNumber");
Assert.assertNotNull(resultNumber, "property [resultNumber] of the dataStore returned by loadData method of the class [" + dataSet.getClass().getName()+ "] cannot be null");
logger.debug("Total records: " + resultNumber);
dataSetWriter = new JSONDataWriter();
gridDataFeed = (JSONObject)dataSetWriter.write(dataStore);
try {
writeBackToClient( new JSONSuccess(gridDataFeed) );
} catch (IOException e) {
String message = "Impossible to write back the responce to the client";
throw new SpagoBIEngineServiceException(getActionName(), message, e);
}
} catch(Throwable t) {
errorHitsMonitor = MonitorFactory.start("QbeEngine.errorHits");
errorHitsMonitor.stop();