db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Rubin" <dan...@nullsoft.com>
Subject Re: Peer class executeQuery method
Date Sun, 03 Aug 2003 10:18:45 GMT

Hey there. I am quite new to Torque myself - but it seems that you
are trying to avoid using the SQL generating methods of the Peer
classes. They work well, and if you intend to select the data into
an object anyway, surely it makes sense to get all of the columns (I
am assuming you are using executeQuery so that you don't get all the
columns back).

How is Torque meant to work out how to fill an object from the
columns you have selected which could be from several tables (even
though your example uses only one)? You expect to do an
executeQuery( "arbitrary SQL" ) and then get a Torque object out of
the returned List? So my suggestion is : use more complex Criteria
with doSelect.

I am interested in hearing from other users whether I am off the
mark...

 - Daniel



> Hi All,
>    I am a new torque user and  have just try making a query using
> peer class' executeQuery" method by passing sql string as its
> parameter. I do get the list of record objects back but when i
> try to iterate through these record objects and cast it to the
> bean object automatically generated by torque, the exception was
> thrown with message = null. I have try using simple criteria and
> it work fine. But for flexibility reason i would like to pass
> query string directly as well. My smaple code is  listed below.
>
>
> import java.util.*;
> import com.gistec.webentrytool.*;
> import org.apache.torque.Torque;
> import org.apache.torque.TorqueException;
> import org.apache.torque.TorqueRuntimeException;
> import org.apache.torque.util.Criteria;
>
> public class TestAddressTemplate {
>
>
>     /**
>      * @param args the command line arguments
>      */
>     public static void main(String[] args) {
>         try {
>       /*
>        * Initializing Torque
>        */
>              Torque.init("C:\\torque\\torque-3.0.2\\Torque.properties");
>              AddressOrg addressObj = new AddressOrg();
>              AddressOrg first = new AddressOrg();
>              first.setIdAddressOrg(1);
>              first.setRporgname("Bookey GmbH");
>              first.setDelpoint("Bookey Strasse 5");
>              first.setCity("Bad konig");
>              first.save();
>            //  first.setCity("Frankfurt");
>            //  AddressOrgPeer.doUpdate(first);
>
>
>            //  AddressOrgPeer.doDelete(first);
>            String sqlString = "select ID_ADDRESS_ORG, RPORGNAME,
> DELPOINT, CITY from ADDRESS_ORG";
>            List addressOrgList = null;
>            addressOrgList = AddressOrgPeer.executeQuery(sqlString);
>           // Criteria crit = new Criteria();
>           // Criteria newCrit =
> crit.addAscendingOrderByColumn(AddressOrgPeer.ID_ADDRESS_ORG);
>           // addressOrgList = AddressOrgPeer.doSelect(crit);
>            List subList = addressOrgList.subList(11, 16);
>            //Iterator i = addressOrgList.iterator();
>            Iterator i = subList.iterator();
>            System.out.println(addressOrgList.size());
>            while (i.hasNext()) {
>                AddressOrg addressOrgObj = (AddressOrg) i.next();
>                // Exception occurs on the line above when using peer
> class' executeQuery method
>                System.out.println("ID_ADDRESS_ORG: " +
> addressOrgObj.getIdAddressOrg() + "\n");
>
>                System.out.println("RPORGNAME: " +
> addressOrgObj.getRporgname() + "\n");
>                System.out.println("DELPOINT:  " +
> addressOrgObj.getDelpoint() + "\n");
>                System.out.println("CITY: " +
> addressOrgObj.getCity() + "\n");
>           }
>         }
>         catch (TorqueException e) {
>             System.out.println(e.getMessage());
>         }
>         catch (TorqueRuntimeException e) {
>             System.out.println(e.getMessage());
>         }
>         catch(Exception e) {
>             System.out.println(e.getMessage());
>         }
>
>     }
> }
>


 - Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message