1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package olr.samples;
18
19 import java.util.List;
20
21 import olr.Olr;
22 import olr.om.RdfUser;
23 import olr.om.RdfUserPeer;
24
25 /***
26 * This demonstrate how we can use <a href="http://db.apache.org/torque/">Torque's</a>
27 * peer classes to execute custom SQL queries with the advantage
28 * of populating the corresponding Torque data objects in the same step.
29 * Using JDBC direct, one would have to loop over the JDBC ResultSet
30 * calling lots of setters and getters.
31 * @version $Id: SqlSample.java,v 1.4 2004/08/02 18:36:42 roku Exp $
32 */
33 public class SqlSample
34 {
35 public static void main(String[] args)
36 {
37 try
38 {
39 Olr.initTorque();
40
41 String sql = "SELECT * FROM rdf_user, rdf_group "
42 + "WHERE rdf_user.group_id=rdf_group.id "
43 + "AND rdf_group.name='Administrator'";
44
45 List users = RdfUserPeer.populateObjects(RdfUserPeer.executeQuery(sql));
46
47 System.out.println("Administrators:\n");
48
49 for(int i=0; i<users.size(); i++)
50 System.out.println(((RdfUser)users.get(i)).getFirstName());
51 }
52 catch(Exception e)
53 {
54 e.printStackTrace();
55 }
56 }
57 }