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:39:40 sinisa Exp $
022: */
023:
024: package jtaDiscRack.business.disc;
025:
026: import jtaDiscRack.data.disc.*;
027: import jtaDiscRack.spec.*;
028: import jtaDiscRack.business.JtaDiscRackBusinessException;
029: import jtaDiscRack.data.person.PersonDO;
030:
031: import com.lutris.appserver.server.sql.ObjectId;
032:
033: /**
034: * Used to find the instances of disc.
035: */
036: public class DiscGeneratorImpl implements DiscGenerator {
037:
038: /**
039: * The findDiscsForPerson method performs a database query to return an
040: * array of <CODE>Disc</CODE> objects representing all the rows in the
041: * <CODE>disc</CODE> table that have and owner matching <CODE>Person
042: * owner</CODE>.
043: *
044: * @param owner
045: * The owner of the discs
046: * @return array of discs.
047: * @exception DiscRackBusinessException
048: * If there is a problem retrieving disc information.
049: */
050: public Disc[] findDiscsForPerson(String ownerHandle)
051: throws JtaDiscRackBusinessException {
052: DiscImpl[] theDiscArray = null;
053: try {
054: DiscQuery query = new DiscQuery();
055: // set query
056: query.setQueryOwner(PersonDO.createExisting(ownerHandle));
057: // Order discs alphabetically by artist
058: query.addOrderByArtist();
059: DiscDO[] DOarray = query.getDOArray();
060: theDiscArray = new DiscImpl[DOarray.length];
061: for (int i = 0; i < DOarray.length; i++)
062: theDiscArray[i] = new DiscImpl(DOarray[i]);
063: } catch (Exception ex) {
064: throw new JtaDiscRackBusinessException(
065: "Exception in findDiscsForPerson()", ex);
066: }
067:
068: return theDiscArray;
069: }
070:
071: /**
072: * The findDiscByID method performs a database query to return a <CODE>Disc</CODE>
073: * object representing the row in the <CODE>disc</CODE> table that matches
074: * the object id.
075: *
076: * @param id ,
077: * the object id of the disc table.
078: * @return the disc. null if there isn't a person associated the id
079: * @exception DiscRackBusinessException
080: * if there is a problem retrieving person information.
081: */
082: public Disc findDiscByID(String id)
083: throws JtaDiscRackBusinessException {
084: DiscImpl theDisc = null;
085: try {
086: DiscQuery query = new DiscQuery();
087: // set query
088: query.setQueryOId(new ObjectId(id));
089: // Throw an exception if more than one user by this name is found
090: query.requireUniqueInstance();
091: DiscDO theDiscDO = query.getNextDO();
092: theDisc = new DiscImpl(theDiscDO);
093: return theDisc;
094: } catch (Exception ex) {
095: throw new JtaDiscRackBusinessException(
096: "Exception in findDiscsByID()", ex);
097: }
098: }
099:
100: }
|