Problem

How can I read data from a table or a view with few instructions.


Solution

There are methods getData and getDataValues (both server side and client side) that allow you to read the data using fewer instructions.
The getData method returns WebDataSet object, which contains rows from the table/view request. An example of usage is as follows:

//Server side
dataweb.util.treeset.WebDataSet wset = dbSession.getData("<package><tableORview>", <optional_condition>, <optional_order>);
for (int i=0;i<=wset.getRowcount()-1;i++){
   Object obj1=wset.getValue(i,"<column>");
   ...
}

//Client side
dataweb.util.treeset.WebDataSet wset = client.getData(session, "<package><tableORview>", <optional_condition>, <optional_order>);
for (int i=0;i<=wset.getRowcount()-1;i++){
   Object obj1=wset.getValue(i,"<column>");
   ...
}

The method GetDataValues returns an array of objects related to a single record. To select the records you should use unique indexes of the table:

//Server side
Object[] objs = dbSession.getDataValues("<package><table>", "<index>", <indexvalues>, <columns>);

//Client side
Object[] objs = client.getDataValues(session, "<package><table>", "<index>", <indexvalues>, <columns>);

the parameters are:
<package><table> Table name (full name with package)
<index> Name of the index on the table
<indexvalues> Array of objects which contains the values of search parameters for the index
<columns> Array of string which contains the names of the columns to return

The method returns an array object containing the values for the columns declared in <columns>

Published in Sun, 19 December 2010 00:12