01: package org.apache.ojb.broker.prevayler.demo;
02:
03: /* Copyright 2003-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * 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;
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: * UCEnterNewProduct constructor comment.
32: */
33: public UCListAllProducts(org.apache.ojb.broker.PersistenceBroker b) {
34: super (b);
35: }
36:
37: /** perform this use case*/
38: public void apply() {
39: System.out.println("The list of available products:");
40: // build a query that select all objects of Class Product, without any further criteria
41: // according to ODMG the Collection containing all instances of a persistent class is called "Extent"
42: Query query = new QueryByCriteria(Product.class, null);
43: try {
44: // ask the broker to retrieve the Extent collection
45: Collection allProducts = broker.getCollectionByQuery(query);
46: // now iterate over the result to print each product
47: java.util.Iterator iter = allProducts.iterator();
48: while (iter.hasNext()) {
49: System.out.println(iter.next());
50: }
51: } catch (Throwable t) {
52: t.printStackTrace();
53: }
54: }
55:
56: /** get descriptive information on use case*/
57: public String getDescription() {
58: return "List all product entries";
59: }
60: }
|