All pastes #929355 Raw Edit

Untitled

public text v1 · immutable
#929355 ·published 2008-03-05 18:32 UTC
rendered paste body
      SQLTemplate sq = new SQLTemplate(Site.class, "select #result('siteid' 'int' 'id') from SA.Site");                                                                                                             
      sq.setFetchingDataRows(true);                                                                                                                                                                                 
      List siteRows = context.performQuery(sq.createQuery(new HashMap()));                                                                                                                                          
                                                                                                                                                                                                                    
      SQLTemplate reservations = new SQLTemplate(Reservation.class,                                                                                                                                                 
              "select * from SA.Reservation r " +                                                                                                                                                                   
                "where " +                                                                                                                                                                                          
                  "r.checkindate < $out and " +                                                                                                                                                                     
                  "r.checkoutdate > $in and " +                                                                                                                                                                     
                  "r.reservationType = 'S' and r.site = $id");                                                                                                                                                      
      reservation.setFetchinDataRows(true);                                                                                                                                                                         
      SQLTemplate stays = new SQLTemplate(Stay.class,                                                                                                                                                               
              "select SA.Stay.* from SA.Stay st, SA.Reservation r " +                                                                                                                                               
                "where " +                                                                                                                                                                                          
                  "r.checkindate < $out and " +                                                                                                                                                                     
                  "r.checkoutdate > $in and " +                                                                                                                                                                     
                  "st.site = $id");                                                                                                                                                                                 
      stays.setFetchinDataRows(true);                                                                                                                                                                               
                                                                                                                                                                                                                    
      Map params = new HashMap();                                                                                                                                                                                   
      FieldPosition fp = new FieldPosition(DateFormat.DATE_FIELD);                                                                                                                                                  
      SimpleDateFormat sdk = new SimpleDateFormat("yyyy-MM-dd");                                                                                                                                                    
      params.put("in", sdk.format(res.getCheckInDate(), new StringBuffer(""), fp).toString());                                                                                                                      
      params.put("out",sdk.format(res.getCheckOutDate(), new StringBuffer(""), fp).toString());                                                                                                                     
                                                                                                                                                                                                                    
      List queries = new ArrayList();                                                                                                                                                                               
      ListIterator<Map> itr = siteRows.listIterator();                                                                                                                                                              
      SQLTemplate tmpl;                                                                                                                                                                                             
      Query q1, q2;                                                                                                                                                                                                 
      while(itr.hasNext()){                                                                                                                                                                                         
        params.put("id", itr.next().get("id"));                                                                                                                                                                     
                                                                                                                                                                                                                    
        queries.add(reservations.createQuery(params));                                                                                                                                                              
        queries.add(stays.createQuery(params));                                                                                                                                                                     
      }                                                                                                                                                                                                             
      /* XXX Execute a batch query */