1 23 24 25 26 package transactionsDiscRack.business.person; 27 28 import transactionsDiscRack.data.person.*; 29 import transactionsDiscRack.spec.*; 30 import transactionsDiscRack.business.TransactionsDiscRackBusinessException; 31 32 import com.lutris.dods.builder.generator.query.*; 33 import com.lutris.appserver.server.Enhydra; 34 import com.lutris.logging.*; 35 import com.lutris.appserver.server.sql.DBTransaction; 36 import org.enhydra.dods.*; 37 38 41 public class PersonGeneratorImpl implements PersonGenerator { 42 43 56 57 public Person findPerson(String username) 58 throws TransactionsDiscRackBusinessException { 59 DBTransaction trans = null; 60 try { 61 try{ 62 trans = DODS.getDatabaseManager().createTransaction(); 63 }catch(Exception ex){ 64 throw new TransactionsDiscRackBusinessException("Error creating transaction!", ex); 65 } 66 PersonQuery query = new PersonQuery(trans); 67 query.setQueryLogin(username); 69 query.requireUniqueInstance(); 71 72 PersonDO[] foundPerson = query.getDOArray(); 73 if(foundPerson.length != 0) { 74 return new PersonImpl(foundPerson[0]); 75 } else { 76 trans.release(); 77 return null; 78 } 79 } catch(NonUniqueQueryException ex) { 80 Enhydra.getLogChannel().write(Logger.DEBUG, 81 "Non-unique user found in database: " + 82 ex.getMessage()); 83 if (trans != null) 84 trans.release(); 85 throw new TransactionsDiscRackBusinessException("More than one user found with username: " + 86 username); 87 } catch(DataObjectException ex) { 88 if (trans != null) 89 trans.release(); 90 throw new TransactionsDiscRackBusinessException("Database error retrieving user: ", ex); 91 } catch(QueryException ex) { 92 if (trans != null) 93 trans.release(); 94 throw new TransactionsDiscRackBusinessException("Query exception retrieving user: ", ex); 95 } 96 97 } 98 99 100 101 102 } 103 | Popular Tags |