/*
* Enhydra Java Application Server Project
*
* The contents of this file are subject to the Enhydra Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License on
* the Enhydra web site ( http://www.enhydra.org/ ).
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific terms governing rights and limitations
* under the License.
*
* The Initial Developer of the Enhydra Application Server is Lutris
* Technologies, Inc. The Enhydra Application Server and portions created
* by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
* All Rights Reserved.
*
* Contributor(s):
*
* $Id: DiscImpl.java,v 1.1 2006-09-11 12:39:40 sinisa Exp $
*/
package jtaDiscRack.business.disc;
import jtaDiscRack.spec.*;
import jtaDiscRack.data.person.PersonDO;
import jtaDiscRack.data.disc.*;
import jtaDiscRack.business.JtaDiscRackBusinessException;
import com.lutris.appserver.server.sql.DatabaseManagerException;
import com.lutris.dods.builder.generator.query.DataObjectException;
import org.enhydra.dods.exceptions.AssertionDataObjectException;
/**
* Represents a disc.
*/
public class DiscImpl implements Disc {
/**
* The attributes of the disc.
*/
protected String handle = null;
protected String title = null;
protected String artist = null;
protected String genre = null;
protected boolean isLiked = false;
protected String owner = null;
/**
* The public constructor.
*/
public DiscImpl() {}
/**
* The protected constructor
*
* @param theDisc
* The data object of the disc.
*/
protected DiscImpl(DiscDO theDisc)
throws JtaDiscRackBusinessException {
try {
handle = theDisc.get_Handle();
title = theDisc.getTitle();
artist = theDisc.getArtist();
genre = theDisc.getGenre();
isLiked = theDisc.getIsLiked();
owner = theDisc.getOwner().get_Handle();
} catch (DataObjectException ex) {
throw new JtaDiscRackBusinessException(
"Error creating Disc", ex);
} catch (DatabaseManagerException ex) {
throw new JtaDiscRackBusinessException(
"Error creating Disc", ex);
}
}
/**
* Gets the object id for the disc
*
* @return the object id.
* @exception DiscRackBusinessException
* if an error occurs retrieving data (usually due to an
* underlying data layer error).
*/
public String getHandle() {
return handle;
}
/**
* Gets the title for the disc
*
* @return the title.
* @exception DiscRackBusinessException
* if an error occurs retrieving data (usually due to an
* underlying data layer error).
*/
public String getTitle() {
return title;
}
/**
* Gets the artist for the disc
*
* @return the artist.
* @exception DiscRackBusinessException
* if an error occurs retrieving data (usually due to an
* underlying data layer error).
*/
public String getArtist() {
return artist;
}
/**
* Gets the genre for the disc
*
* @return the genre.
* @exception DiscRackBusinessException
* if an error occurs retrieving data (usually due to an
* underlying data layer error).
*/
public String getGenre() {
return genre;
}
/**
* Gets the preference for the disc
*
* @return true if like the disc, false if not
* @exception DiscRackBusinessException
* if an error occurs retrieving data (usually due to an
* underlying data layer error).
*/
public boolean isLiked() {
return isLiked;
}
/**
* Sets the title for the disc.
*
* @param title
* @exception DiscRackBusinessException
* if an error occurs setting the data (usually due to an
* underlying data layer error).
*/
public void setTitle(String title) {
this.title = title;
}
/**
* Sets the artist for the disc.
*
* @param artist
* @exception DiscRackBusinessException
* if an error occurs setting the data (usually due to an
* underlying data layer error).
*/
public void setArtist(String artist) {
this.artist = artist;
}
/**
* Sets the genre for the disc.
*
* @param genre
* @exception DiscRackBusinessException
* if an error occurs setting the data (usually due to an
* underlying data layer error).
*/
public void setGenre(String genre) {
this.genre = genre;
}
/**
* Sets the owner for the disc.
*
* @param owner
* @exception DiscRackBusinessException
* if an error occurs setting the data (usually due to an
* underlying data layer error).
*/
public void setOwner(String ownerHandle) {
this.owner = ownerHandle;
}
/**
* Sets the preference for the disc.
*
* @param isLiked
* @exception DiscRackBusinessException
* if an error occurs setting the data (usually due to an
* underlying data layer error).
*/
public void setLiked(boolean isLiked) {
this.isLiked = isLiked;
}
/**
* Commits all changes to the database.
*
* @exception DiscRackBusinessException
* if an error occurs retrieving data (usually due to an
* underlying data layer error).
*/
public void save() throws JtaDiscRackBusinessException,
AssertionDataObjectException {
try {
PersonDO personDO = PersonDO.createExisting(this.owner);
DiscDO myDO = DiscDO.createExisting(this.handle);
if (myDO == null) {
// disc creation
myDO = DiscDO.createVirgin();
}
myDO.setTitle(this.title);
myDO.setArtist(this.artist);
myDO.setGenre(this.genre);
myDO.setIsLiked(this.isLiked);
myDO.setOwner(personDO);
myDO.save();
} catch (AssertionDataObjectException ex) {
throw new AssertionDataObjectException(
"Read-only table: DML operations not allowed", ex);
} catch (Exception ex) {
throw new JtaDiscRackBusinessException(
"Error saving disc", ex);
}
}
/**
* Deletes the disc from the database.
*
* @exception DiscRackBusinessException
* if an error occurs deleting data (usually due to an
* underlying data layer error).
*/
public void delete() throws JtaDiscRackBusinessException,
AssertionDataObjectException {
try {
DiscDO myDO = DiscDO.createExisting(this.handle);
myDO.delete();
} catch (AssertionDataObjectException ex) {
throw new AssertionDataObjectException(
"Read-only table: DML operations not allowed", ex);
} catch (Exception ex) {
throw new JtaDiscRackBusinessException(
"Error deleting disc", ex);
}
}
}
|