org.objectweb.jac.aspects.persistence
Class FSStorage

java.lang.Object
  extended byorg.objectweb.jac.aspects.persistence.FSStorage
All Implemented Interfaces:
Storage

public class FSStorage
extends Object
implements Storage

A FileSystem storage


Field Summary
protected  String encoding
           
protected  String id
           
 
Constructor Summary
FSStorage(PersistenceAC ac, String basedirName)
          Create a new file system storage with the default encoding
FSStorage(PersistenceAC ac, String basedirName, String encoding)
          Create a new file system storage
 
Method Summary
 void addToList(OID cid, long position, Object value)
          Insert a value into an existing List.
 void addToList(OID cid, Object value)
          Add a value at the end of a list.
 boolean addToSet(OID cid, Object value)
          Add an object to a Set.
 void bindOIDToName(OID oid, String name)
          Bind an existing object to a logical name to that it can be found later on.
 void clearList(OID cid)
          Remove all objects from a list.
 void clearMap(OID cid)
          Remove all objects from a set.
 void clearSet(OID cid)
          Remove all objects from a set.
 void close()
          Safely close the storage.
 void commit()
          Commit started transaction
 OID createObject(String className)
          Create an object in the storage.
 void deleteName(String name)
          Delete a name from the storage.
 void deleteObject(OID oid)
          Delete an object from the storage.
 String getClassID(OID oid)
          Get the class ID of a given object.
 OID getCollectionID(OID oid, CollectionItem collection)
          Get the ID of a collection
protected  long getCollectionSize(OID cid)
           
 Object getField(OID oid, FieldItem field)
          Get the value of a field.
protected  Properties getFields(OID oid)
           
 StorageField[] getFields(OID oid, ClassItem cl, FieldItem[] fields)
          Get the values of several fields.
 Object getFromMap(OID cid, Object key)
          Get the value associated to a key from a Map.
 String getId()
          Returns the id of the storage
 long getIndexInList(OID cid, Object value)
          Get the smallest index of an element in a List.
 long getLastIndexInList(OID cid, Object value)
          Get the highest index of an element in a List.
 List getList(OID cid)
          Get a List from the storage.
 List getList(OID oid, CollectionItem collection)
          Get a List from the storage.
 Object getListItem(OID cid, long index)
          Get an element from a list
 long getListSize(OID cid)
          Get the number of objects contained in a list
 Map getMap(OID cid)
          Get the elements of a Map.
 Map getMap(OID oid, CollectionItem collection)
          Describe getMap method here.
 long getMapSize(OID cid)
          Get the number of objects contained in a map
 Map getNameCounters()
          Gets the name counters used to generate new names.
 String getNameFromOID(OID oid)
          Get the name of an object from its oid.
 Collection getObjects(ClassItem cl)
          Get all instances of a class, or all objects if cl == null.
protected  void getObjects(ClassItem cl, Vector objects)
          Gets all instances of a class and its subclasses.
 OID getOIDFromName(String name)
          Get the ID of an object from its name.
protected  PrintWriter getPrintWriter(File file, boolean append, boolean autoFlush)
           
protected  PrintWriter getPrintWriter(OID oid, boolean append, boolean autoFlush)
           
protected  PrintWriter getPrintWriter(OutputStream stream, boolean autoFlush)
           
 Collection getRootObjects()
          Get OIDs of all root objects.
 List getSet(OID cid)
          Get the elements of a Set.
 List getSet(OID oid, CollectionItem collection)
          Get the elements of a Set.
 long getSetSize(OID cid)
          Get the number of objects contained in a set
protected  StreamTokenizer getStreamTokenizer(File file)
           
protected  Writer getWriter(File file, boolean append)
           
 boolean listContains(OID cid, Object value)
          Say if a List contains an object.
 boolean mapContainsKey(OID cid, Object key)
          Says if a Map contains a key.
 boolean mapContainsValue(OID cid, Object value)
          Says if a Map contains a value.
 String newName(String className)
          Generate a new name for an instance.
 Object putInMap(OID cid, Object key, Object value)
          Put an element in a Map.
 void removeField(OID oid, FieldItem field, Object value)
          Remove a field from an existing object.
 void removeFromList(OID cid, long position)
          Remove a value from an existing list.
 void removeFromList(OID cid, Object value)
          Remove the first value from an existing list.
 Object removeFromMap(OID cid, Object key)
          Remove a key from a Map.
 boolean removeFromSet(OID cid, Object value)
          Remove an element from a Set.
 void rollback()
          Rollback started transaction
