com.funambol.storage
Class NamedObjectStore

java.lang.Object
  extended by com.funambol.storage.NamedObjectStore

public class NamedObjectStore
extends java.lang.Object

This class uses the J2ME RMS to store and retrieve objects using a name. The first record of the record store is used to save the index. A recordstore managed by NamedObjectStore must be modified using this class methods only, or the index will be currupted. To persist an object using ObjectStore, it must implement the com.funambol.storage.Serializable interface.


Constructor Summary
NamedObjectStore()
          Creates a new instance of ObjectStore.
 
Method Summary
 void close()
          Close the current RecordStore, if open.
 boolean create(java.lang.String name)
          Creates a new RecordStore, or open an existing one.
 int getAvaliableStorage()
          Returns the amount of additional room (in bytes) available for this record store to grow.
 Serializable getFirstObject(Serializable obj)
          Retrieve the first serializable object from the record store.
 Serializable getNextObject(Serializable obj)
          Retrieve the next serializable object from the record store.
 int lookup(java.lang.String name)
          Search for a name in the record store, returning the object index
 java.lang.String[] names()
          Retrieve the list of names from the record store.
 boolean open(java.lang.String name)
          Open an existing RecordStore, or throws an exception if not present.
 boolean remove(java.lang.String name)
          Remove the object from the store.
 Serializable retrieve(int index, Serializable obj)
          Retrieve the serializable object from the record store, using a positional index.
 Serializable retrieve(java.lang.String name, Serializable obj)
          Retrieve the serializable object from the record store, using name to index it.
 int size()
          Returns the number of objects in the store.
 boolean store(java.lang.String name, Serializable obj)
          Store the serializable object in the ObjectStore, using the name hashcode to index it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamedObjectStore

public NamedObjectStore()
Creates a new instance of ObjectStore.

Method Detail

open

public boolean open(java.lang.String name)
             throws javax.microedition.rms.RecordStoreException,
                    java.io.IOException
Open an existing RecordStore, or throws an exception if not present. If the name is the same of the currently open one, no action is taken, otherwise the old one is closed.

Parameters:
name - is the name of the RecordStore to be managed
Returns:
true if the record store has been open or created false if it was cached
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

close

public void close()
           throws javax.microedition.rms.RecordStoreException
Close the current RecordStore, if open.

Throws:
javax.microedition.rms.RecordStoreException - if the ObjectStore was not open.

create

public boolean create(java.lang.String name)
               throws javax.microedition.rms.RecordStoreException,
                      java.io.IOException
Creates a new RecordStore, or open an existing one.

Parameters:
name - is the name of the RecordStore to be managed
Returns:
true if the record store has been open or created false if it was cached
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

store

public boolean store(java.lang.String name,
                     Serializable obj)
              throws javax.microedition.rms.RecordStoreException,
                     java.io.IOException
Store the serializable object in the ObjectStore, using the name hashcode to index it.

Parameters:
name - the name of the object
obj - the serializable object
Returns:
true if the record has been added by this call
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

retrieve

public Serializable retrieve(java.lang.String name,
                             Serializable obj)
                      throws javax.microedition.rms.RecordStoreException,
                             java.io.IOException
Retrieve the serializable object from the record store, using name to index it.

Parameters:
name - the name of the object
obj - the serializable object
Returns:
a reference to the object
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

retrieve

public Serializable retrieve(int index,
                             Serializable obj)
                      throws javax.microedition.rms.RecordStoreException,
                             java.io.IOException
Retrieve the serializable object from the record store, using a positional index.

Parameters:
index - the index in the recordstore.
obj - the serializable object
Returns:
a reference to the object
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

names

public java.lang.String[] names()
Retrieve the list of names from the record store. The order is not guaranteed.

Returns:
an array of String containing the names

lookup

public int lookup(java.lang.String name)
Search for a name in the record store, returning the object index

Parameters:
name - the name of the object
Returns:
the index in the record store, or 0 if not found

getFirstObject

public Serializable getFirstObject(Serializable obj)
                            throws javax.microedition.rms.RecordStoreException,
                                   java.io.IOException
Retrieve the first serializable object from the record store.

Parameters:
obj - the serializable object
Returns:
a reference to the object, or null if no objects found.
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

getNextObject

public Serializable getNextObject(Serializable obj)
                           throws javax.microedition.rms.RecordStoreException,
                                  java.io.IOException
Retrieve the next serializable object from the record store.

Parameters:
obj - the serializable object
Returns:
a reference to the object, or null if there are no more objects in the store
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

remove

public boolean remove(java.lang.String name)
               throws javax.microedition.rms.RecordStoreException,
                      java.io.IOException
Remove the object from the store.

Parameters:
name - the serializable object name
Returns:
true if the object has been removed, false if not found
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

size

public int size()
Returns the number of objects in the store.

Returns:
the number of objectss in the store, or -1 on error.

getAvaliableStorage

public int getAvaliableStorage()
Returns the amount of additional room (in bytes) available for this record store to grow.

Returns:
the amount of storage left for this store.


Copyright © 2001-2009 Funambol.