KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > business > disc > DiscFactory


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: DiscFactory.java,v 1.3 2005/02/21 08:34:42 slobodan Exp $
22  */

23
24 package discRack.business.disc;
25
26 import discRack.business.DiscRackBusinessException;
27 import discRack.data.disc.*;
28 import com.lutris.dods.builder.generator.query.*;
29 import discRack.business.person.*;
30 import discRack.data.person.PersonDO;
31 import com.lutris.appserver.server.sql.ObjectId;
32
33 import java.util.*;
34
35 /**
36  * Used to find the instances of disc.
37  */

38 public class DiscFactory {
39
40
41    /**
42     * The findDiscsForPerson method performs a database query to
43     * return an array of <CODE>Disc</CODE> objects
44     * representing all the rows in the <CODE>disc</CODE> table
45     * that have and owner matching <CODE>Person owner</CODE>.
46     *
47     * @param owner. The owner of the discs
48     * @return
49     * array of discs.
50     * @exception DiscRackBusinessException
51     * If there is a problem retrieving disc information.
52     */

53    public static Disc[] findDiscsForPerson(Person owner)
54    throws DiscRackBusinessException {
55       Disc[] theDiscArray = null;
56
57       try {
58          DiscQuery query = new DiscQuery();
59          //set query
60
query.setQueryOwner(PersonDO.createExisting(owner.getHandle()));
61          // Order discs alphabetically by artist
62
query.addOrderByArtist();
63          DiscDO[] DOarray = query.getDOArray();
64          theDiscArray = new Disc[ DOarray.length ];
65          for ( int i = 0; i < DOarray.length; i++ )
66             theDiscArray[i] = new Disc(DOarray[i]);
67       }catch(Exception JavaDoc ex) {
68          throw new DiscRackBusinessException("Exception in findDiscsForPerson()", ex);
69       }
70       return theDiscArray;
71    }
72
73    /**
74     * The findDiscByID method performs a database query to
75     * return a <CODE>Disc</CODE> object
76     * representing the row in the <CODE>disc</CODE> table
77     * that matches the object id.
78     *
79     * @param id, the object id of the disc table.
80     * @return
81     * the disc. null if there isn't a person associated
82     * the id
83     * @exception DiscRackBusinessException
84     * if there is a problem retrieving person information.
85     */

86    public static Disc findDiscByID(String JavaDoc id)
87    throws DiscRackBusinessException {
88       Disc theDisc = null;
89
90       try {
91          DiscQuery query = new DiscQuery();
92          //set query
93
query.setQueryOId(new ObjectId(id));
94          // Throw an exception if more than one user by this name is found
95
query.requireUniqueInstance();
96          DiscDO theDiscDO = query.getNextDO();
97          theDisc = new Disc(theDiscDO);
98          return theDisc;
99       }catch(Exception JavaDoc ex) {
100          throw new DiscRackBusinessException("Exception in findDiscsForPerson()", ex);
101       }
102    }
103 }
104
105
Popular Tags