}
public LabelValueBean[] getReportParameterOptions(IParameterDefnBase parameter) throws Exception {
EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
LabelValueBean options[] = null;
ScalarParameterHandle handle = (ScalarParameterHandle) parameter.getHandle();
Vector<LabelValueBean> v = new Vector<LabelValueBean>();
if (handle.getDataSetName() != null) {
String columnName = extractSqlColumn(handle.getValueExpr());
List<?> list = runnable.getDesignInstance().getDataSet(handle.getDataSetName()).getCachedResultSetColumns();
Iterator<?> columnIterator = list.iterator();
int position = 0;
while (columnIterator.hasNext()) {
IResultSetColumn column = (IResultSetColumn) columnIterator.next();
String name = column.getName();
if (name.equals(columnName)) {
break;
}
position++;
}
IDataSet dataSet = runnable.getDesignInstance().getDataSet(handle.getDataSetName());
String queryText = dataSet.getQueryText();
String sortByColumn = extractSqlColumn(handle.getSortByColumn());
queryText += " order by " + sortByColumn;
queryText += " " + handle.getSortDirection();
Query query = em.createNativeQuery(queryText);
Iterator<?> iterator = query.getResultList().iterator();
while (iterator.hasNext()) {
Object object[] = (Object[]) iterator.next();
LabelValueBean bean = new LabelValueBean((String) object[position], (String) object[position]);
v.add(bean);
}
}
else {
Iterator<?> iterator = handle.getListProperty("selectionList").iterator();
while (iterator.hasNext()) {
SelectionChoice selectionChoice = (SelectionChoice) iterator.next();
LabelValueBean bean = new LabelValueBean(selectionChoice.getLabel(), selectionChoice.getValue());
v.add(bean);
}