You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by bhiyavudh <bh...@hotmail.com> on 2003/08/03 05:03:00 UTC

Peer class executeQuery method

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());
        }

    }
}

Re: How to creat a Transaction to add or delete muti-Table Data?

Posted by Michel Beijlevelt / Lucka <mb...@lucka.nl>.
Howdy,

I you search the archives, there's some information about transcations, 
but very little actually. I did find something like this:

            Connection conn = Transaction.begin( 
FactextraoptionsPeer.DATABASE_NAME );
                extraoptions.save();
                contract.save();
            Transaction.commit( conn );

But I haven't seen any proof in the logs that the transactional 
statements are actually generated, so I doubt if it really works.

gr. Michel

PS Transaction is from: import org.apache.torque.util.Transaction;

sailorhero wrote:

>I use torque at MSSAL server.I want to create a Transcation to add or delete multi-Table Data.
>How to create this Transaction?
>Please give me a example .Thanks very much!
>
>
>
>  
>



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


How to creat a Transaction to add or delete muti-Table Data?

Posted by sailorhero <sa...@hotmail.com>.
I use torque at MSSAL server.I want to create a Transcation to add or delete multi-Table Data.
How to create this Transaction?
Please give me a example .Thanks very much!

Re: Peer class executeQuery method

Posted by Daniel Rubin <da...@nullsoft.com>.
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