db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Donald Rosengartner" <DROSENGART...@kc.rr.com>
Subject RE: LEFT JOINS, manually execute SQL
Date Wed, 02 Apr 2003 16:58:34 GMT
I just learned (thanks to Jurgen Hoffmann) to execute manually created sql in a peer class.
http://db.apache.org/torque/apidocs/org/apache/torque/util/BasePeer.html#executeQuery(java.lang.String)

EX:

public class CustomerPeer
    extends org.apache.torque.BaseCustomerPeer
{
 public static List getCustomersByPref(String state, String subject, int isPreferred ){
  List results = null;
  String sql = "SELECT CUSTOMER.CUSTOMER_ID, CUSTOMER.CUSTOMER_NAME, CUSTOMER.RATING, CUSTOMER.RATED_COUNT,
CUSTOMER.PAID_AD, CUSTOMER.USE_URL, CUSTOMER.ADDED FROM CUSTOMER, CATEGORY_MINOR, LOCATION
WHERE CATEGORY_MINOR.CATEGORY_NAME LIKE '%" + subject + "%' AND LOCATION.FK_STATE='" + state
+ "' AND CUSTOMER.PAID_AD = " + isPreferred + " AND CATEGORY_MINOR.FKCUSTOMER_ID=CUSTOMER.CUSTOMER_ID
AND CUSTOMER.CUSTOMER_ID=LOCATION.FKCUSTOMER_ID ORDER BY CUSTOMER.CUSTOMER_NAME ASC";
  try{
   results = BasePeer.executeQuery( sql, "fishing" );  //where fishing is dbName, case sensitive
   System.out.println("Results List = " + results.toString());
   return populateObjects(results);
  }
  catch(Exception e){
   System.out.println("Error in getCustomersByPref");
   e.printStackTrace();
  }
    return null;
 }
}

warning: all columns of Customer object had to be present for populateObjects method to work.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message