KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > business > person > PersonGeneratorImpl


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

23
24
25
26 package discRack.business.person;
27
28 import discRack.data.person.*;
29 import discRack.spec.*;
30 import discRack.business.DiscRackBusinessException;
31
32 import com.lutris.dods.builder.generator.query.*;
33 import com.lutris.appserver.server.Enhydra;
34 import com.lutris.logging.*;
35
36
37 /**
38  * Used to find the instance of Person.
39  */

40 public class PersonGeneratorImpl implements PersonGenerator {
41     
42     /**
43      * The findPerson method performs a database query to
44      * return a <CODE>Person</CODE> object
45      * representing the row in the <CODE>person</CODE> table
46      * that matches login name with the username.
47      *
48      * @param username the login name of the person.
49      * @return
50      * the person. null if there isn't a person associated
51      * the username
52      * @exception DiscRackBusinessException
53      * if there is a problem retrieving person information.
54      */

55       
56      public Person findPerson(String JavaDoc username)
57         throws DiscRackBusinessException {
58         try {
59             PersonQuery query = new PersonQuery();
60             // set query.
61
query.setQueryLogin(username);
62             // Throw an exception if more than one user by this name is found
63
query.requireUniqueInstance();
64             
65             PersonDO[] foundPerson = query.getDOArray();
66             if(foundPerson.length != 0) {
67                 return new PersonImpl(foundPerson[0]);
68             } else {
69                 return null;
70             }
71         } catch(NonUniqueQueryException ex) {
72             Enhydra.getLogChannel().write(Logger.DEBUG,
73                                           "Non-unique user found in database: " +
74                                           ex.getMessage());
75             throw new DiscRackBusinessException("More than one user found with username: " +
76                                                 username);
77         } catch(DataObjectException ex) {
78             throw new DiscRackBusinessException("Database error retrieving user: ", ex);
79         } catch(QueryException ex) {
80             throw new DiscRackBusinessException("Query exception retrieving user: ", ex);
81         }
82
83     }
84    
85     
86     
87     
88 }
89
Popular Tags