KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > discRack > biz > 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/02/05 10:24:50 slobodan Exp $
22  */

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

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

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

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