protected  void saveList(OID cid, List list)
           
protected  void saveMap(OID cid, Map map)
           
 boolean setContains(OID cid, Object value)
          Say if a set contains an object.
 void setField(OID oid, FieldItem field, Object value)
          Initialize the value of an object's field.
 void setId(String id)
          Sets the id of the storage
 void setListItem(OID cid, long index, Object value)
          Set the value of a list element.
 void startTransaction()
          Starts a transaction
 void updateField(OID oid, FieldItem field, Object value)
          Update a field value.
protected  void updateJacNames()
           
 void updateNameCounters(Map counters)
          Sets the name counters used to generate new names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

encoding

protected String encoding

id

protected String id
Constructor Detail

FSStorage

public FSStorage(PersistenceAC ac,
                 String basedirName)
          throws Exception
Create a new file system storage with the default encoding

Parameters:
basedirName - name of the directory where to store data files

FSStorage

public FSStorage(PersistenceAC ac,
                 String basedirName,
                 String encoding)
          throws Exception
Create a new file system storage

Parameters:
basedirName - name of the directory where to store data files
encoding - the encoding to use for files
Method Detail

getId

public String getId()
Description copied from interface: Storage
Returns the id of the storage

Specified by:
getId in interface Storage

setId

public void setId(String id)
Description copied from interface: Storage
Sets the id of the storage

Specified by:
setId in interface Storage

updateJacNames

protected void updateJacNames()

close

public void close()
Safely close the storage. Waits for all operations to terminate.

Specified by:
close in interface Storage

getNameCounters

public Map getNameCounters()
Description copied from interface: Storage
Gets the name counters used to generate new names.

Specified by:
getNameCounters in interface Storage
Returns:
a Map associating counter names to a Long value. The value is the next value to be used.
See Also:
Storage.updateNameCounters(Map)

updateNameCounters

public void updateNameCounters(Map counters)
                        throws IOException
Description copied from interface: Storage
Sets the name counters used to generate new names.

Specified by:
updateNameCounters in interface Storage
Parameters:
counters - a Map associating counter names to a Long value. The value is the next value to be used. A counter is updated only if the suplied value is greater than the current value.
Throws:
IOException
See Also:
Storage.getNameCounters()

getStreamTokenizer

protected StreamTokenizer getStreamTokenizer(File file)
                                      throws FileNotFoundException,
                                             IOException
Throws:
FileNotFoundException
IOException

createObject

public OID createObject(String className)
                 throws Exception
Description copied from interface: Storage
Create an object in the storage.

Specified by:
createObject in interface Storage
Parameters:
className - a String value
Returns:
the OID of new object
Throws:
Exception - if an error occurs

deleteObject

public void deleteObject(OID oid)
                  throws Exception
Description copied from interface: Storage
Delete an object from the storage.

Specified by:
deleteObject in interface Storage
Parameters:
oid - the ID of the object to delete
Throws:
Exception - if an error occurs

setField

public void setField(OID oid,
                     FieldItem field,
                     Object value)
              throws Exception
Description copied from interface: Storage
Initialize the value of an object's field. The field must not have already been set.

Specified by:
setField in interface Storage
Parameters:
oid - the ID of the object that will contain the field
field - the field to set
value - the value of the field
Throws:
Exception - if an error occurs

updateField

public void updateField(OID oid,
                        FieldItem field,
                        Object value)
                 throws Exception
Description copied from interface: Storage
Update a field value.

Specified by:
updateField in interface Storage
Parameters:
oid - the ID of the object that already contains the field
field - the field to update
value - the new value of the field
Throws:
Exception - if an error occurs

getField

public Object getField(OID oid,
                       FieldItem field)
                throws Exception
Description copied from interface: Storage
Get the value of a field.

Specified by:
getField in interface Storage
Parameters:
oid - the ID of the object that contains the field
field - the field to retrieve
Returns:
the stored value of the field, or null if there's no stored value for that field
Throws:
Exception - if an error occurs

getFields

protected Properties getFields(OID oid)
                        throws IOException
Throws:
IOException

getFields

public StorageField[] getFields(OID oid,
                                ClassItem cl,
                                FieldItem[] fields)
                         throws Exception
Description copied from interface: Storage
Get the values of several fields.

Specified by:
getFields in interface Storage
Parameters:
oid - the ID of object to retrieve
cl - the class of the object
fields - the fields to retrieve
Returns:
the value of the fields
Throws:
Exception - if an error occurs

