net.wotonomy.datastore
Class FileSoup

java.lang.Object
  extended by net.wotonomy.datastore.FileSoup
All Implemented Interfaces:
DataSoup
Direct Known Subclasses:
SerializedFileSoup, XMLFileSoup

public abstract class FileSoup
extends java.lang.Object
implements DataSoup


Field Summary
protected  java.io.File homeDirectory
           
static java.lang.String INDEX_SUFFIX
           
protected  java.util.Map indices
           
static java.lang.String MAP_SUFFIX
           
protected  DataKey nextUniqueIdentifier
           
 
Constructor Summary
FileSoup(java.lang.String aPath)
           
 
Method Summary
 void addIndex(java.lang.String aName, java.lang.String aProperty)
          Adds an index to the soup.
 DataKey addObject(java.lang.Object anObject)
          Adds the specified object to the soup and returns the key for the new object by which it may be subsequently retrieved.
protected  void buildIndex(DataIndex anIndex)
           
 DataView createView()
          Returns an empty data view, suitable for creating new entries in the soup.
protected abstract  boolean deleteFile(java.lang.String name)
           
 java.util.Collection getAllIndices()
          Gets a collection of all indices in this soup.
 java.io.File getHomeDirectory()
           
protected  DataKey getNextKey()
           
protected  DataKey getNextTempKey()
           
 java.lang.Object getObjectByKey(DataKey aKey)
          Gets object from data store whose identifier is equal to the specified object.
 java.lang.Object getValueFromObject(java.lang.Object anObject, java.lang.String aProperty)
           
 DataView queryByIndex(java.lang.String anIndexName, java.lang.Object beginKey, java.lang.Object endKey)
          Queries by the specified pre-generated index, if it exists.
 DataView queryByKeys(java.util.Collection aKeyList)
          Returns a view containing the objects for the specified keys.
 DataView queryByProperty(java.lang.String aPropertyName, java.lang.Object beginKey, java.lang.Object endKey)
          Generates an index based on the specified property and then executes the query.
 DataView queryObjects(java.lang.Object beginKey, java.lang.Object endKey)
          Generates an index based on the specified property and then executes the query.
protected abstract  java.lang.Object readFile(java.lang.String name)
           
 DataKey registerTemporaryObject(java.lang.Object anObject)
          Registers an object that may or may not be created later, returning a temporary but uniquely identifiable key.
 void removeIndex(java.lang.String aName)
          Deletes the specified index from the soup.
 java.lang.Object removeObject(DataKey aKey)
          Removes the specified object from the soup and returns the removed object as read from the soup (which is the original copy of the object).
 DataView reverseQueryByIndex(java.lang.String anIndexName, java.lang.Object beginKey, java.lang.Object endKey)
          As queryByIndex, but with objects returned in reverse order.
 DataView reverseQueryByProperty(java.lang.String aPropertyName, java.lang.Object beginKey, java.lang.Object endKey)
          As queryByProperty, but with objects returned in reverse order.
 DataView reverseQueryObjects(java.lang.Object beginKey, java.lang.Object endKey)
          As queryObjects, but with objects returned in reverse order.
 java.lang.Object updateObject(DataKey aKey, java.lang.Object updatedObject)
          Updates the specified object and returns the object as updated.
protected abstract  boolean writeFile(java.lang.String name, java.lang.Object anObject)
           
protected  void writeIndices()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INDEX_SUFFIX

public static final java.lang.String INDEX_SUFFIX
See Also:
Constant Field Values

MAP_SUFFIX

public static final java.lang.String MAP_SUFFIX
See Also:
Constant Field Values

nextUniqueIdentifier

protected DataKey nextUniqueIdentifier

homeDirectory

protected java.io.File homeDirectory

indices

protected java.util.Map indices
Constructor Detail

FileSoup

public FileSoup(java.lang.String aPath)
Method Detail

getHomeDirectory

public java.io.File getHomeDirectory()

addIndex

public void addIndex(java.lang.String aName,
                     java.lang.String aProperty)
Description copied from interface: DataSoup
Adds an index to the soup.

Specified by:
addIndex in interface DataSoup
Parameters:
aName - The string identifier for this index.
aProperty - The property on which this index will be based.

removeIndex

public void removeIndex(java.lang.String aName)
Description copied from interface: DataSoup
Deletes the specified index from the soup.

Specified by:
removeIndex in interface DataSoup
Parameters:
aName - The string identifier for the index to be removed.

getAllIndices

public java.util.Collection getAllIndices()
Description copied from interface: DataSoup
Gets a collection of all indices in this soup.

Specified by:
getAllIndices in interface DataSoup
Returns:
A collection of all indices in this soup.

buildIndex

protected void buildIndex(DataIndex anIndex)

writeIndices

protected void writeIndices()

registerTemporaryObject

public DataKey registerTemporaryObject(java.lang.Object anObject)
Description copied from interface: DataSoup
Registers an object that may or may not be created later, returning a temporary but uniquely identifiable key. The key will be replaced with a permanent key when the object is created with addObject().

