net.sf.jso.engine
Class JSOStorageManager

java.lang.Object
  extended byjava.rmi.server.RemoteObject
      extended byjava.rmi.server.RemoteServer
          extended byjava.rmi.server.UnicastRemoteObject
              extended bynet.sf.jso.engine.JSOStorageManager
All Implemented Interfaces:
java.util.EventListener, ManagerInfo, QueryProcessor, java.rmi.Remote, RemoteStorageManager, SchemaListener, java.io.Serializable, StatusListener, StorageListener, StorageManager, TransactionListener

public class JSOStorageManager
extends java.rmi.server.UnicastRemoteObject
implements StorageManager, RemoteStorageManager, ManagerInfo, TransactionListener

Manager responsible for storage operations with storable objects.

See Also:
Storable, Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
JSOStorageManager(java.util.Properties properties)
          Constructs the manager.
 
Method Summary
 void addStatusListener(StatusListener listener)
          Starts sending status events to a listener.
 void addStorageListener(StorageListener listener)
          Starts sending storage events to a listener.
 void batchStore(java.util.Collection objs, boolean deep)
          Stores a collection of objects in one only "batch" operation.
 void classAltered(SchemaEvent event)
          Called when a class in the schema is altered.
 void classDropped(SchemaEvent event)
          Called when a class in the schema is dropped.
 int count(Parameters params)
          Counts the number of objects according to parameters.
 int countPages(Parameters params)
          Counts the number of result pages according to parameters.
 OID createOID(java.lang.Object obj)
          Creates an OID from an object.
 void delete(java.lang.Object obj)
          Deletes an object.
 void delete(OID oid)
          Deletes an object.
 int delete(Parameters params)
          Deletes objects according to parameters.
protected  void finalize()
          Stops the manager.
 int getCacheLoad()
          Returns the number of cache slots in use.
 int getCacheSize()
          Returns cache's size.
 ManagerInfo getManagerInfo()
          Gets storage management information.
 OID getOID(java.lang.Object obj)
          Returns OID of a transient storable object.
 int getPoolCapacity()
          Returns the connection pool capacity.
 int getPoolLoad()
          Returns the number of pool's connections in use.
 Status getStatus()
          Gets manager's status.
 int getThreadCount()
          Returns the number of active threads.
 Transaction getTransaction()
          Gets the transaction associated to the current thread.
 int getTransactionCount()
          Returns the number of active transactions.
 void invalidateCache()
          Invalidates manager's cache.
 boolean isRemote()
          Indicates if manager is running on another JVM.
 void objectDeleted(StorageEvent event)
          Called when an object is deleted.
 void objectStored(StorageEvent event)
          Called when an object is stored.
 void removeStatusListener(StatusListener listener)
          Stops sending status events to a listener.
 void removeStorageListener(StorageListener listener)
          Stops sending storage events to a listener.
 java.lang.Object retrieve(OID oid)
          Retrieves an object.
 java.lang.Object retrieve(OID oid, boolean summary)
          Retrieves an object.
 java.lang.Object retrieve(OID oid, boolean summary, boolean lazy)
          Retrieves an object.
 java.util.List retrieve(Parameters params)
          Retrieves objects according to parameters.
static void safellyStop(StorageManager aManager)
          Stops a storage manager without throwing any exceptions.
 void start(StorageController aController)
          Starts the manager.
 void statusChanged(StatusEvent event)
          Called when a status change occur.
 void stop()
          Stops the manager.
 OID store(java.lang.Object obj)
          Stores an object and referenced objects.
 OID store(java.lang.Object obj, boolean deep)
          Stores an object.
 void subclassCreated(SchemaEvent event)
          Called when a class in the schema is created and is subclass of another class.
 void subclassDropped(SchemaEvent event)
          Called when a class in the schema is dropped and is subclass of another class.
 void transactionBegun(TransactionEvent event)
          Called immediately after transaction beginning.
 void transactionCommit(TransactionEvent event)
          Called immediately before transaction commit.
 void transactionFinished(TransactionEvent event)
          Called immediately after transaction finish.
 void transactionRollback(TransactionEvent event)
          Called immediately before transaction rollback.
 void unlinkTransientObjects()
          Unlinks transient storable objects from stored ones.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JSOStorageManager

public JSOStorageManager(java.util.Properties properties)
                  throws java.rmi.RemoteException
Constructs the manager.

Parameters:
properties - Properties containing parameters to the manager. The following properties can be used:
Method Detail

start

public void start(StorageController aController)
           throws StorageException
Starts the manager.

Specified by:
start in interface StorageManager
Parameters:
aController - Application's controller.
Throws:
StorageException

