I have come up with some sort of solution that doesn't use reflection. I
would be greatful if anybody can improve it, as my solution rather relies
heavily on the premise that the attributes are capitalized in the same
manner as the properties of the VO i.e. attr<EmpId> / property
setEmpId().
My attempt is as follows ...
row = broker.getReportQueryIteratorByQuery(query);
while (row.hasNext()) {
for(int i=0; i<attrSubString.length; i++){
Object[] data = (Object[]) row.next();
Object arg = data[i];
String methodName = "set"+attrSubString[i];
EmpVO empVO = new EmpVO();
try {
MethodUtils.invokeMethod(pickValueVO,methodName,arg);
} catch (Exception e) {
throw e;
}
result.add(empVO);
}
}
On Sun, 06 Mar 2005 18:02:29 +1100, Mike Young wrote:
> Hi,
> I am trying to write a data access object that will return the results of
> a Report Query back as a Collection of Value List Objects based on the
> table row and the columns required.
>
> If I have a table employee with three columns (empid, empname,
> empsurname).
>
> And I have a Value Object EmpVo with appropriate getters and
> setters (i.e. getEmpId,setEmpId,getEmpName and so on).
>
> And for example I would like to carry out a select that returns only
> specific columns ...
> e.g.
> select distinct empsurname from employee or select empname,empsurname from
> employee
>
>
> My DAO is as follows ...
>
> * @param Criteria
> * @param (String)sortOrder - comma separated list of data columns to
> return
> * @param (String)sortOrder - comma separated list of columns
> to sort by
> * @return Iterator of ValueObject (-EmployeeValueVO)
>
> public Collection findManyByCritRpt(Criteria criteria,String
> attributes){
> PersistenceBroker broker = null;
> Iterator row = null;
> Object[] obj = null;
> Collection result = new Vector();
>
> broker = ServiceLocator.getInstance().findBroker();
> ReportQueryByCriteria query =
> QueryFactory.newReportQuery(PickValueVO.class, criteria,
> distinct); // Create Column List ( turns comma separated values
> into String array) String[] attrSubString =
> TwoSqUtils.ExtractSubString(attributes.trim(),',');
> query.setAttributes(attrSubString);
> row = broker.getReportQueryIteratorByQuery(query);
>
> while (row.hasNext()) {
> result.add(row.next());
> // *** TURN ROW into VALUE Object Here *** //
> // *** set(attrSubString[x]) ***//
> }
> return result;
> } // end findManyByCritRpt
>
> How would I go about using reflection and my "attrSubString" array (which
> lists the column names in the select) to call the appropriate setter in my
> Value Object and then create a (Vector) list of these Value Objects ?
>
> I am guessing I need to use the commons.beanutils class, however this is
> as far as I can get as I am quite new to java (3mths). Could some one help
> me fill in the gaps please?
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]