Specified by:
registerTemporaryObject in interface DataSoup
Parameters:
anObject - An object to be registered.
Returns:
A temporary key for this object.

addObject

public DataKey addObject(java.lang.Object anObject)
Adds the specified object to the soup and returns the key for the new object by which it may be subsequently retrieved. Null indicates an error, probably due to serialization.

Specified by:
addObject in interface DataSoup
Parameters:
anObject - Object to be added to soup.
Returns:
The unique identifier used for the new object.

removeObject

public java.lang.Object removeObject(DataKey aKey)
Removes the specified object from the soup and returns the removed object as read from the soup (which is the original copy of the object). Null indicates object not found.

Specified by:
removeObject in interface DataSoup
Parameters:
aKey - A key for an object to be removed.
Returns:
The object that was removed, or null if not found or error.

updateObject

public java.lang.Object updateObject(DataKey aKey,
                                     java.lang.Object updatedObject)
Updates the specified object and returns the object as updated. Null indicates an error writing the object.

Specified by:
updateObject in interface DataSoup
Parameters:
aKey - A key for an object to be updated.
Returns:
A copy of the updated object, possibly updated, or null if not found or error.

getNextKey

protected DataKey getNextKey()

getNextTempKey

protected DataKey getNextTempKey()

getObjectByKey

public java.lang.Object getObjectByKey(DataKey aKey)
Gets object from data store whose identifier is equal to the specified object.

Specified by:
getObjectByKey in interface DataSoup
Parameters:
aKey - A key for an object to be retrieved.
Returns:
The corresponding object from the soup.

createView

public DataView createView()
Returns an empty data view, suitable for creating new entries in the soup.

Specified by:
createView in interface DataSoup
Returns:
A DataView containing no entries.

queryByIndex

public DataView queryByIndex(java.lang.String anIndexName,
                             java.lang.Object beginKey,
                             java.lang.Object endKey)
Queries by the specified pre-generated index, if it exists. Otherwise, falls through to queryByProperty.

Specified by:
queryByIndex in interface DataSoup
Parameters:
anIndexName - The index to be queried.
Returns:
A DataView containing the query results, or null for invalid query parameters.

queryByProperty

public DataView queryByProperty(java.lang.String aPropertyName,
                                java.lang.Object beginKey,
                                java.lang.Object endKey)
Generates an index based on the specified property and then executes the query.

Specified by:
queryByProperty in interface DataSoup
Parameters:
aPropertyName - The property to be queried. If null, will query the objects directly with queryObjects().
Returns:
A DataView containing the query results, or null for invalid query parameters.

queryObjects

public DataView queryObjects(java.lang.Object beginKey,
                             java.lang.Object endKey)
Generates an index based on the specified property and then executes the query.

Specified by:
queryObjects in interface DataSoup
Returns:
A DataView containing the query results, or null for invalid query parameters.

queryByKeys

public DataView queryByKeys(java.util.Collection aKeyList)
Returns a view containing the objects for the specified keys.

Specified by:
queryByKeys in interface DataSoup
Parameters:
aKeyList - A collection of keys to be placed in the view.
Returns:
A DataView containing the objects for the corresponding keys, in the order in which the keys are returned from the collection.

reverseQueryByIndex

public DataView reverseQueryByIndex(java.lang.String anIndexName,
                                    java.lang.Object beginKey,
                                    java.lang.Object endKey)
As queryByIndex, but with objects returned in reverse order.

Specified by:
reverseQueryByIndex in interface DataSoup
Parameters:
anIndexName - The index to be queried.
beginValue - The beginning value, or null for all values up to an including the end key.
endValue - The ending value, or null for all values since and including the begin key.
Returns:
A DataView containing the query results, or null for invalid query parameters.

reverseQueryByProperty

public DataView reverseQueryByProperty(java.lang.String aPropertyName,
                                       java.lang.Object beginKey,
                                       java.lang.Object endKey)
As queryByProperty, but with objects returned in reverse order.

Specified by:
reverseQueryByProperty in interface DataSoup
Parameters:
aPropertyName - The property to be queried. If null, will query the objects directly with queryObjects().
beginValue - The beginning value, or null for all values up to an including the end key.
endValue - The ending value, or null for all values since and including the begin key.
Returns:
A DataView containing the query results, or null for invalid query parameters.

reverseQueryObjects

public DataView reverseQueryObjects(java.lang.Object beginKey,
                                    java.lang.Object endKey)
As queryObjects, but with objects returned in reverse order.

Specified by:
reverseQueryObjects in interface DataSoup
Parameters:
beginValue - The beginning value, or null for all values up to an including the end key.
endValue - The ending value, or null for all values since and including the begin key.
Returns:
A DataView containing the query results, or null for invalid query parameters.

getValueFromObject

public java.lang.Object getValueFromObject(java.lang.Object anObject,
                                           java.lang.String aProperty)

writeFile

protected abstract boolean writeFile(java.lang.String name,
                                     java.lang.Object anObject)

readFile

protected abstract java.lang.Object readFile(java.lang.String name)

deleteFile

protected abstract boolean deleteFile(java.lang.String name)


Copyright © 2006 null. All Rights Reserved.