KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > barracudaDiscRack > business > person > PersonFactory


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: PersonFactory.java,v 1.4 2004/12/03 14:12:34 slobodan Exp $
22  */

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

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

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