KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > prevayler > demo > UCListAllProducts


1 package org.apache.ojb.broker.prevayler.demo;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import org.apache.ojb.broker.query.Query;
19 import org.apache.ojb.broker.query.QueryByCriteria;
20 import org.apache.ojb.tutorial1.Product;
21
22 import java.util.Collection JavaDoc;
23
24 /**
25  * Insert the type's description here.
26  * Creation date: (04.03.2001 10:34:15)
27  * @author Thomas Mahler
28  */

29 public class UCListAllProducts extends AbstractUseCase
30 {
31     /**
32      * UCEnterNewProduct constructor comment.
33      */

34     public UCListAllProducts(org.apache.ojb.broker.PersistenceBroker b)
35     {
36         super(b);
37     }
38
39     /** perform this use case*/
40     public void apply()
41     {
42         System.out.println("The list of available products:");
43         // build a query that select all objects of Class Product, without any further criteria
44
// according to ODMG the Collection containing all instances of a persistent class is called "Extent"
45
Query query = new QueryByCriteria(Product.class, null);
46         try
47         {
48             // ask the broker to retrieve the Extent collection
49
Collection JavaDoc allProducts = broker.getCollectionByQuery(query);
50             // now iterate over the result to print each product
51
java.util.Iterator JavaDoc iter = allProducts.iterator();
52             while (iter.hasNext())
53             {
54                 System.out.println(iter.next());
55             }
56         }
57         catch (Throwable JavaDoc t)
58         {
59             t.printStackTrace();
60         }
61     }
62
63     /** get descriptive information on use case*/
64     public String JavaDoc getDescription()
65     {
66         return "List all product entries";
67     }
68 }
69
Popular Tags