001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: DiscGeneratorImpl.java,v 1.1 2006-09-11 12:44:38 sinisa Exp $
022: */
023:
024: package transactionsDiscRack.business.disc;
025:
026: import transactionsDiscRack.data.disc.*;
027: import transactionsDiscRack.spec.*;
028: import transactionsDiscRack.business.TransactionsDiscRackBusinessException;
029: import transactionsDiscRack.data.person.PersonDO;
030:
031: import com.lutris.appserver.server.sql.DBTransaction;
032: import com.lutris.appserver.server.sql.ObjectId;
033:
034: /**
035: * Used to find the instances of disc.
036: */
037: public class DiscGeneratorImpl implements DiscGenerator {
038:
039: /**
040: * The findDiscsForPerson method performs a database query to return an
041: * array of <CODE>Disc</CODE> objects representing all the rows in the
042: * <CODE>disc</CODE> table that have and owner matching <CODE>Person
043: * owner</CODE>.
044: *
045: * @param owner
046: * The owner of the discs
047: * @return array of discs.
048: * @exception DiscRackBusinessException
049: * If there is a problem retrieving disc information.
050: */
051: public Disc[] findDiscsForPerson(String ownerHandle,
052: DBTransaction transaction)
053: throws TransactionsDiscRackBusinessException {
054: DiscImpl[] theDiscArray = null;
055: try {
056: DiscQuery query = new DiscQuery(transaction);
057: // set query
058: query.setQueryOwner(PersonDO.createExisting(ownerHandle,
059: transaction));
060: // Order discs alphabetically by artist
061: query.addOrderByArtist();
062: DiscDO[] DOarray = query.getDOArray();
063: theDiscArray = new DiscImpl[DOarray.length];
064: for (int i = 0; i < DOarray.length; i++)
065: theDiscArray[i] = new DiscImpl(DOarray[i]);
066: } catch (Exception ex) {
067: throw new TransactionsDiscRackBusinessException(
068: "Exception in findDiscsForPerson()", ex);
069: }
070:
071: return theDiscArray;
072: }
073:
074: /**
075: * The findDiscByID method performs a database query to return a <CODE>Disc</CODE>
076: * object representing the row in the <CODE>disc</CODE> table that matches
077: * the object id.
078: *
079: * @param id ,
080: * the object id of the disc table.
081: * @return the disc. null if there isn't a person associated the id
082: * @exception DiscRackBusinessException
083: * if there is a problem retrieving person information.
084: */
085: public Disc findDiscByID(String id, DBTransaction transaction)
086: throws TransactionsDiscRackBusinessException {
087: DiscImpl theDisc = null;
088: try {
089: DiscQuery query = new DiscQuery(transaction);
090: // set query
091: query.setQueryOId(new ObjectId(id));
092: // Throw an exception if more than one user by this name is found
093: query.requireUniqueInstance();
094: DiscDO theDiscDO = query.getNextDO();
095: theDisc = new DiscImpl(theDiscDO);
096: return theDisc;
097: } catch (Exception ex) {
098: throw new TransactionsDiscRackBusinessException(
099: "Exception in findDiscsByID()", ex);
100: }
101: }
102:
103: }
|