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

Quick Search    Search Deep

com.virtuosotechnologies.asaph.xmldatabase
Class IndexedSongDatabase  view IndexedSongDatabase download IndexedSongDatabase.java

java.lang.Object
  extended bycom.virtuosotechnologies.asaph.xmldatabase.IndexedSongDatabase
All Implemented Interfaces:
com.virtuosotechnologies.asaph.model.SongDatabase

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

Indexed implementation of SongDatabase


Nested Class Summary
(package private)  class IndexedSongDatabase.IndexXMLHandler
          DefaultHandler for initial loading of the index file
(package private)  class IndexedSongDatabase.SongIDImpl
          Implementation of SongID for this database
(package private)  class IndexedSongDatabase.SongInfoCache
          Cache of song info
 
Field Summary
private  java.io.File fileDirectory_
           
private  com.virtuosotechnologies.lib.util.StringID lastSongID_
           
private  java.util.logging.Logger logger_
           
private  com.virtuosotechnologies.asaph.standardmodel.StandardModelFactory modelFactory_
           
private  java.util.Map songMap_
           
private  com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils_
           
private static java.lang.String STR_err_CantFindIndex
           
private static java.lang.String STR_PreferredCharacterEncoding
           
private  java.net.URL urlDirectory_
           
 
Constructor Summary
(package private) IndexedSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils, com.virtuosotechnologies.asaph.standardmodel.StandardModelFactory modelFactory, java.io.File fileDirectory, javax.xml.parsers.SAXParser parser, java.lang.String dtdString)
          Constructor for mutable database
(package private) IndexedSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils, com.virtuosotechnologies.asaph.standardmodel.StandardModelFactory modelFactory, java.net.URL urlDirectory, javax.xml.parsers.SAXParser parser, java.lang.String dtdString, org.xml.sax.ErrorHandler errorHandler)
          Constructor for immutable database
 
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.
private  boolean commitIndex()
           
 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.
private  java.io.OutputStream getOutputStream(java.lang.String fileName)
          Utility method
private  java.io.Reader getReader(java.lang.String fileName)
          Utility method
 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.
private  void performGetField(com.virtuosotechnologies.asaph.model.SongIDResultSet resultSet, java.lang.String fieldName)
           
 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.
private  void performSearchField(com.virtuosotechnologies.asaph.model.SongIDResultSet resultSet, java.lang.String fieldName, com.virtuosotechnologies.asaph.model.opsemantics.SearchParameters params)
           
 boolean removeSong(com.virtuosotechnologies.asaph.model.SongID id)
          Remove the given song from the database.
private  void writeIndex(java.io.OutputStream stream)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STR_err_CantFindIndex

private static final java.lang.String STR_err_CantFindIndex

STR_PreferredCharacterEncoding

private static final java.lang.String STR_PreferredCharacterEncoding

lastSongID_

private com.virtuosotechnologies.lib.util.StringID lastSongID_

songMap_

private java.util.Map songMap_

songUtils_

private com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils_

modelFactory_

private com.virtuosotechnologies.asaph.standardmodel.StandardModelFactory modelFactory_

fileDirectory_

private java.io.File fileDirectory_

urlDirectory_

private java.net.URL urlDirectory_

logger_

private java.util.logging.Logger logger_
Constructor Detail

IndexedSongDatabase

IndexedSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils,
                    com.virtuosotechnologies.asaph.standardmodel.StandardModelFactory modelFactory,
                    java.net.URL urlDirectory,
                    javax.xml.parsers.SAXParser parser,
                    java.lang.String dtdString,
                    org.xml.sax.ErrorHandler errorHandler)
              throws java.io.IOException,
                     org.xml.sax.SAXException
Constructor for immutable database


IndexedSongDatabase

IndexedSongDatabase(com.virtuosotechnologies.asaph.modelutils.SongUtils songUtils,
                    com.virtuosotechnologies.asaph.standardmodel.StandardModelFactory modelFactory,
                    java.io.File fileDirectory,
                    javax.xml.parsers.SAXParser parser,
                    java.lang.String dtdString)
              throws java.io.IOException
Constructor for mutable database

Method Detail

getReader

private java.io.Reader getReader(java.lang.String fileName)
Utility method


getOutputStream

private java.io.OutputStream getOutputStream(java.lang.String fileName)
Utility method


commitIndex

private boolean commitIndex()

writeIndex

private void writeIndex(java.io.OutputStream stream)
                 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

performGetField

private void performGetField(com.virtuosotechnologies.asaph.model.SongIDResultSet resultSet,
                             java.lang.String fieldName)

performSearchField

private void performSearchField(com.virtuosotechnologies.asaph.model.SongIDResultSet resultSet,
                                java.lang.String fieldName,
                                com.virtuosotechnologies.asaph.model.opsemantics.SearchParameters params)

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