com.ados.hestia.utils.io
Class DBStore

java.lang.Object
  extended by com.ados.hestia.utils.io.DBStore
All Implemented Interfaces:
IStore, Serializable

public class DBStore
extends Object
implements IStore

This realize IStore interface using database to store data.

Version:
$Revision: 1371 $ $Date: 2005-11-22 02:44:08 +0900 $
See Also:
com.ados.hestia.db.Processor, Serialized Form

Field Summary
protected  DBStoreKey m_key
           
protected static HashMap<String,Processor> m_processors
          Store correlation beetween id and processor.
protected  String m_repositoryID
           
static int MEM_SWITCH_LIMIT
           
 
Constructor Summary
  DBStore(String repositoryID)
          Construct empty DBStore (data size is 0).
protected DBStore(String repositoryID, String storeID)
          Read Store description from DB.
  DBStore(String repositoryID, String storeID, InputStream stream)
          Construct DBStore.
 
Method Summary
 OutputStream createStream()
          Create output stream to write data.
protected  byte[] getContent()
          Read content of Store to memory.
 String getID()
          Returns id of store.
 Processor getProcessor()
          Returns processor that is responsible for database access.
Used repository identification to lookup at static map
 long getSize()
          Returns size of data at store.
protected  void initProxy(InputStream stream)
          Init stream that does not support mark.
 InputStream openSharedStream()
          Open shared stream to read data.
 InputStream openStream()
          Open ordinary stream to read data.
static void registerProcessor(String repositoryID, Processor processor)
          Staticly register processor to work.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MEM_SWITCH_LIMIT

public static final int MEM_SWITCH_LIMIT
See Also:
Constant Field Values

m_key

protected DBStoreKey m_key

m_repositoryID

protected String m_repositoryID

m_processors

protected static HashMap<String,Processor> m_processors
Store correlation beetween id and processor.

Constructor Detail

DBStore

public DBStore(String repositoryID)
        throws IOException
Construct empty DBStore (data size is 0).

Parameters:
repositoryID - identification of repository that owns this DBStore.
Throws:
IOException - if store cannot be allocated at database.

DBStore

public DBStore(String repositoryID,
               String storeID,
               InputStream stream)
        throws IOException
Construct DBStore. Used provided stream to fill data.

Parameters:
repositoryID - identification of repository that owns this DBStore.
storeID - store identification across repository.
stream - stream to fill initial content of DBStore.
Throws:
IOException - if stream cannot be read or store cannot be allocated.

DBStore

protected DBStore(String repositoryID,
                  String storeID)
           throws IOException
Read Store description from DB. Entry must be already present.

Parameters:
repositoryID - identification of repository that owns this DBStore.
storeID - store identification across repository. Must be present at database.
Throws:
IOException - if entry does not exist or cannot be read.
Method Detail

registerProcessor

public static void registerProcessor(String repositoryID,
                                     Processor processor)
Staticly register processor to work.

Parameters:
id - repository identification.
processor - processor corresponded Processor for repository.

getProcessor

public Processor getProcessor()
                       throws IOException
Returns processor that is responsible for database access.
Used repository identification to lookup at static map

Returns:
processor processor that is responsible for database access.
Throws:
IOException - if processor is not available for provided repository.

initProxy

protected void initProxy(InputStream stream)
                  throws IOException
Init stream that does not support mark. Need create temp store. SQL Standard requires (some db may ignore it but some required) set exact stream size for blob objects. In this way, readion to proxy storage is requied to get exact stream size.

Parameters:
stream - stream to fill content.
Throws:
IOException - if error with stream occured.

getID

public String getID()
Returns id of store.

Specified by:
getID in interface IStore
Returns:
id of store.

openStream

public InputStream openStream()
                       throws IOException
Open ordinary stream to read data.

Specified by:
openStream in interface IStore
Returns:
opened stream
Throws:
IOException - if stream can not be opened

getContent

protected byte[] getContent()
                     throws IOException,
                            ProcessorException
Read content of Store to memory. Note! use this method carefully because size of store data may be huge and will bring to memory error.

Returns:
content of Store as byte array/
Throws:
IOException - if data cannot be readed.
ProcessorException - if processor is not available or database access failed.

openSharedStream

public InputStream openSharedStream()
                             throws IOException
Open shared stream to read data.

Specified by:
openSharedStream in interface IStore
Returns:
opened shared stream
Throws:
IOException - if stream can not be opened

createStream

public OutputStream createStream()
                          throws IOException
Create output stream to write data.

Specified by:
createStream in interface IStore
Returns:
create opened stream
Throws:
IOException - if stream can not be opened

getSize

public long getSize()
Returns size of data at store.

Specified by:
getSize in interface IStore
Returns:
size of data at store


Copyright © 2005-2006 ADOS Co.,Ltd.. All Rights Reserved.