Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.virtuosotechnologies.asaph.standardmodel
Class SimpleSongDatabase  view SimpleSongDatabase download SimpleSongDatabase.java

java.lang.Object
  extended bycom.virtuosotechnologies.asaph.standardmodel.SimpleSongDatabase
All Implemented Interfaces:
com.virtuosotechnologies.asaph.model.SongDatabase

class SimpleSongDatabase
extends java.lang.Object
implements com.virtuosotechnologies.asaph.model.SongDatabase

Simple implementation of SongDatabase


Nested Class Summary
(package private)  class SimpleSongDatabase.ParseHandler
           
(package private)  class SimpleSongDatabase.SongIDImpl
          Implementation of SongID
 
Field Summary
private  com.virtuosotechnologies.lib.util.StringID lastSongID_
           
private  java.util.Map songMap_
           
private  com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils_
           
private  boolean writable_
           
 
Constructor Summary
(package private) SimpleSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils)
           
(package private) SimpleSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils, java.lang.String lastID)
           
(package private) SimpleSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils, java.lang.String lastID, boolean writable)
           
 
Method Summary
 com.virtuosotechnologies.asaph.model.SongID addCopyOfSong(com.virtuosotechnologies.asaph.model.Song original)
          Makes a copy of the given song and adds it to the database.
 com.virtuosotechnologies.asaph.model.SongID addEmptySong(java.lang.String title, java.util.Locale locale)
          Add a new empty Song to the database.
 com.virtuosotechnologies.asaph.model.Song checkOutSong(com.virtuosotechnologies.asaph.model.SongID id)
          Get a song by SongID.
 void commitSong(com.virtuosotechnologies.asaph.model.Song song)
          Commit changes to this song.
 boolean containsSongID(com.virtuosotechnologies.asaph.model.SongID id)
          Tests whether the given song id exists in this database.
 com.virtuosotechnologies.asaph.model.SongIDResultSet createEmptyResultSet()
          Create an empty result set.
 void forceCommitSong(com.virtuosotechnologies.asaph.model.Song song)
          Commit changes to this song.
 void forceCommitSongAs(com.virtuosotechnologies.asaph.model.Song song, com.virtuosotechnologies.asaph.model.SongID songID)
          Force-commit a song as the given SongID.
 com.virtuosotechnologies.asaph.model.SongID getSongIDForString(java.lang.String idStr)
          Get the SongID for the given string, if it exists.
 boolean isSongFresh(com.virtuosotechnologies.asaph.model.Song song)
          Check the commit count to see if this song is still fresh.
 boolean isWritable()
          Returns true if the database is writable.
 com.virtuosotechnologies.asaph.model.SongIDResultSet performOperation(com.virtuosotechnologies.asaph.model.SongOperation operation, com.virtuosotechnologies.asaph.model.SongIDResultSet param)
          Perform an operation on a set of songs.
 boolean removeSong(com.virtuosotechnologies.asaph.model.SongID id)
          Remove the given song from the database.
(package private)  void unparse(com.virtuosotechnologies.lib.xml.XMLUnparser unparser)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lastSongID_

private com.virtuosotechnologies.lib.util.StringID lastSongID_

songMap_

private java.util.Map songMap_

songUtils_

private com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils_

writable_

private boolean writable_
Constructor Detail

SimpleSongDatabase

SimpleSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils)

SimpleSongDatabase

SimpleSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils,
                   java.lang.String lastID)

SimpleSongDatabase

SimpleSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils,
                   java.lang.String lastID,
                   boolean writable)
Method Detail

unparse

void unparse(com.virtuosotechnologies.lib.xml.XMLUnparser unparser)
       throws java.io.IOException

isWritable

public boolean isWritable()
Returns true if the database is writable. If this returns false, every mutation method will throw DatabaseNotWritableException. Note that even if this returns false, the database may still be changed by other entities. In other words, this method reflects the ability to write to the database through this interface, not necessarily through all interfaces.

Specified by:
isWritable in interface com.virtuosotechnologies.asaph.model.SongDatabase

checkOutSong

public com.virtuosotechnologies.asaph.model.Song checkOutSong(com.virtuosotechnologies.asaph.model.SongID id)
                                                       throws com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Get a song by SongID. Note that the Song returned is a copy. Changes do not get reflected in the database until commitSong() succeeds. Returns null if the song doesn't exist in this database. (This could mean the song was deleted, or it is part of a different database.)

Specified by:
checkOutSong in interface com.virtuosotechnologies.asaph.model.SongDatabase

containsSongID

public boolean containsSongID(com.virtuosotechnologies.asaph.model.SongID id)
                       throws com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Tests whether the given song id exists in this database. Returns false if the song was deleted or if it is part of a different database.

Specified by:
containsSongID in interface com.virtuosotechnologies.asaph.model.SongDatabase

getSongIDForString

public com.virtuosotechnologies.asaph.model.SongID getSongIDForString(java.lang.String idStr)
                                                               throws com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Get the SongID for the given string, if it exists. This is used to deserialize a SongID that was stored persistently as its string representation. Returns null if the string does not correspond to a SongID that exists in this database.

