com.sibvisions.rad.persist
Class AbstractMemStorage

java.lang.Object
  extended by com.sibvisions.rad.persist.AbstractStorage
      extended by com.sibvisions.rad.persist.AbstractCachedStorage
          extended by com.sibvisions.rad.persist.AbstractMemStorage
All Implemented Interfaces:
ICachedStorage, IStorage, INamedObject

public abstract class AbstractMemStorage
extends AbstractCachedStorage

The AbstractMemStorage is an AbstractCachedStorage and holds an internal MemDataBook for the data. It implements all methods which are necessary that the client is able to receive data. All data manipulation methods like insert/update/delete are abstract and have to be implemented.


Constructor Summary
AbstractMemStorage()
          Creates a new instance of AbstractMemStorage.
 
Method Summary
 void close()
          Closes the storage.
protected  BeanType createBeanType(String[] pColumnNames)
          Creates a BeanType for the given column names.
abstract  void delete(DataBookEvent pEvent)
          Deletes an existing row.
 void doDelete(DataBookEvent pEvent)
          The delete notification method from the data book.
 void doInsert(DataBookEvent pEvent)
          The insert notification method from the data book.
 void doUpdate(DataBookEvent pEvent)
          The update notification method from the data book.
 void executeDelete(Object[] pDeleteDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the delete method.
 void executeDeleteAsBean(Object[] pDeleteDataRow)
          This method will be used if AbstractStorage.delete(Object) was called.
 List<Object[]> executeFetch(ICondition pFilter, SortDefinition pSort, int pFromRow, int pMinimumRowCount)
          This method has to be implemented in the Storage implementation and should have the functionality of the fetch method.
 List<Object[]> executeFetchAsBean(ICondition pFilter, SortDefinition pSort, int pFromRow, int pMinimumRowCount)
          This method will be used if AbstractStorage.fetchBean(ICondition, SortDefinition, int, int) was called.
 MetaData executeGetMetaData()
          This method has to be implemented in the Storage implementation and should have the functionality of the getMetaData method.
 Object[] executeInsert(Object[] pDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the insert method.
 Object[] executeInsertAsBean(Object[] pDataRow)
          This method will be used if AbstractStorage.insert(Object) was called.
 Object[] executeRefetchRow(Object[] pDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the refetchRow method.
 Object[] executeRefetchRow(String[] pQueryColumns, Object[] pDataRow)
          Refetches data.
 Object[] executeRefetchRowAsBean(Object[] pDataRow)
          This method will be used if AbstractStorage.refetch(Object) was called.
 Object[] executeUpdate(Object[] pOldDataRow, Object[] pNewDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the update method.
 Object[] executeUpdateAsBean(Object[] pOldDataRow, Object[] pNewDataRow)
          This method will be used if AbstractStorage.update(Object) was called.
 void finalize()
          
 MemDataBook getDataBook()
          Gets the internal MemDataBook.
 SortDefinition getDefaultSort()
          Gets the default sort definition.
 int getEstimatedRowCount(ICondition pFilter)
          Returns the number of rows in this AbstractStorage from the storage.
 int getRowCount()
          Gets the row count.
abstract  RowDefinition getRowDefinition()
          Returns the row definition for the internal MemDataBook.
abstract  void insert(DataBookEvent pEvent)
          Inserts a new row.
 boolean isOpen()
          Returns whether the storage is open and ready to use.
abstract  void loadData(MemDataBook pBook, ICondition pFilter)
          Loads the relevant data into the internal data book.
 void open()
          Opens the storage.
 void setDefaultSort(SortDefinition pSort)
          Sets the default sort definition.
abstract  void update(DataBookEvent pEvent)
          Updates an existing row.
protected  void validateWithMetaData(String[] pQueryColumns, Object[] pRow)
          Validates the given row with the meta data.
 void writeCSV(OutputStream pStream, String[] pColumnNames, String[] pLabels, ICondition pFilter, SortDefinition pSort, String pSeparator)
          Write the current storage with the specified filter and sort into the given output stream as CSV Format.
 
Methods inherited from class com.sibvisions.rad.persist.AbstractCachedStorage
clearMetaData, clearMetaData, getMetaData, getMetaData, getMetaDataCacheOption, getMetaDataFromCache, getMetaDataFromCache, isGlobalMetaDataCacheEnabled, isMetaDataCacheEnabled, putMetaDataToCache, removeMetaData, setGlobalMetaDataCacheEnabled, setMetaDataCacheOption
 
Methods inherited from class com.sibvisions.rad.persist.AbstractStorage
createBean, createCSV, createCSV, createCSV, createEmptyBean, createPOJO, createPOJO, debug, delete, delete, error, eventAfterDelete, eventAfterInsert, eventAfterUpdate, eventBeforeDelete, eventBeforeInsert, eventBeforeUpdate, eventCalculateRow, fetch, fetch, fetch, fetchBean, fetchBean, getAndInitBeanType, getMetaData, getName, info, insert, insert, refetch, refetchRow, setName, setPropertyNameForColumn, update, update, updateBean
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.rad.persist.IStorage
delete, fetch, getMetaData, insert, refetchRow, update
 

Constructor Detail

AbstractMemStorage

public AbstractMemStorage()
Creates a new instance of AbstractMemStorage.

Method Detail

writeCSV

public void writeCSV(OutputStream pStream,
                     String[] pColumnNames,
                     String[] pLabels,
                     ICondition pFilter,
                     SortDefinition pSort,
                     String pSeparator)
              throws Exception
Write the current storage with the specified filter and sort into the given output stream as CSV Format.

Specified by:
writeCSV in class AbstractStorage
Parameters:
pStream - the output stream to use for the CSV stream
pColumnNames - the column names to include in the export
pLabels - the labels to show as header in the export
pFilter - the condition
pSort - the sort definition
pSeparator - the column separator
Throws:
Exception - if the CSV output couldn't written to stream

executeGetMetaData

public final MetaData executeGetMetaData()
                                  throws DataSourceException
This method has to be implemented in the Storage implementation and should have the functionality of the getMetaData method.

Specified by:
executeGetMetaData in class AbstractStorage
Returns:
the MetaData
Throws:
DataSourceException - if an Exception occur during getting the meta data from the storage
See Also:
IStorage.getMetaData()

executeFetch

public final List<Object[]> executeFetch(ICondition pFilter,
                                         SortDefinition pSort,
                                         int pFromRow,
                                         int pMinimumRowCount)
                                  throws DataSourceException
This method has to be implemented in the Storage implementation and should have the functionality of the fetch method.

Specified by:
executeFetch in class AbstractStorage
Parameters:
pFilter - the ICondition to use.
pSort - the SortDefinition to use.
pFromRow - the from row index to request from storage.
pMinimumRowCount - the minimum row count to request, beginning from the pFromRow.
Returns:
the requested rows as List[Object[]].
Throws:
DataSourceException - if an Exception occur during interacting with the storage.
See Also:
IStorage.fetch(ICondition, SortDefinition, int, int)

executeFetchAsBean

public final List<Object[]> executeFetchAsBean(ICondition pFilter,
                                               SortDefinition pSort,
                                               int pFromRow,
                                               int pMinimumRowCount)
                                        throws DataSourceException
This method will be used if AbstractStorage.fetchBean(ICondition, SortDefinition, int, int) was called.

Overrides:
executeFetchAsBean in class AbstractStorage
Parameters:
pFilter - the ICondition to use.
pSort - the SortDefinition to use.
pFromRow - the from row index to request from storage.
pMinimumRowCount - the minimum row count to request, beginning from the pFromRow.
Returns:
the requested rows as List[Object[]].
Throws:
DataSourceException - if an Exception occur during interacting with the storage.
See Also:
IStorage.fetch(ICondition, SortDefinition, int, int)

executeRefetchRow

public final Object[] executeRefetchRow(Object[] pDataRow)
                                 throws DataSourceException
This method has to be implemented in the Storage implementation and should have the functionality of the refetchRow method.

Specified by:
executeRefetchRow in class AbstractStorage
Parameters:
pDataRow - the specified row as Object[].
Returns:
the refetched row as Object[].
Throws:
DataSourceException - if an Exception occur during interacting with the storage.
See Also:
IStorage.refetchRow(Object[])

executeRefetchRowAsBean

public final Object[] executeRefetchRowAsBean(Object[] pDataRow)
                                       throws DataSourceException
This method will be used if AbstractStorage.refetch(Object) was called.

Overrides:
executeRefetchRowAsBean in class AbstractStorage
Parameters:
pDataRow - the specified row as Object[].
Returns:
the refetched row as Object[].
Throws:
DataSourceException - if an Exception occur during interacting with the storage.
See Also:
IStorage.refetchRow(Object[])

executeInsert

public final Object[] executeInsert(Object[] pDataRow)
                             throws DataSourceException
This method has to be implemented in the Storage implementation and should have the functionality of the insert method.

Specified by:
executeInsert in class AbstractStorage
Parameters:
pDataRow - the new row as Object[] to insert.
Returns:
the newly inserted row from this IStorage.
Throws:
DataSourceException - if an Exception occur during insert the row to the storage
See Also:
IStorage.insert(Object[])

executeInsertAsBean

public final Object[] executeInsertAsBean(Object[] pDataRow)
                                   throws DataSourceException
This method will be used if AbstractStorage.insert(Object) was called.

Overrides:
executeInsertAsBean in class AbstractStorage
Parameters:
pDataRow - the new row as Object[] to insert.
Returns:
the newly inserted row from this IStorage.
Throws:
DataSourceException - if an Exception occur during insert the row to the storage
See Also:
IStorage.insert(Object[])

executeUpdate

public final Object[] executeUpdate(Object[] pOldDataRow,
                                    Object[] pNewDataRow)
                             throws DataSourceException
This method has to be implemented in the Storage implementation and should have the functionality of the update method.

Specified by:
executeUpdate in class AbstractStorage
Parameters:
pOldDataRow - the old row as Object[]
pNewDataRow - the new row as Object[] to update
Returns:
the updated row as Object[].
Throws:
DataSourceException - if an Exception occur during updating the row.
See Also:
IStorage.update(Object[], Object[])

executeUpdateAsBean

public final Object[] executeUpdateAsBean(Object[] pOldDataRow,
                                          Object[] pNewDataRow)
                                   throws DataSourceException
This method will be used if AbstractStorage.update(Object) was called.

Overrides:
executeUpdateAsBean in class AbstractStorage
Parameters:
pOldDataRow - the old row as Object[]
pNewDataRow - the new row as Object[] to update
Returns:
the updated row as Object[].
Throws:
DataSourceException - if an Exception occur during updating the row.
See Also:
IStorage.update(Object[], Object[])

executeDelete

public final void executeDelete(Object[] pDeleteDataRow)
                         throws DataSourceException
This method has to be implemented in the Storage implementation and should have the functionality of the delete method.

Specified by:
executeDelete in class AbstractStorage
Parameters:
pDeleteDataRow - the row as Object[] to delete.
Throws:
DataSourceException - if an Exception occur during deleting the row or if the storage isn't opened or the PrimaryKey is wrong and more/less then one row is deleted.
See Also:
IStorage.delete(Object[])

executeDeleteAsBean

public void executeDeleteAsBean(Object[] pDeleteDataRow)
                         throws DataSourceException
This method will be used if AbstractStorage.delete(Object) was called.

Overrides:
executeDeleteAsBean in class AbstractStorage
Parameters:
pDeleteDataRow - the row as Object[] to delete.
Throws:
DataSourceException - if an Exception occur during deleting the row or if the storage isn't opened or the PrimaryKey is wrong and more/less then one row is deleted.
See Also:
IStorage.delete(Object[])

getEstimatedRowCount

public int getEstimatedRowCount(ICondition pFilter)
                         throws DataSourceException
Returns the number of rows in this AbstractStorage from the storage.
It consider the specified ICondition to count the rows.

Parameters:
pFilter - the ICondition to use.
Returns:
the number of rows in this AbstractStorage from the storage.
Throws:
DataSourceException - if an Exception occur during interacting with the storage.

getRowDefinition

public abstract RowDefinition getRowDefinition()
                                        throws ModelException
Returns the row definition for the internal MemDataBook. The row definition will be used to create and cache the meta data. The ColumnView will be used to detect the column which will be used for meta data creation.

Returns:
the row definition
Throws:
ModelException - if the row definition can not be created

loadData

public abstract void loadData(MemDataBook pBook,
                              ICondition pFilter)
                       throws ModelException
Loads the relevant data into the internal data book. The data book is always the same and won't be deleted by this storage. This method is invoked when the client tries to fetch data.

Parameters:
pBook - the internal data book
pFilter - the filter
Throws:
ModelException - if an error occurs during filling

insert

public abstract void insert(DataBookEvent pEvent)
                     throws ModelException
Inserts a new row. Called bevore inserted a new row.

Parameters:
pEvent - the data book event
Throws:
ModelException - if an insert error occurs

update

public abstract void update(DataBookEvent pEvent)
                     throws ModelException
Updates an existing row. Called bevore updated an existing row.

Parameters:
pEvent - the data book event
Throws:
ModelException - if an update error occurs

delete

public abstract void delete(DataBookEvent pEvent)
                     throws ModelException
Deletes an existing row. Called bevore deleted an existing row.

Parameters:
pEvent - the data book event
Throws:
ModelException - if a delete error occurs

finalize

public void finalize()
              throws Throwable

Overrides:
finalize in class Object
Throws:
Throwable

createBeanType

protected BeanType createBeanType(String[] pColumnNames)
Creates a BeanType for the given column names.

Overrides:
createBeanType in class AbstractStorage
Parameters:
pColumnNames - the column names which are allowed for beans
Returns:
the bean type

open

public void open()
          throws DataSourceException
Opens the storage.

Throws:
DataSourceException - if the storage can not be opened

close

public void close()
Closes the storage.


isOpen

public boolean isOpen()
Returns whether the storage is open and ready to use.

Returns:
true if the storage is open, false otherwise

executeRefetchRow

public final Object[] executeRefetchRow(String[] pQueryColumns,
                                        Object[] pDataRow)
                                 throws DataSourceException
Refetches data.

Parameters:
pQueryColumns - the query columns
pDataRow - the old data
Returns:
the new data
Throws:
DataSourceException - if refetch fails

doInsert

public void doInsert(DataBookEvent pEvent)
              throws ModelException
The insert notification method from the data book. It ignores events which occured during loadData(MemDataBook, ICondition).

Parameters:
pEvent - the data book event
Throws:
ModelException - if an insert error occurs

doUpdate

public void doUpdate(DataBookEvent pEvent)
              throws ModelException
The update notification method from the data book. It ignores events which occured during loadData(MemDataBook, ICondition).

Parameters:
pEvent - the data book event
Throws:
ModelException - if an update error occurs

doDelete

public void doDelete(DataBookEvent pEvent)
              throws ModelException
The delete notification method from the data book. It ignores events which occured during loadData(MemDataBook, ICondition).

Parameters:
pEvent - the data book event
Throws:
ModelException - if a delete error occurs

validateWithMetaData

protected void validateWithMetaData(String[] pQueryColumns,
                                    Object[] pRow)
                             throws ModelException
Validates the given row with the meta data. The validation checks if all columns fulfill the meta data restrictions, like nullable.

Parameters:
pQueryColumns - the columns to check
pRow - the column array ordered in the visible columns order
Throws:
ModelException - if the validation fails

getDataBook

public MemDataBook getDataBook()
Gets the internal MemDataBook.

Returns:
the data book

setDefaultSort

public void setDefaultSort(SortDefinition pSort)
Sets the default sort definition. It will be used when no sort definition is defined through the client fetch call.

Parameters:
pSort - the default sort definition

getDefaultSort

public SortDefinition getDefaultSort()
Gets the default sort definition.

Returns:
the default sort definition
See Also:
setDefaultSort(SortDefinition)

getRowCount

public int getRowCount()
                throws ModelException
Gets the row count.

Returns:
the row count
Throws:
ModelException - if data access failed


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.