package thegroup.projectcddb.database;

import java.rmi.*;
import javax.ejb.*;

/**
 *  Class which encapsulates the abstract idea of a track from a CD according
 *  to the data available from the CDDB entry
 *
 *@author     diana abbas < dabbas @ umail ucsb edu >
 *@author     kyle dorman <kyle_dorman @ umail ucsb edu>
 *@version    1.0
 */
public class TrackBean implements EntityBean
{

	/**
	 *  The runtime context of the entity bean
	 *
	 *
	 */
	public EntityContext context;

	/**
	 *  Primary Key ID
	 *
	 *
	 */
	public Integer id;
	/**
	 *  Name of the track
	 *
	 *
	 */
	public String trackName;
	/**
	 *  Extended data which may or may not be present
	 *
	 *
	 */
	public String ext;
	/**
	 *  Number of the track on the disc
	 *
	 *
	 */
	public Integer trackNumber;
	/**
	 *  the CDDB disc id of the CD that this track is on
	 *
	 *
	 */
	public String discId;


	/**
	 *  Constructor for the Track object
	 *
	 *
	 */
	public TrackBean()
	{
		this.trackName = "";
		this.ext = "";
	}



	/**
	 *  Sets the TrackName attribute of the Track object
	 *
	 *@param  trackName  The new TrackName value
	 *
	 */
	public void setTrackName( String trackName )
	{
		this.trackName += trackName;
	}


	/**
	 *  Sets the Ext attribute of the Track object
	 *
	 *@param  ext  The new Ext value
	 *
	 */
	public void setExt( String ext )
	{
		this.ext = ext;
	}


	/**
	 *  Sets the TrackNumber attribute of the Track object
	 *
	 *@param  trackNumber  The new TrackNumber value
	 *
	 */
	public void setTrackNumber( Integer trackNumber )
	{
		this.trackNumber = trackNumber;
	}


	/**
	 *  Sets the DiscId attribute of the Track object
	 *
	 *@param  discId  The new DiscId value
	 *
	 */
	public void setDiscId( String discId )
	{
		this.discId = discId;
	}


	/**
	 *  Sets the Id attribute of the TrackBean object
	 *
	 *@param  id  The new Id value
	 *
	 */
	public void setId( Integer id )
	{
		this.id = id;
	}


	/**
	 *  Sets the EntityContext attribute of the TrackBean object
	 *
	 *@param  context              The new EntityContext value
	 *@exception  EJBException     Indicates a failure caused by a system-level error
	 *@exception  RemoteException  Provides backward compatibility for enterprise beans
	 *
	 */
	public void setEntityContext( EntityContext context )
			 throws EJBException, RemoteException
	{
		this.context = context;
	}


	/**
	 *  Gets the TrackName attribute of the Track object
	 *
	 *@return    The TrackName value
	 *
	 */
	public String getTrackName()
	{
		return trackName;
	}


	/**
	 *  Gets the Ext attribute of the Track object
	 *
	 *@return    The Ext value
	 *
	 */
	public String getExt()
	{
		return ext;
	}


	/**
	 *  Gets the TrackNumber attribute of the Track object
	 *
	 *@return    The TrackNumber value
	 *
	 */
	public Integer getTrackNumber()
	{
		return trackNumber;
	}


	/**
	 *  Gets the DiscId attribute of the Track object
	 *
	 *@return    The DiscId value
	 *
	 */
	public String getDiscId()
	{
		return discId;
	}


	/**
	 *  Gets the Id attribute of the TrackBean object
	 *
	 *@return    The Id value
	 *
	 */
	public Integer getId()
	{
		return id;
	}


	/**
	 *  Converts to a String which is the SQL INSERT statement to be used to add
	 *  this data to a database.
	 *
	 *@return    A string representation of the object.
	 *
	 */
	public String toString()
	{
		return "INSERT INTO tracks ( fkey, track_number, track_name, track_info ) VALUES ( '" +
				this.getDiscId() + "', " +
				this.getTrackNumber() + ", '" +
				this.getTrackName() + "', '" +
				this.getExt() + "' ); \n";
	}


	/**
	 *  Unset the associated entity context. The container calls this method before removing the instance
	 *
	 *@exception  EJBException     Indicates a failure caused by a system-level error
	 *@exception  RemoteException  Provides backward compatibility for enterprise beans
	 *
	 */
	public void unsetEntityContext()
			 throws EJBException, RemoteException
	{
	}


	/**
	 *  A container invokes this method when the instance is taken out of the pool of available instances to become associated with a specific EJB object. 
         *  This method transitions the instance to the ready state.
	 *
	 *@exception  EJBException     Indicates a failure caused by a system-level error
	 *@exception  RemoteException  Provides backward compatibility for enterprise beans
	 *
	 */
	public void ejbActivate()
			 throws EJBException, RemoteException
	{
	}


	/**
	 *  A container invokes this method to instruct the instance to synchronize its state by loading it state from the underlying database
	 *
	 *@exception  EJBException     Indicates a failure caused by a system-level error
	 *@exception  RemoteException  Provides backward compatibility for enterprise beans
	 *
	 */
	public void ejbLoad()
			 throws EJBException, RemoteException
	{
	}


	/**
	 *  A container invokes this method on an instance before the instance becomes disassociated with a specific EJB object. 
         *  After this method completes, the container will place the instance into the pool of available instances.
	 *
	 *@exception  EJBException     Indicates a failure caused by a system-level error
	 *@exception  RemoteException  Provides backward compatibility for enterprise beans
	 *@since                       empty
	 */
	public void ejbPassivate()
			 throws EJBException, RemoteException
	{
	}


	/**
	 *  A container invokes this method before it removes the EJB object that is currently associated with the instance.
	 *
	 *@exception  RemoveException  An attempt to remove an EJB object when the enterprise Bean or the container does not allow the EJB object to be removed
	 *@exception  EJBException     Indicates a failure caused by a system-level error
	 *@exception  RemoteException  Provides backward compatibility for enterprise beans
	 *
	 */
	public void ejbRemove()
			 throws EJBException, RemoteException, RemoveException
	{
	}


	/**
	 *  A container invokes this method to instruct the instance to synchronize its state by storing it to the underlying database.
	 *
	 *@exception  EJBException     Indicates a failure caused by a system-level error
	 *@exception  RemoteException  Provides backward compatibility for enterprise beans
	 *
	 */
	public void ejbStore()
			 throws EJBException, RemoteException
	{
	}


	/**
	 *  Creates a bean with the information given to it
	 *
	 *@param  discId               
	 *@param  trackName            
	 *@param  trackNumber          
	 *@param  ext                  Extended Data
	 *@return                      Returns a track bean
	 *@exception  CreateException  Failure to create an entity EJB object
	 *
	 */
	public Integer ejbCreate( String discId, String trackName, Integer trackNumber, String ext ) throws CreateException
	{
		this.discId = discId;
		this.trackName = trackName;
		this.trackNumber = trackNumber;
		this.ext = ext;
		return null;
	}


	/**
	 *  Manages the already created bean
	 *
	 *@param  discId               
	 *@param  trackName            
	 *@param  trackNumber          
	 *@param  ext                  Extended Data
	 *@exception  CreateException  Failure to create an entity EJB object
	 *
	 */
	public void ejbPostCreate( String discId, String trackName, Integer trackNumber, String ext ) throws CreateException
	{
	}

}
