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 2006-09-11 12:30:36 sinisa Exp $
22: */
23:
24: package barracudaDiscRack.business.person;
25:
26: import barracudaDiscRack.data.person.*;
27: import barracudaDiscRack.business.DiscRackBusinessException;
28: import com.lutris.dods.builder.generator.query.*;
29: import com.lutris.appserver.server.Enhydra;
30: import com.lutris.logging.*;
31:
32: /**
33: * Used to find the instance of Person.
34: */
35: public class PersonFactory {
36:
37: /**
38: * The findPerson method performs a database query to
39: * return a <CODE>Person</CODE> object
40: * representing the row in the <CODE>person</CODE> table
41: * that matches login name with the username.
42: *
43: * @param username, the login name of the person.
44: * @return
45: * the person. null if there isn't a person associated
46: * the username
47: * @exception DiscRackBusinessException
48: * if there is a problem retrieving person information.
49: */
50: public static Person findPerson(String username)
51: throws DiscRackBusinessException {
52: try {
53: PersonQuery query = new PersonQuery();
54: // set query.
55: query.setQueryLogin(username);
56: // Throw an exception if more than one user by this name is found
57: query.requireUniqueInstance();
58:
59: PersonDO[] foundPerson = query.getDOArray();
60: if (foundPerson.length != 0) {
61: return new Person(foundPerson[0]);
62: } else {
63: return null;
64: }
65: } catch (NonUniqueQueryException ex) {
66: Enhydra.getLogChannel().write(
67: Logger.DEBUG,
68: "Non-unique user found in database: "
69: + ex.getMessage());
70: throw new DiscRackBusinessException(
71: "More than one user found with username: "
72: + username);
73: } catch (DataObjectException ex) {
74: throw new DiscRackBusinessException(
75: "Database error retrieving user: ", ex);
76: } catch (QueryException ex) {
77: throw new DiscRackBusinessException(
78: "Query exception retrieving user: ", ex);
79: }
80:
81: }
82: }
|