Actually I'm not looking for anything fancy. Just wanna make it work and don't know exactly how. Please evaluate my idea of how it works, and correct me if I'm wrong.
1. I have the implementation of the JRDataSource, which has the getFieldValue method. I got the second implementation from the hibernate site:
Code:
public class HibernateQueryResultDataSource implements JRDataSource {
private String[] fields;
private Iterator iterator;
private Object currentValue;
public HibernateQueryResultDataSource(List list, String[] fields) {
this.fields = fields;
this.iterator = list.iterator();
}
public Object getFieldValue(JRField field) throws JRException {
Object value = null;
int index = getFieldIndex(field.getName());
if (index > -1) {
Object[] values = (Object[])currentValue;
value = values[index];
}
return value;
}
public boolean next() throws JRException {
currentValue = iterator.hasNext() ? iterator.next() : null;
return (currentValue != null);
}
private int getFieldIndex(String field) {
int index = -1;
for (int i = 0; i < fields.length; i++) {
if (fields[i].equals(field)) {
index = i;
break;
}
}
return index;
}
}
Isn't this the correct one? What should be different?
2. On iReports, I configure my datasource using custom jrdatasource. Then this class will be my factory class. But what will be my method to retrieve the JRDataSource?
3. Then, with these things ready, how do I do my statements? I can't use SQL query, it won't accept HQL. I suppose I don't do nothing, just send the data ready to the report. But how do I refer to it there?
Really, I know there are basic things here, but my problem would probably be solved with an example or a more specific tutorial.