getCollectionSize

protected long getCollectionSize(OID cid)
                          throws Exception
Throws:
Exception

getCollectionID

public OID getCollectionID(OID oid,
                           CollectionItem collection)
                    throws Exception
Description copied from interface: Storage
Get the ID of a collection

Specified by:
getCollectionID in interface Storage
Parameters:
oid - the oid of he object that owns the collection
collection - the collection
Returns:
the id of the collection
Throws:
Exception - if an error occurs

clearList

public void clearList(OID cid)
               throws Exception
Description copied from interface: Storage
Remove all objects from a list.

Specified by:
clearList in interface Storage
Parameters:
cid - the ID of the list to clear
Throws:
Exception - if an error occurs

getList

public List getList(OID oid,
                    CollectionItem collection)
             throws Exception
Description copied from interface: Storage
Get a List from the storage.

Specified by:
getList in interface Storage
Parameters:
oid - the ID of the object that contains the vector
collection - the collection to retrieve
Returns:
the List
Throws:
Exception - if an error occurs

getList

public List getList(OID cid)
             throws Exception
Description copied from interface: Storage
Get a List from the storage.

Specified by:
getList in interface Storage
Parameters:
cid - the ID of the List
Returns:
the List
Throws:
Exception - if an error occurs

getListSize

public long getListSize(OID cid)
                 throws Exception
Description copied from interface: Storage
Get the number of objects contained in a list

Specified by:
getListSize in interface Storage
Parameters:
cid - the ID of the list
Returns:
the number of objects contained in the list
Throws:
Exception - if an error occurs

getListItem

public Object getListItem(OID cid,
                          long index)
                   throws Exception,
                          IndexOutOfBoundsException
Description copied from interface: Storage
Get an element from a list

Specified by:
getListItem in interface Storage
Parameters:
cid - the ID of the List
index - the index of the element
Returns:
the element
Throws:
Exception - if an error occurs
IndexOutOfBoundsException

listContains

public boolean listContains(OID cid,
                            Object value)
                     throws Exception
Description copied from interface: Storage
Say if a List contains an object.

Specified by:
listContains in interface Storage
Parameters:
cid - the ID of the List
value - the object to look for in the list
Returns:
wether the List contains the value
Throws:
Exception - if an error occurs

saveList

protected void saveList(OID cid,
                        List list)
                 throws IOException
Throws:
IOException

addToList

public void addToList(OID cid,
                      long position,
                      Object value)
               throws Exception
Description copied from interface: Storage
Insert a value into an existing List.

Specified by:
addToList in interface Storage
Parameters:
cid - the ID of the List
position - the position where to insert the value
value - the value to insert
Throws:
Exception - if an error occurs

addToList

public void addToList(OID cid,
                      Object value)
               throws Exception
Description copied from interface: Storage
Add a value at the end of a list.

Specified by:
addToList in interface Storage
Parameters:
cid - the ID of the List
value - the value to add
Throws:
Exception - if an error occurs

setListItem

public void setListItem(OID cid,
                        long index,
                        Object value)
                 throws Exception
Description copied from interface: Storage
Set the value of a list element.

Specified by:
setListItem in interface Storage
Parameters:
cid - the ID of the List
index - the index of the element to set
value - the value
Throws:
Exception - if an error occurs

removeFromList

public void removeFromList(OID cid,
                           long position)
                    throws Exception
Description copied from interface: Storage
Remove a value from an existing list.

Specified by:
removeFromList in interface Storage
Parameters:
cid - the ID the List
position - the position of the element to remove
Throws:
Exception - if an error occurs

removeFromList

public void removeFromList(OID cid,
                           Object value)
                    throws Exception
Description copied from interface: Storage
Remove the first value from an existing list.

Specified by:
removeFromList in interface Storage
Parameters:
cid - the ID the List
value - the value to remove
Throws:
Exception - if an error occurs

getIndexInList

public long getIndexInList(OID cid,
                           Object value)
                    throws Exception
Description copied from interface: Storage
Get the smallest index of an element in a List.

Specified by:
getIndexInList in interface Storage
Parameters:
cid - the ID of the List
value - the value
Returns:
the index of value
Throws:
Exception - if an error occurs

getLastIndexInList

public long getLastIndexInList(OID cid,
                               Object value)
                        throws Exception
Description copied from interface: Storage
Get the highest index of an element in a List.

