KickJava   Java API By Example, From Geeks To Geeks.

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


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: DiscGeneratorImpl.java,v 1.1 2004/08/16 09:39:19 slobodan Exp $
22  */

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

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

52     public Disc[] findDiscsForPerson(Person owner)
53         throws DiscRackBusinessException {
54         DiscImpl[] theDiscArray = null;
55         
56         try {
57             DiscQuery query = new DiscQuery();
58             //set query
59
query.setQueryOwner(PersonDO.createExisting(owner.getHandle()));
60             // Order discs alphabetically by artist
61
query.addOrderByArtist();
62             DiscDO[] DOarray = query.getDOArray();
63             theDiscArray = new DiscImpl[ DOarray.length ];
64             for ( int i = 0; i < DOarray.length; i++ )
65             theDiscArray[i] = new DiscImpl(DOarray[i]);
66         }catch(Exception JavaDoc ex) {
67             throw new DiscRackBusinessException("Exception in findDiscsForPerson()", ex);
68         }
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 Disc findDiscByID(String JavaDoc id)
87         throws DiscRackBusinessException {
88         DiscImpl 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 DiscImpl(theDiscDO);
98             return theDisc;
99         }catch(Exception JavaDoc ex) {
100             throw new DiscRackBusinessException("Exception in findDiscsByID()", ex);
101         }
102     }
103     
104    
105     
106 }
107
108
Popular Tags