com.funambol.storage
Class ObjectStore

java.lang.Object
  extended by com.funambol.storage.ObjectStore
Direct Known Subclasses:
NonClosingObjectStore

public class ObjectStore
extends java.lang.Object

This class uses the J2ME RMS to store and retrieve objects using the rms positional access. To persist an object using ObjectStore, it must implement the com.funambol.storage.Serializable interface.


Field Summary
protected  java.lang.Object mutex
           
protected  java.lang.String name
           
protected  AbstractRecordStore rs
           
 
Constructor Summary
ObjectStore()
          Creates a new instance of ObjectStore.
ObjectStore(java.lang.String name)
          Creates a new instance of ObjectStore given the record store name.
 
Method Summary
 void addStoreListener(ObjectStoreListener listener)
          Add a RecordListener to the recordStore
 void close()
          Close the current RecordStore, if open.
 boolean create(java.lang.String name)
          Creates a new RecordStore, or open an existing one.
 int createEmptyRecord()
          Creates an empty record.
 int getAvaliableStorage()
          Returns the amount of additional room (in bytes) available for this record store to grow.
 int getFirstIndex()
          Get the first valid index in the record store.
 java.lang.String getName()
           
 int getNextIndex()
          Get the next valid index in the record store.
 java.util.Enumeration getObjects(Serializable s)
          Get all object of the ObjectStore
 boolean open()
          Open the current RecordStore, or throws an exception if not present.
 boolean open(java.lang.String name)
          Open an existing RecordStore, or throws an exception if not present.
protected  boolean openStore()
          private method used by open and create to share code.
protected  boolean openStore(java.lang.String name, boolean create)
          private method used by open and create to share code.
 void remove()
          Removes this object store.
 void remove(int index)
          Remove the object from the store.
 void removeObjectComparator()
          Set Comparator for this ObjectStore
 void removeObjectFilter()
          Remove Filter after usage
 void removeStoreListener(ObjectStoreListener listener)
          Add a RecordListener to the recordStore
 Serializable retrieve(int index, Serializable obj)
          Retrieve the serialize object from the record store.
 java.io.DataInputStream retrieveBytes(int index)
          Retrieve the DataInputStream corresponding to a record.
 void setObjectComparator(ObjectComparator newOc)
          Set Comparator for this ObjectStore
 void setObjectFilter(ObjectFilter newOf)
          Set Filter for this ObjectStore
 int size()
          Return the number of records in this ObjectStore
 int store(int index, Serializable obj)
          Store the serializable object in an existent record.
 int store(Serializable obj)
          Store the serializable object in a new record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rs

protected AbstractRecordStore rs

mutex

protected final java.lang.Object mutex

name

protected java.lang.String name
Constructor Detail

ObjectStore

public ObjectStore()
Creates a new instance of ObjectStore.


ObjectStore

public ObjectStore(java.lang.String name)
Creates a new instance of ObjectStore given the record store name.

Method Detail

getObjects

public java.util.Enumeration getObjects(Serializable s)
Get all object of the ObjectStore

Parameters:
s - Serializable Object to be returned
Returns:
Enumeration of Serializable object found

getName

public java.lang.String getName()
Returns:
Store name

open

public boolean open(java.lang.String name)
             throws javax.microedition.rms.RecordStoreException
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

open

public boolean open()
             throws javax.microedition.rms.RecordStoreException
Open the current RecordStore, or throws an exception if not present.

Returns:
true if the record store has been open or created false if it was cached
Throws:
javax.microedition.rms.RecordStoreException

create

public boolean create(java.lang.String name)
               throws javax.microedition.rms.RecordStoreException
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

openStore

protected boolean openStore(java.lang.String name,
                            boolean create)
                     throws javax.microedition.rms.RecordStoreException
private method used by open and create to share code.

Throws:
javax.microedition.rms.RecordStoreException

openStore

protected boolean openStore()
                     throws javax.microedition.rms.RecordStoreException
private method used by open and create to share code.

Throws:
javax.microedition.rms.RecordStoreException

close

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

Throws:
javax.microedition.rms.RecordStoreException

remove

public void remove()
            throws javax.microedition.rms.RecordStoreException
Removes this object store. The store is closed before trying to remove it.

Throws:
javax.microedition.rms.RecordStoreException

size

public int size()
Return the number of records in this ObjectStore

Returns:
the number of records present or -1 if the ObjectStore is not open.

getFirstIndex

public int getFirstIndex()
                  throws javax.microedition.rms.RecordStoreException
Get the first valid index in the record store.

Returns:
the first valid index in the record store, or -1 if empty.
Throws:
javax.microedition.rms.RecordStoreException

getNextIndex

public int getNextIndex()
                 throws javax.microedition.rms.RecordStoreException
Get the next valid index in the record store.

Returns:
the next valid index in the record store, or -1 if no more record are present.
Throws:
javax.microedition.rms.RecordStoreException

store

public int store(Serializable obj)
          throws javax.microedition.rms.RecordStoreException,
                 java.io.IOException
Store the serializable object in a new record.

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

createEmptyRecord

public int createEmptyRecord()
                      throws javax.microedition.rms.RecordStoreException,
                             java.io.IOException
Creates an empty record. Empty records are allowed by RMS as records with 0 lenght.

Returns:
the index in the recordstore
Throws:
javax.microedition.rms.RecordStoreException
java.io.IOException

store

public int store(int index,
                 Serializable obj)
          throws javax.microedition.rms.RecordStoreException,
                 java.io.IOException
Store the serializable object in an existent record.

Parameters:
obj - the serializable object
Returns:
the index in the recordstore
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 serialize object from the record store.

Parameters:
obj - the serializable object
index - the index in the recordstore
Returns:
a reference to the object, or null if the object is empty in the store.
Throws:
javax.microedition.rms.RecordStoreException - if the record is invalid
java.io.IOException - if the store is not accessible

retrieveBytes

public java.io.DataInputStream retrieveBytes(int index)
                                      throws javax.microedition.rms.RecordStoreException,
                                             java.io.IOException
Retrieve the DataInputStream corresponding to a record.

Parameters:
index - the index in the record store
Returns:
an input stream that allows the record content reading (maybe empty if the record id empty)
Throws:
javax.microedition.rms.RecordStoreException - if the record is invalid
java.io.IOException - if the store is not accessible

remove

public void remove(int index)
            throws javax.microedition.rms.RecordStoreException
Remove the object from the store.

Parameters:
index - the index in the recordstore
Throws:
javax.microedition.rms.RecordStoreException

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.

addStoreListener

public void addStoreListener(ObjectStoreListener listener)
Add a RecordListener to the recordStore


removeStoreListener

public void removeStoreListener(ObjectStoreListener listener)
Add a RecordListener to the recordStore


setObjectFilter

public void setObjectFilter(ObjectFilter newOf)
Set Filter for this ObjectStore


removeObjectFilter

public void removeObjectFilter()
Remove Filter after usage


setObjectComparator

public void setObjectComparator(ObjectComparator newOc)
Set Comparator for this ObjectStore


removeObjectComparator

public void removeObjectComparator()
Set Comparator for this ObjectStore



Copyright © 2001-2009 Funambol.