01: /*
02: * Enhydra Java Application Server Project
03: *
04: * The contents of this file are subject to the Enhydra Public License
05: * Version 1.1 (the "License"); you may not use this file except in
06: * compliance with the License. You may obtain a copy of the License on
07: * the Enhydra web site ( http://www.enhydra.org/ ).
08: *
09: * 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.1 2004/09/03 13:41:25 sinisa Exp $
22: */
23:
24: package discRack.business.person;
25:
26: import discRack.data.person.*;
27: import discRack.business.DiscRackBusinessException;
28: import com.lutris.dods.builder.generator.query.*;
29: import java.util.*;
30:
31: /**
32: * Used to find the instance of Person.
33: */
34: public class PersonFactory {
35:
36: /**
37: * The findPerson method performs a database query to
38: * return a <CODE>Person</CODE> object
39: * representing the row in the <CODE>person</CODE> table
40: * that matches login name with the username.
41: *
42: * @param username, the login name of the person.
43: * @return
44: * the person. null if there isn't a person associated
45: * the username
46: * @exception DiscRackBusinessException
47: * if there is a problem retrieving person information.
48: */
49: public static Person findPerson(String username)
50: throws DiscRackBusinessException {
51: try {
52: PersonQuery query = new PersonQuery();
53: // set query.
54: query.setQueryLogin(username);
55: // Throw an exception if more than one user by this name is found
56: query.requireUniqueInstance();
57:
58: PersonDO[] foundPerson = query.getDOArray();
59: if (foundPerson.length != 0) {
60: return new Person(foundPerson[0]);
61: } else {
62: return null;
63: }
64: } catch (NonUniqueQueryException ex) {
65: throw new DiscRackBusinessException(
66: "More than one user found with username: "
67: + username);
68: } catch (DataObjectException ex) {
69: throw new DiscRackBusinessException(
70: "Database error retrieving user: ", ex);
71: } catch (QueryException ex) {
72: throw new DiscRackBusinessException(
73: "Query exception retrieving user: ", ex);
74: }
75: }
76:
77: }
|