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/02/23 08:47:29 slobodan Exp $
22: */
23:
24: package jtaDiscRack.business.person;
25:
26: import jtaDiscRack.data.person.*;
27: import jtaDiscRack.business.JtaDiscRackBusinessException;
28: import jtaDiscRack.business.StaticXaTransactionSupport;
29:
30: import com.lutris.dods.builder.generator.query.*;
31:
32: /**
33: * Used to find the instance of Person.
34: */
35: public class PersonFactory extends StaticXaTransactionSupport {
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 JtaDiscRackBusinessException {
52:
53: initTransaction();
54:
55: boolean doCommit = true;
56:
57: try {
58: PersonQuery query = new PersonQuery();
59: // set query.
60: query.setQueryLogin(username);
61: // Throw an exception if more than one user by this name is found
62: query.requireUniqueInstance();
63:
64: PersonDO[] foundPerson = query.getDOArray();
65: if (foundPerson.length != 0) {
66: return new Person(foundPerson[0]);
67: } else {
68: return null;
69: }
70: } catch (NonUniqueQueryException ex) {
71: doCommit = false;
72: throw new JtaDiscRackBusinessException(
73: "More than one user found with username: "
74: + username);
75: } catch (DataObjectException ex) {
76: doCommit = false;
77: throw new JtaDiscRackBusinessException(
78: "Database error retrieving user: ", ex);
79: } catch (QueryException ex) {
80: doCommit = false;
81: throw new JtaDiscRackBusinessException(
82: "Query exception retrieving user: ", ex);
83: } finally {
84: if (doCommit) {
85: commitTransaction();
86: } else {
87: rollbackTransaction();
88: }
89: }
90: }
91:
92: }
|