de.enough.polish.io
Class RmsStorage

java.lang.Object
  extended by de.enough.polish.io.RmsStorage
Type Parameters:
K - when you use the enough-polish-client-java5.jar you can parameterize the RmsStorage, e.g. RmsStorage<Vector<Note>>>.
All Implemented Interfaces:
Storage

public class RmsStorage
extends java.lang.Object
implements Storage

Stores serializable objects in the record store system.

Copyright Enough Software 2006 - 2008

 history
        13-Mar-2006 - rob creation
 

Author:
Robert Virkus, j2mepolish@enough.de, Begin Fabio (delete functions)

Constructor Summary
RmsStorage()
          Creates a new RmsStorage that uses different record stores for each stored object
RmsStorage(java.lang.String singleRecordStoreName)
          Creates a new RmsStorage that uses a single record store for several stored objects
 
Method Summary
 void delete(java.lang.String name)
          Delete the object with the given name.
 void deleteAll()
          Delete all record store to improve performance.
 java.util.Enumeration enumerate(java.lang.String name)
          Enumerates the objects that have been previously stored under the given name.
 java.lang.String getRecordLogicKey(int recordSetId)
          F.Beghin Retrieves the logic key by the record set ID
 int getRecordSetId(java.lang.String name)
          Retrieves the record set ID for the given name.
 int getSize()
          Retrieves the used size of the underlying record store
 int getSizeAvailable()
          Retrieves the available size of the underlying record store
 java.lang.String[] list()
          Retrieves a list of all entries that have been stored in this storage system.
 java.lang.Object read(java.lang.String name)
          Reads and de-serializes the given object which has been previously saved under the given name.
 void save(java.lang.Object object, java.lang.String name)
          Serializes the given object and stores is under the given name.
 void update(java.lang.Object object, java.lang.String newKey, java.lang.String oldKey)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RmsStorage

public RmsStorage()
Creates a new RmsStorage that uses different record stores for each stored object


RmsStorage

public RmsStorage(java.lang.String singleRecordStoreName)
           throws java.io.IOException
Creates a new RmsStorage that uses a single record store for several stored objects

Parameters:
singleRecordStoreName - the name of the record store, when one record store should be used for all entries - or null when for each name a new record store should be created.
Throws:
java.io.IOException - when the singleRecordStore is not null and the corresponding recordstore could not be opened or created.
Method Detail

getRecordSetId

public int getRecordSetId(java.lang.String name)
Retrieves the record set ID for the given name. This method can only be used when a master record store is used.

Parameters:
name - the name of the set
Returns:
either the set ID or -1 when the name is not yet used

getRecordLogicKey

public java.lang.String getRecordLogicKey(int recordSetId)
F.Beghin Retrieves the logic key by the record set ID

Parameters:
recordSetId - the ID of the set
Returns:
the name of the record set

save

public void save(java.lang.Object object,
                 java.lang.String name)
          throws java.io.IOException
Description copied from interface: Storage
Serializes the given object and stores is under the given name.

Specified by:
save in interface Storage
Parameters:
object - the object
name - the name under which the object should be stored
Throws:
java.io.IOException - when serializing or storage fails

update

public void update(java.lang.Object object,
                   java.lang.String newKey,
                   java.lang.String oldKey)
            throws java.io.IOException
Throws:
java.io.IOException

read

public java.lang.Object read(java.lang.String name)
                      throws java.io.IOException
Description copied from interface: Storage
Reads and de-serializes the given object which has been previously saved under the given name.

Specified by:
read in interface Storage
Parameters:
name - the name under which the object has been stored
Returns:
the initialized object
Throws:
java.io.IOException - when de-serializing or reading fails

enumerate

public java.util.Enumeration enumerate(java.lang.String name)
                                throws java.io.IOException
Description copied from interface: Storage
Enumerates the objects that have been previously stored under the given name.

Specified by:
enumerate in interface Storage
Parameters:
name - the name under which the objects have been stored
Returns:
an enumeration containing all objects
Throws:
java.io.IOException - when de-serializing or reading fails

list

public java.lang.String[] list()
                        throws java.io.IOException
Description copied from interface: Storage
Retrieves a list of all entries that have been stored in this storage system. WARNING: Not all storage implementations might support this.

Specified by:
list in interface Storage
Returns:
an array of names of stored objects.
Throws:
java.io.IOException - when the names could not be read

delete

public void delete(java.lang.String name)
            throws java.io.IOException
Description copied from interface: Storage
Delete the object with the given name.

Specified by:
delete in interface Storage
Parameters:
name - the name under which the object has been stored
Throws:
java.io.IOException - when deletion fails

deleteAll

public void deleteAll()
               throws java.io.IOException
Delete all record store to improve performance. This method should be used only with RmsStorage that uses a single record store for several stored objects

Throws:
java.io.IOException - when the operation fails

getSize

public int getSize()
Retrieves the used size of the underlying record store

Returns:
the used size (in bytes), -1 when an error occurred

getSizeAvailable

public int getSizeAvailable()
Retrieves the available size of the underlying record store

Returns:
the available size (in bytes), -1 when an error occurred