{
try
{
final String sqlGeneratorClass = configuration.getConfigProperty
("org.pentaho.reporting.engine.classic.extensions.datasources.pmd.SqlGeneratorClass");
final SqlGenerator sqlGenerator = (SqlGenerator) ObjectUtilities.loadAndInstantiate
(sqlGeneratorClass, SimplePmdDataFactory.class, SqlGenerator.class);
if (sqlGenerator == null)
{
logger.error("Default SqlGenerator class " + sqlGeneratorClass + " not found."); //$NON-NLS-1$
throw new ReportDataFactoryException("Failed to generate SQL. No valid SqlGenerator class found.");//$NON-NLS-1$
}
// convert DataRow into Map<String,Object>
final Map<String, Object> parameterMap = new HashMap<String, Object>();
final String[] columnNames = parameters.getColumnNames();
for (int i = 0; i < columnNames.length; i++)
{
final String key = columnNames[i];
final Object value = parameters.get(key);
parameterMap.put(key, value);
}
final IMetadataDomainRepository domainRepository = getDomainRepository();
Locale locale;
if (resourceBundleFactory != null)
{
locale = resourceBundleFactory.getLocale();
}
else
{
locale = LocaleHelper.getLocale();
}
if (locale == null)
{
locale = Locale.getDefault();
}
return sqlGenerator.generateSql(queryObject, locale.toString(), domainRepository, databaseMeta, parameterMap, true);
}
catch (ReportDataFactoryException e)
{
throw e;
}