goodsjpi
Class Database

java.lang.Object
  extended bygoodsjpi.Database

public class Database
extends java.lang.Object

Class representing GOODS database connection


Field Summary
protected  int allocBufSize
           
protected  CacheManager cacheManager
           
protected static java.util.Hashtable connections
           
protected  IdentityHashtable notifications
           
protected  CondEvent onTransactionAbortEvent
           
static int PER_PROCESS_TRANSACTION
          Transaction isolation levels.
static int PER_THREAD_TRANSACTION
           
static RawBinaryFactory rawBinaryFactory
          Factory of raw binary objects which is used to pack/unpack raw binary objects
protected  Storage[] storages
           
 
Constructor Summary
Database()
          Constructor of the database
 
Method Summary
protected  void abortTransaction()
           
 void attach()
          Attach current thread to the database.
 void attach(java.lang.Object obj, int sid)
          Associate persistent capable object with particular storage.
 void close()
          Close database connection
static void closeAll()
          Close all database active connections.
static void closeAllDead()
          Iterate through the listy of all active conenction and close ones associated with dead threads.
protected  Storage createStorage(Database db, int id)
          Create storage
 void detach()
          Detach current thread fro the database
protected  void disconnected(int sid)
          Handler of client server connection failure.
 CacheManager getCacheManager()
          Get database cache manager.
static Database getDatabase(java.lang.String cfgFileName)
          Create or reuse existed connection from connection pool
 int getNumberOfStorages()
          Get number of storages in the database
 Persistent getObject(int storageId, int oid)
          Get object from the storage by OID
 Persistent getObject(java.lang.String oid)
          Parse oid into number and get that id from the first storage
 java.lang.Object getRoot()
          Get root object of the first storage in the database
 java.lang.Object getRoot(int sid)
          Get root of the specified storage
 long getSize(int sid)
          Get size of the database file of the storage
protected  void handleError(java.lang.String text)
          Error handler.
protected  void handleException(java.io.IOException x)
          Error handler.
 void notifyOnModification(java.lang.Object obj, CondEvent event)
          Register event to be signaled on object modification
 void notifyOnTransactionAbort(CondEvent event)
          Register event to be signaled when transaction is aborted by server
 boolean open(java.lang.String cfgFileName)
          Open the database
 void setAllocBufferSize(int size)
          Set buffer size for bulk alloc.
 void setIsolationLevel(int level)
          Set isoaltion level
 void setRoot(int sid, java.lang.Object root)
          Set root object for the specified storage in the database
 void setRoot(java.lang.Object root)
          Set root object for the first storage in the database
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

storages

protected Storage[] storages

notifications

protected IdentityHashtable notifications

cacheManager

protected CacheManager cacheManager

allocBufSize

protected int allocBufSize

rawBinaryFactory

public static RawBinaryFactory rawBinaryFactory
Factory of raw binary objects which is used to pack/unpack raw binary objects


onTransactionAbortEvent

protected CondEvent onTransactionAbortEvent

PER_PROCESS_TRANSACTION

public static final int PER_PROCESS_TRANSACTION
Transaction isolation levels.

See Also:
Constant Field Values

PER_THREAD_TRANSACTION

public static final int PER_THREAD_TRANSACTION
See Also:
Constant Field Values

connections

protected static java.util.Hashtable connections
Constructor Detail

Database

public Database()
Constructor of the database

Method Detail

attach

public void attach()
Attach current thread to the database. This method is used in per-thread-transaction model associate the current thread with cache manager


detach

public void detach()
Detach current thread fro the database


setIsolationLevel

public void setIsolationLevel(int level)
Set isoaltion level


getCacheManager

public CacheManager getCacheManager()
Get database cache manager. In per-thread transaction model each database has its own cache manager, providing isolation of the threads from each other. In cooperative model all databases share the same cache managers.


getDatabase

public static Database getDatabase(java.lang.String cfgFileName)
Create or reuse existed connection from connection pool


closeAll

public static void closeAll()
Close all database active connections.


closeAllDead

public static void closeAllDead()
Iterate through the listy of all active conenction and close ones associated with dead threads.


open

public boolean open(java.lang.String cfgFileName)
Open the database

Parameters:
cfgFileName - path to the configuration file

close

public void close()
Close database connection


getNumberOfStorages

public int getNumberOfStorages()
Get number of storages in the database


getRoot

public java.lang.Object getRoot()
Get root object of the first storage in the database


getRoot

public java.lang.Object getRoot(int sid)
Get root of the specified storage

Parameters:
sid - storage identifier

getSize

public long getSize(int sid)
Get size of the database file of the storage

Parameters:
sid - storage identifier

setRoot

public void setRoot(java.lang.Object root)
Set root object for the first storage in the database

Parameters:
root - root object

setRoot

public void setRoot(int sid,
                    java.lang.Object root)
Set root object for the specified storage in the database

Parameters:
sid - storage identifier
root - root object

attach

public void attach(java.lang.Object obj,
                   int sid)
Associate persistent capable object with particular storage. Object should not yet be persistent (not belongs to soe storage)

Parameters:
obj - persistent capable object
sid - storage identifier

setAllocBufferSize

public void setAllocBufferSize(int size)
Set buffer size for bulk alloc. Bulk alloc alllows to minimize number of messages sent o the server by preallocating several OIDs during one request.

Parameters:
size - bulk allocation buffer size

getObject

public Persistent getObject(java.lang.String oid)
Parse oid into number and get that id from the first storage


getObject

public Persistent getObject(int storageId,
                            int oid)
Get object from the storage by OID

Parameters:
storageId - storage
oid - object identifer
Returns:
fethed object or null if not found

notifyOnModification

public void notifyOnModification(java.lang.Object obj,
                                 CondEvent event)
Register event to be signaled on object modification

Parameters:
obj - inspected object
event - event which will be signalled when object is modified by some other client

notifyOnTransactionAbort

public void notifyOnTransactionAbort(CondEvent event)
Register event to be signaled when transaction is aborted by server


handleError

protected void handleError(java.lang.String text)
Error handler. Override this method in derived class to provide applciation specified error handling policy.

Parameters:
text - error message

handleException

protected void handleException(java.io.IOException x)
Error handler. Override this method in derived class to provide applciation specified error handling policy.

Parameters:
x - IOException

createStorage

protected Storage createStorage(Database db,
                                int id)
Create storage

Parameters:
db - database
id - storage idenrtifier
Returns:
created storage

disconnected

protected void disconnected(int sid)
Handler of client server connection failure. This method is called when connection with server is broken. Override this method in derived class to provide applciation specified error handling policy.

Parameters:
sid - storage identifier

abortTransaction

protected void abortTransaction()