db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jrovi...@notes.banesto.es
Subject Re: How to create a join ?
Date Thu, 11 Dec 2003 13:57:19 GMT

Use this:

// BUILD QUERY
Criteria criteria = new Criteria();
criteria.setDbName( "MyDB" ); // Optional

T1Peer.addSelectColumns( criteria );
T2Peer.addSelectColumns( criteria );
T3Peer.addSelectColumns( criteria );

criteria.addJoin( T1.ID_T1, T2.ID_T1 );
criteria.addJoin( T2.ID_T3, T3.ID_T3 );

// DO SELECT
List result = new LinkedList();

List records = BasePeer.doSelect( criteria, connection ); //
BasePeer.doSelect( criteria );
for( int i = 0; i < records.size(); i++ ) {
      Record row = (Record)records.get( i );

      // T1
      int index = 1;
      Object object1 = T1Peer.row2Object( row, index, T1Peer.getOMClass()
);

      // T2
      index += T1Peer.numColumns;
      Object object2 = T2Peer.row2Object( row, index, T2Peer.getOMClass()
);

      // T3
      index += T2Peer.numColumns;
      Object object3 = T3Peer.row2Object( row, index, T3Peer.getOMClass()
);

      result.add( new Object[] { object1, object2, object3 } );
}

// SHOW
fof( Iterator it = result.iterator(); it.hasNext(); ) {
      Object[] row = (Object[])it.next();
      T1 t1 = (T1)row[ 0 ];
      T2 t2 = (T2)row[ 1 ];
      T3 t3 = (T3)row[ 2 ];

      System.out.println( t1 );
      System.out.println( t2 );
      System.out.println( t3 );
}


-------> Do the same thing for T1.id_t3 = T3.id_t3

Easy, isnt it????

Ive got a framework to do this very easy ;)

Jose Luis Rovira Martin.




                                                                                         
                     
                      Cristian Zoicas                                                    
                     
                      <zoicas@medialab         Para:    torque-user@db.apache.org     
                        
                      .sissa.it>               cc:                                    
                        
                                               Asunto:  How to create a join ?           
                     
                      11/12/2003 13:48                                                   
                     
                      Por favor,                                                         
                     
                      responda a                                                         
                     
                      "Apache Torque                                                     
                     
                      Users List"                                                        
                     
                                                                                         
                     
                                                                                         
                     






Hello all

I've tried to figure out how to use the Criteria class in
order to obtain a statement like

SELECT
       *
FROM
       T1, T2, T3
WHERE
       ( T1.id_t1= T2.id_t1 AND T2.id_t3 = T3.id_t3 )
       OR
       ( T1.id_t3 = T3.id_t3 )

but I was not able to do it.
Does anybody has any solution ?

Thank you in advance
Cristian Zoicas



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







---------------------------------------------------------------------
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