package doc.walkthru;

import org.benow.java.annotations.Required;
import org.benow.repository.mapping.JSQLObject;

/**
 * Utility class for uniting the position of a track within an album.  
 */
public class AlbumTrack extends JSQLObject {
  
  // serialVersionUID is used to version repository table
  private static final long serialVersionUID = 1L;
  
  private AlbumImpl album;
  private int pos;
  // ensure track is always fetched from the repository when this is
  @Required
  private TrackImpl track;
  
  // repository requires a zero parameter constructor.
  protected AlbumTrack() {
    super();
  }
  
  public AlbumTrack(AlbumImpl album, TrackImpl track, int pos) {
    super();
    this.album=album;
    this.track=track;
    this.pos=pos;
  }
  
  public Album getAlbum() {
    // ensure album is fetched
    fetchFieldQuiet("album");
    return album;
  }
  public int getPositionInAlbum() {
    return pos;
  }
  public Track getTrack() {
    // track is marked with @Required, so it'll always be there
    return track;
  }

  public void setPosition(int pos) {
    this.pos=pos;
  }
}