Specified by:
getLastIndexInList in interface Storage
Parameters:
cid - the ID of the List
value - the value
Returns:
the index of value
Throws:
Exception - if an error occurs

clearSet

public void clearSet(OID cid)
              throws Exception
Description copied from interface: Storage
Remove all objects from a set.

Specified by:
clearSet in interface Storage
Parameters:
cid - the ID of the set to clear
Throws:
Exception - if an error occurs

getSet

public List getSet(OID oid,
                   CollectionItem collection)
            throws Exception
Description copied from interface: Storage
Get the elements of a Set.

Specified by:
getSet in interface Storage
Parameters:
oid - the ID of the object that contains the Set
collection - the collection
Returns:
the elements of the Set
Throws:
Exception - if an error occurs

getSet

public List getSet(OID cid)
            throws Exception
Description copied from interface: Storage
Get the elements of a Set.

Specified by:
getSet in interface Storage
Parameters:
cid - the ID of the Set
Returns:
the elements of the Set
Throws:
Exception - if an error occurs

getSetSize

public long getSetSize(OID cid)
                throws Exception
Description copied from interface: Storage
Get the number of objects contained in a set

Specified by:
getSetSize in interface Storage
Parameters:
cid - the ID of the list
Returns:
the number of objects contained in the set
Throws:
Exception - if an error occurs

addToSet

public boolean addToSet(OID cid,
                        Object value)
                 throws Exception
Description copied from interface: Storage
Add an object to a Set.

Specified by:
addToSet in interface Storage
Parameters:
cid - the ID of the Set
value - the value to add
Returns:
true if the set did not already contain the object, false otherwise.
Throws:
Exception - if an error occurs

removeFromSet

public boolean removeFromSet(OID cid,
                             Object value)
                      throws Exception
Description copied from interface: Storage
Remove an element from a Set.

Specified by:
removeFromSet in interface Storage
Parameters:
cid - the ID of the Set
value - the value to add
Returns:
wether the set did contain the object
Throws:
Exception - if an error occurs

setContains

public boolean setContains(OID cid,
                           Object value)
                    throws Exception
Description copied from interface: Storage
Say if a set contains an object.

Specified by:
setContains in interface Storage
Parameters:
cid - the ID of the Set
value - the value
Returns:
wether the Set contains the value
Throws:
Exception - if an error occurs

getMap

public Map getMap(OID oid,
                  CollectionItem collection)
           throws Exception
Description copied from interface: Storage
Describe getMap method here.

Specified by:
getMap in interface Storage
Parameters:
oid - an OID value
collection - a CollectionItem value
Returns:
a Map value
Throws:
Exception - if an error occurs

getMap

public Map getMap(OID cid)
           throws Exception
Description copied from interface: Storage
Get the elements of a Map.

Specified by:
getMap in interface Storage
Parameters:
cid - the ID of the Set
Returns:
the Map
Throws:
Exception - if an error occurs

getMapSize

public long getMapSize(OID cid)
                throws Exception
Description copied from interface: Storage
Get the number of objects contained in a map

Specified by:
getMapSize in interface Storage
Parameters:
cid - the ID of the list
Returns:
the number of objects contained in the map
Throws:
Exception - if an error occurs

saveMap

protected void saveMap(OID cid,
                       Map map)
                throws IOException
Throws:
IOException

clearMap

public void clearMap(OID cid)
              throws Exception
Description copied from interface: Storage
Remove all objects from a set.

Specified by:
clearMap in interface Storage
Parameters:
cid - the ID of the set to clear
Throws:
Exception - if an error occurs

putInMap

public Object putInMap(OID cid,
                       Object key,
                       Object value)
                throws Exception
Description copied from interface: Storage
Put an element in a Map.

Specified by:
putInMap in interface Storage
Parameters:
cid - the ID of the Map
key - the key
value - the value
Returns:
the previous value associated with the key
Throws:
Exception - if an error occurs

getFromMap

public Object getFromMap(OID cid,
                         Object key)
                  throws Exception
Description copied from interface: Storage
Get the value associated to a key from a Map.

Specified by:
getFromMap in interface Storage
Parameters:
cid - the ID of the Map
key - the key
Returns:
the value associated with the key
Throws:
Exception - if an error occurs

mapContainsKey

public boolean mapContainsKey(OID cid,
                              Object key)
                       throws Exception
Description copied from interface: Storage
Says if a Map contains a key.

Specified by:
mapContainsKey in interface Storage
Parameters:
cid - the ID of the Map
key - the key to search
Returns:
wether the Map contains the key
Throws:
Exception - if an error occurs