Specified by:
getSongIDForString in interface com.virtuosotechnologies.asaph.model.SongDatabase

createEmptyResultSet

public com.virtuosotechnologies.asaph.model.SongIDResultSet createEmptyResultSet()
Create an empty result set.

Specified by:
createEmptyResultSet in interface com.virtuosotechnologies.asaph.model.SongDatabase

performOperation

public com.virtuosotechnologies.asaph.model.SongIDResultSet performOperation(com.virtuosotechnologies.asaph.model.SongOperation operation,
                                                                             com.virtuosotechnologies.asaph.model.SongIDResultSet param)
                                                                      throws com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Perform an operation on a set of songs. Operations could be accessors for information that could be cached by the database, such as the main title, or they could be filters applied to the result set, or they could have other semantics such as mass-checkouts or mass-checkins. The client specifies as the parameter a SongIDResultSet specifying the songs and parameter data for the operation. If null is passed, the database creates a new SongIDResultSet whose values are all the SongIDs in the database with null data for each one. The client also specifies the operation to perform. The method performs the operation on the result set in place, and then returns it.

Note that some SongDatabase implementations may choose to optimize this method by not calling the operation directly, but by analzying the semantics of the operation as declared by which operation semantics interfaces are implemented, and performing accelerated operations such as checking caches. Thus, do not expect that the SongOperation object you pass will actually be invoked.

One common use of this method is to get a result set containing all the SongIDs in the database. This is accomplished by passing null for the parameter, and a NopSemantics implementation for the operation.

Specified by:
performOperation in interface com.virtuosotechnologies.asaph.model.SongDatabase

addEmptySong

public com.virtuosotechnologies.asaph.model.SongID addEmptySong(java.lang.String title,
                                                                java.util.Locale locale)
                                                         throws com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Add a new empty Song to the database.

Specified by:
addEmptySong in interface com.virtuosotechnologies.asaph.model.SongDatabase

addCopyOfSong

public com.virtuosotechnologies.asaph.model.SongID addCopyOfSong(com.virtuosotechnologies.asaph.model.Song original)
                                                          throws com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Makes a copy of the given song and adds it to the database. The given song need not be from this database. On completion, the song in the database will be identical to the given song, but the given song will not be modified. In particular, if the given song is owned by a different database, it will still be owned by that database.

Specified by:
addCopyOfSong in interface com.virtuosotechnologies.asaph.model.SongDatabase

removeSong

public boolean removeSong(com.virtuosotechnologies.asaph.model.SongID id)
                   throws com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Remove the given song from the database. Returns true if the song existed and was removed, or false if it was not present.

Specified by:
removeSong in interface com.virtuosotechnologies.asaph.model.SongDatabase

isSongFresh

public boolean isSongFresh(com.virtuosotechnologies.asaph.model.Song song)
                    throws com.virtuosotechnologies.asaph.model.SongDeletedException,
                           com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Check the commit count to see if this song is still fresh. In other words, this returns true if the song has not been committed by someone else since this copy was checked out. Note that this should be taken to mean "this song was fresh a little while ago." A return value of true should not be taken as a guarantee that a subsequent call to commitSong will not throw SongNotFreshException, because another client may commit in between.

Specified by:
isSongFresh in interface com.virtuosotechnologies.asaph.model.SongDatabase

commitSong

public void commitSong(com.virtuosotechnologies.asaph.model.Song song)
                throws com.virtuosotechnologies.asaph.model.SongNotFreshException,
                       com.virtuosotechnologies.asaph.model.SongDeletedException,
                       com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Commit changes to this song. Also sets this song to fresh, since it now reflects the database contents. Does not perform the commit and throws SongNotFreshException if someone already committed a change in the meantime.

Specified by:
commitSong in interface com.virtuosotechnologies.asaph.model.SongDatabase

forceCommitSong

public void forceCommitSong(com.virtuosotechnologies.asaph.model.Song song)
                     throws com.virtuosotechnologies.asaph.model.SongDeletedException,
                            com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Commit changes to this song. Also sets this song to fresh, since it now reflects the database contents. Commits and overwrites any changes made by clients in the meantime. (In other words, doesn't throw SongNotFreshException.)

Specified by:
forceCommitSong in interface com.virtuosotechnologies.asaph.model.SongDatabase

forceCommitSongAs

public void forceCommitSongAs(com.virtuosotechnologies.asaph.model.Song song,
                              com.virtuosotechnologies.asaph.model.SongID songID)
                       throws com.virtuosotechnologies.asaph.model.SongDeletedException,
                              com.virtuosotechnologies.asaph.model.SongDatabaseFailedException
Force-commit a song as the given SongID. The given SongID must be in this database, but the given checked-out song need not be from this database. On completion, the song in the database will be identical to the given song, but the given song will not be modified. In particular, if the given song is owned by a different database, it will still be owned by that database.

Specified by:
forceCommitSongAs in interface com.virtuosotechnologies.asaph.model.SongDatabase