stop

public void stop()
          throws StorageException
Stops the manager.

Specified by:
stop in interface StorageManager
Throws:
StorageException

safellyStop

public static void safellyStop(StorageManager aManager)
Stops a storage manager without throwing any exceptions.

Parameters:
aManager - Storage manager to be stopped.

store

public OID store(java.lang.Object obj)
          throws StorageException
Stores an object and referenced objects. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
store in interface StorageManager
Parameters:
obj - The object to be stored.
Returns:
The stored object identification.
Throws:
StorageException - If any storage operation fails.

store

public OID store(java.lang.Object obj,
                 boolean deep)
          throws StorageException
Stores an object. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
store in interface StorageManager
Parameters:
obj - The object to be stored.
deep - Indicates if referenced objects should also be stored.
Returns:
The stored object identification.
Throws:
StorageException - If any storage operation fails.

batchStore

public void batchStore(java.util.Collection objs,
                       boolean deep)
                throws StorageException
Stores a collection of objects in one only "batch" operation. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
batchStore in interface StorageManager
Parameters:
objs - The collection of object to be stored.
deep - Indicates if referenced objects should also be stored.
Throws:
StorageException - If any storage operation fails.

retrieve

public java.lang.Object retrieve(OID oid)
                          throws StorageException
Retrieves an object. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
retrieve in interface StorageManager
Parameters:
oid - The identification of object to be stored.
Returns:
The stored object.
Throws:
StorageException - If any storage operation fails.

retrieve

public java.lang.Object retrieve(OID oid,
                                 boolean summary)
                          throws StorageException
Retrieves an object. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
retrieve in interface StorageManager
Parameters:
oid - The identification of object to be stored.
summary - Indicates if only summary fields should be retrieved.
Returns:
The stored object.
Throws:
StorageException - If any storage operation fails.

retrieve

public java.lang.Object retrieve(OID oid,
                                 boolean summary,
                                 boolean lazy)
                          throws StorageException
Retrieves an object. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
retrieve in interface StorageManager
Parameters:
oid - The identification of object to be stored.
summary - Indicates if only summary fields should be retrieved.
lazy - Indicates if referenced objects should be lazy loaded.
Returns:
The stored object.
Throws:
StorageException - If any storage operation fails.

delete

public void delete(java.lang.Object obj)
            throws StorageException
Deletes an object. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
delete in interface StorageManager
Parameters:
obj - The object to be deleted.
Throws:
StorageException - If any storage operation fails.

delete

public void delete(OID oid)
            throws StorageException
Deletes an object. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
delete in interface StorageManager
Parameters:
oid - The identification of object to be deleted.
Throws:
StorageException - If any storage operation fails.

delete

public int delete(Parameters params)
           throws StorageException
Deletes objects according to parameters. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
delete in interface StorageManager
Parameters:
params - Parameters to be used.
Returns:
The number of objects deleted.
Throws:
StorageException - If any storage operation fails.

count

public int count(Parameters params)
          throws StorageException
Counts the number of objects according to parameters. Only variables and criteria are used from parameters. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
count in interface QueryProcessor
Parameters:
params - Parameters to be used.
Returns:
The number of objects that match supplied criteira.
Throws:
StorageException - If any storage operation fails.

countPages

public int countPages(Parameters params)
               throws StorageException
Counts the number of result pages according to parameters. Only variables, criteria and page size are used from parameters. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
countPages in interface QueryProcessor
Parameters:
params - Parameters to be used.
Returns:
The number of result pages that match supplied criteira according to supplied paging parameters. If supplied page size is lesser than 1 a negative count is returned.
Throws:
StorageException - If any storage operation fails.

retrieve

public java.util.List retrieve(Parameters params)
                        throws StorageException
Retrieves objects according to parameters. Current thread's transaction is used. If current thread has no transaction associated a new one is begun and committed.

Specified by:
retrieve in interface QueryProcessor
Parameters:
params - Parameters to be used.
Returns:
A list of objects that match supplied criteira, in supplied order and within supplied paging limits.
Throws:
StorageException - If any storage operation fails.

createOID

public OID createOID(java.lang.Object obj)
Creates an OID from an object.

Specified by:
createOID in interface StorageManager
Parameters:
obj - An OID representation. Usually a String or Number object.

getOID

public OID getOID(java.lang.Object obj)
           throws StorageException
Returns OID of a transient storable object.

Specified by:
getOID in interface StorageManager
Parameters:
obj - The object to be identified.
Returns:
Storable object's OID.
Throws:
StorageException

unlinkTransientObjects

public void unlinkTransientObjects()
Unlinks transient storable objects from stored ones.

