KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > barracudaDiscRack > 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.4 2004/12/03 14:12:34 slobodan Exp $
22  */

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

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

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

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