View Javadoc

1   /*
2    *  Copyright 2004 University of Hannover
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  
17  package olr.samples;
18  
19  import java.util.List;
20  
21  import olr.Olr;
22  import olr.om.RdfGroup;
23  import olr.om.RdfGroupPeer;
24  import olr.om.RdfUser;
25  
26  import org.apache.torque.util.Criteria;
27  
28  /***
29   * Example showing how to retrieve collections of objects
30   * referenced by a foreign key using the Torque object model.
31   * @version $Id: ForeignKeySample.java,v 1.3 2004/08/02 18:36:43 roku Exp $
32   */
33  public class ForeignKeySample
34  {
35      public static void main(String[] args)
36      {
37          try 
38          {
39              Olr.initTorque();
40              Criteria criteria = new Criteria();
41              criteria.add(RdfGroupPeer.NAME, "Administrator");
42              List groups = RdfGroupPeer.doSelect(criteria);
43              
44              assert(groups.size() == 1);
45              
46              RdfGroup group = (RdfGroup)groups.get(0);
47              List members = group.getRdfUsers();
48              
49              System.out.println("Members of group " 
50                      + group.getName() + ":\n");
51              
52              for(int i=0; i<members.size(); i++)
53                  System.out.println(((RdfUser)members.get(i)).getLogin());
54          }
55          catch(Exception e)
56          {
57              e.printStackTrace();
58          }
59      }
60  }