Specified by:
unlinkTransientObjects in interface StorageManager

statusChanged

public void statusChanged(StatusEvent event)
Called when a status change occur.

Specified by:
statusChanged in interface StatusListener

getStatus

public Status getStatus()
Gets manager's status.

Specified by:
getStatus in interface StorageManager
Returns:
manager's current status.

isRemote

public boolean isRemote()
Indicates if manager is running on another JVM.

Specified by:
isRemote in interface StorageManager
Returns:
true if manager is running on another JVM; false otherwise.

addStatusListener

public void addStatusListener(StatusListener listener)
Starts sending status events to a listener.

Specified by:
addStatusListener in interface StorageManager
Parameters:
listener - Listener to receive status events.

removeStatusListener

public void removeStatusListener(StatusListener listener)
Stops sending status events to a listener.

Specified by:
removeStatusListener in interface StorageManager
Parameters:
listener - Listener to stop receiving status events.

objectStored

public void objectStored(StorageEvent event)
Called when an object is stored.

Specified by:
objectStored in interface StorageListener

objectDeleted

public void objectDeleted(StorageEvent event)
Called when an object is deleted.

Specified by:
objectDeleted in interface StorageListener

addStorageListener

public void addStorageListener(StorageListener listener)
Starts sending storage events to a listener.

Specified by:
addStorageListener in interface StorageManager
Parameters:
listener - Listener to receive storage events.

removeStorageListener

public void removeStorageListener(StorageListener listener)
Stops sending storage events to a listener.

Specified by:
removeStorageListener in interface StorageManager
Parameters:
listener - Listener to stop receiving storage events.

classAltered

public void classAltered(SchemaEvent event)
Called when a class in the schema is altered.

Specified by:
classAltered in interface SchemaListener

classDropped

public void classDropped(SchemaEvent event)
Called when a class in the schema is dropped.

Specified by:
classDropped in interface SchemaListener

subclassCreated

public void subclassCreated(SchemaEvent event)
Called when a class in the schema is created and is subclass of another class.

Specified by:
subclassCreated in interface SchemaListener

subclassDropped

public void subclassDropped(SchemaEvent event)
Called when a class in the schema is dropped and is subclass of another class.

Specified by:
subclassDropped in interface SchemaListener

getTransaction

public Transaction getTransaction()
                           throws StorageException
Gets the transaction associated to the current thread.

Specified by:
getTransaction in interface StorageManager
Returns:
If no transaction is currently associated to the current thread a new one is created and returned. Otherwise the associated transaction is returned.
Throws:
StorageException

transactionBegun

public void transactionBegun(TransactionEvent event)
Called immediately after transaction beginning.

Specified by:
transactionBegun in interface TransactionListener

transactionCommit

public void transactionCommit(TransactionEvent event)
Called immediately before transaction commit.

Specified by:
transactionCommit in interface TransactionListener

transactionRollback

public void transactionRollback(TransactionEvent event)
Called immediately before transaction rollback.

Specified by:
transactionRollback in interface TransactionListener

transactionFinished

public void transactionFinished(TransactionEvent event)
Called immediately after transaction finish.

Specified by:
transactionFinished in interface TransactionListener

invalidateCache

public void invalidateCache()
Invalidates manager's cache.

Specified by:
invalidateCache in interface StorageManager

getManagerInfo

public ManagerInfo getManagerInfo()
Gets storage management information.

Specified by:
getManagerInfo in interface StorageManager
Returns:
Information about storage management.

getThreadCount

public int getThreadCount()
Returns the number of active threads.

Specified by:
getThreadCount in interface ManagerInfo
Returns:
The number of active threads.

getTransactionCount

public int getTransactionCount()
Returns the number of active transactions.

Specified by:
getTransactionCount in interface ManagerInfo
Returns:
The number of active transactions.

getCacheSize

public int getCacheSize()
Returns cache's size.

Specified by:
getCacheSize in interface ManagerInfo
Returns:
Cache's size.

getCacheLoad

public int getCacheLoad()
Returns the number of cache slots in use.

Specified by:
getCacheLoad in interface ManagerInfo
Returns:
The number of cache slots in use.

getPoolCapacity

public int getPoolCapacity()
Returns the connection pool capacity.

Specified by:
getPoolCapacity in interface ManagerInfo
Returns:
The connection pool capacity.

getPoolLoad

public int getPoolLoad()
Returns the number of pool's connections in use.

Specified by:
getPoolLoad in interface ManagerInfo
Returns:
The number of pool's connections in use.

finalize

protected void finalize()
                 throws java.lang.Throwable
Stops the manager.

Throws:
java.lang.Throwable