mapContainsValue

public boolean mapContainsValue(OID cid,
                                Object value)
                         throws Exception
Description copied from interface: Storage
Says if a Map contains a value.

Specified by:
mapContainsValue in interface Storage
Parameters:
cid - the ID of the Map
value - the value to search
Returns:
wether the Map contains the value
Throws:
Exception - if an error occurs

removeFromMap

public Object removeFromMap(OID cid,
                            Object key)
                     throws Exception
Description copied from interface: Storage
Remove a key from a Map.

Specified by:
removeFromMap in interface Storage
Parameters:
cid - the ID the Map
key - the key to remove
Returns:
the previous value associated to the key, or null
Throws:
Exception - if an error occurs

removeField

public void removeField(OID oid,
                        FieldItem field,
                        Object value)
                 throws Exception
Description copied from interface: Storage
Remove a field from an existing object.

Specified by:
removeField in interface Storage
Parameters:
oid - the ID of the object that contains the field
field - the ID of the field to remove
value - Deprecated
Throws:
Exception

newName

public String newName(String className)
               throws Exception
Description copied from interface: Storage
Generate a new name for an instance.

Specified by:
newName in interface Storage
Parameters:
className - the className of the instance for which to generate a name
Returns:
the generated name, null if failure
Throws:
Exception

getOIDFromName

public OID getOIDFromName(String name)
                   throws Exception
Description copied from interface: Storage
Get the ID of an object from its name.

Specified by:
getOIDFromName in interface Storage
Parameters:
name - the candidate object name
Returns:
null if not found
Throws:
Exception

getNameFromOID

public String getNameFromOID(OID oid)
                      throws Exception
Description copied from interface: Storage
Get the name of an object from its oid.

Specified by:
getNameFromOID in interface Storage
Parameters:
oid - the candidate object oid
Throws:
Exception

bindOIDToName

public void bindOIDToName(OID oid,
                          String name)
                   throws Exception
Description copied from interface: Storage
Bind an existing object to a logical name to that it can be found later on.

This method allows the user to create persistence roots.

Specified by:
bindOIDToName in interface Storage
Parameters:
oid - an existing object ID
name - the name that is given to it
Throws:
Exception

deleteName

public void deleteName(String name)
                throws Exception
Description copied from interface: Storage
Delete a name from the storage.

Specified by:
deleteName in interface Storage
Parameters:
name - the name to remove
Throws:
Exception

getClassID

public String getClassID(OID oid)
                  throws Exception
Description copied from interface: Storage
Get the class ID of a given object.

Specified by:
getClassID in interface Storage
Parameters:
oid - the object's class ID
Throws:
Exception - if an error occurs

getRootObjects

public Collection getRootObjects()
                          throws Exception
Description copied from interface: Storage
Get OIDs of all root objects.

Specified by:
getRootObjects in interface Storage
Returns:
the root objects
Throws:
Exception - if an error occurs

getObjects

public Collection getObjects(ClassItem cl)
                      throws Exception
Description copied from interface: Storage
Get all instances of a class, or all objects if cl == null.

Specified by:
getObjects in interface Storage
Parameters:
cl - the class
Returns:
the instances
Throws:
Exception

getObjects

protected void getObjects(ClassItem cl,
                          Vector objects)
                   throws Exception
Gets all instances of a class and its subclasses.

Parameters:
cl - the class
objects - instances of the class are added to this collection
Throws:
Exception

startTransaction

public void startTransaction()
Description copied from interface: Storage
Starts a transaction

Specified by:
startTransaction in interface Storage

commit

public void commit()
Description copied from interface: Storage
Commit started transaction

Specified by:
commit in interface Storage

rollback

public void rollback()
Description copied from interface: Storage
Rollback started transaction

Specified by:
rollback in interface Storage

getPrintWriter

protected PrintWriter getPrintWriter(OID oid,
                                     boolean append,
                                     boolean autoFlush)
                              throws IOException
Throws:
IOException

getPrintWriter

protected PrintWriter getPrintWriter(File file,
                                     boolean append,
                                     boolean autoFlush)
                              throws IOException
Throws:
IOException

getPrintWriter

protected PrintWriter getPrintWriter(OutputStream stream,
                                     boolean autoFlush)
                              throws IOException
Throws:
IOException

getWriter

protected Writer getWriter(File file,
                           boolean append)
                    throws IOException
Throws:
IOException