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:
ICloseable, ICachedStorage, IStorage, INamedObject
Direct Known Subclasses:
MemDataBookStorage

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.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.sibvisions.rad.persist.AbstractStorage
AbstractStorage.AllFetchedList<E>
 
Constructor Summary
  AbstractMemStorage()
          Creates a new instance of AbstractMemStorage.
protected AbstractMemStorage(MemDataBook pDataBook)
          Creates a new instance of AbstractMemStorage with an external data book.
 
Method Summary
 void close()
          Closes the storage.
protected  BeanType createBeanType(java.lang.String[] pColumnNames)
          Creates a BeanType for the given column names.
protected  ColumnMetaData createColumnMetaData(ColumnDefinition pColumnDefinition)
          It returns the ColumnMetaData to the corresponding ColumnDefinition.
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 doValidate(DataBookEvent pEvent)
          Validates the current record with metadata restrictions.
protected  void executeDelete(java.lang.Object[] pDeleteDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the delete method.
protected  void executeDeleteAsBean(java.lang.Object[] pDeleteDataRow)
          This method will be used if AbstractStorage.delete(Object) was called.
protected  java.util.List<java.lang.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.
protected  java.util.List<java.lang.Object[]> executeFetchAsBean(ICondition pFilter, SortDefinition pSort, int pFromRow, int pMinimumRowCount)
          This method will be used if AbstractStorage.fetchBean(ICondition, SortDefinition, int, int) was called.
protected  java.lang.Object[] executeInsert(java.lang.Object[] pDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the insert method.
protected  java.lang.Object[] executeInsertAsBean(java.lang.Object[] pDataRow)
          This method will be used if AbstractStorage.insert(Object) was called.
protected  java.lang.Object[] executeRefetchRow(java.lang.Object[] pDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the refetchRow method.
protected  java.lang.Object[] executeRefetchRow(java.lang.String[] pQueryColumns, java.lang.Object[] pDataRow)
          Refetches data.
protected  java.lang.Object[] executeRefetchRowAsBean(java.lang.Object[] pDataRow)
          This method will be used if AbstractStorage.refetch(Object) was called.
protected  java.lang.Object[] executeUpdate(java.lang.Object[] pOldDataRow, java.lang.Object[] pNewDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the update method.
protected  java.lang.Object[] executeUpdateAsBean(java.lang.Object[] pOldDataRow, java.lang.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.
 MetaData getMetaData()
          Returns the meta data for this AbstractStorage from the storage as MetaData.
 int getRowCount()
          Gets the row count.
abstract  RowDefinition getRowDefinition()
          Returns the row definition for the internal MemDataBook.
protected  ColumnMetaData initializeColumnMetaData(ColumnDefinition pColumnDefinition, ColumnMetaData pColumnMetaData)
          This initializes the ColumnMetaData with the given corresponding ColumnDefinition.
protected  ColumnMetaData initializeDataType(ColumnDefinition pColumnDefinition, ColumnMetaData pColumnMetaData)
          This initializes the column meta data with the data of the data type IDataType.
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.
 void setDispatchEventsEnabled(boolean pEnabled)
          Sets event dispatching en-/disabled for "before" events.
abstract  void update(DataBookEvent pEvent)
          Updates an existing row.
protected  void validateWithMetaData()
          Validates all columns.
protected  void validateWithMetaData(java.lang.String[] pColumns, java.lang.Object[] pValues)
          Validates the given row with the meta data.
 void writeCSV(java.io.OutputStream pStream, java.lang.String[] pColumnNames, java.lang.String[] pLabels, ICondition pFilter, SortDefinition pSort, java.lang.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, getMetaDataCacheGroups, 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, eventInsteadOfDelete, eventInsteadOfInsert, eventInsteadOfUpdate, fetch, fetch, fetch, fetchBean, fetchBean, getAndInitBeanType, getBeanConverter, getName, getPropertyNameForColumn, hasInsteadOfDeleteEventHandler, hasInsteadOfInsertEventHandler, hasInsteadOfUpdateEventHandler, info, insert, insert, isLogEnabled, isRefetch, refetch, refetchRow, setName, setPropertyNameForColumn, setRefetch, update, update, update
 
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, insert, refetchRow, update
 

Constructor Detail

AbstractMemStorage

protected AbstractMemStorage(MemDataBook pDataBook)
Creates a new instance of AbstractMemStorage with an external data book.

Parameters:
pDataBook - the data book

AbstractMemStorage

public AbstractMemStorage()
Creates a new instance of AbstractMemStorage.

Method Detail

writeCSV

public void writeCSV(java.io.OutputStream pStream,
                     java.lang.String[] pColumnNames,
                     java.lang.String[] pLabels,
                     ICondition pFilter,
                     SortDefinition pSort,
                     java.lang.String pSeparator)
              throws java.lang.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:
java.lang.Exception - if the CSV output couldn't written to stream

getMetaData

@Accessible
public final MetaData getMetaData()
                           throws DataSourceException
Returns the meta data for this AbstractStorage from the storage as MetaData.

Returns:
the meta data for this AbstractStorage from the storage as MetaData.
Throws:
DataSourceException - if an Exception occur during getting the meta data from the storage.

executeFetch

protected final java.util.List<java.lang.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

protected final java.util.List<java.lang.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

protected final java.lang.Object[] executeRefetchRow(java.lang.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

protected final java.lang.Object[] executeRefetchRowAsBean(java.lang.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

protected final java.lang.Object[] executeInsert(java.lang.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. null if no insert operation was performed.
Throws:
DataSourceException - if an Exception occur during insert the row to the storage
See Also:
IStorage.insert(Object[])

executeInsertAsBean

protected final java.lang.Object[] executeInsertAsBean(java.lang.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

protected final java.lang.Object[] executeUpdate(java.lang.Object[] pOldDataRow,
                                                 java.lang.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[]. null if no update operation was performed.
Throws:
DataSourceException - if an Exception occur during updating the row.
See Also:
IStorage.update(Object[], Object[])

executeUpdateAsBean

protected final java.lang.Object[] executeUpdateAsBean(java.lang.Object[] pOldDataRow,
                                                       java.lang.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

protected final void executeDelete(java.lang.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

protected void executeDeleteAsBean(java.lang.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 before 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 before 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 before deleted an existing row.

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

finalize

public void finalize()
              throws java.lang.Throwable

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

createBeanType

protected BeanType createBeanType(java.lang.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

createColumnMetaData

protected ColumnMetaData createColumnMetaData(ColumnDefinition pColumnDefinition)
It returns the ColumnMetaData to the corresponding ColumnDefinition.

Parameters:
pColumnDefinition - the ColumnDefinition to use.
Returns:
the ColumnMetaData to the corresponding ColumnDefinition.

initializeColumnMetaData

protected ColumnMetaData initializeColumnMetaData(ColumnDefinition pColumnDefinition,
                                                  ColumnMetaData pColumnMetaData)
This initializes the ColumnMetaData with the given corresponding ColumnDefinition.

Parameters:
pColumnDefinition - the ColumnDefinition to use.
pColumnMetaData - the ColumnMetaData.
Returns:
ColumnMetaData the result column metadata

initializeDataType

protected ColumnMetaData initializeDataType(ColumnDefinition pColumnDefinition,
                                            ColumnMetaData pColumnMetaData)
This initializes the column meta data with the data of the data type IDataType.

Parameters:
pColumnDefinition - the ColumnDefinition to use.
pColumnMetaData - the ColumnMetaData.
Returns:
ColumnMetaData the result column metadata

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

protected final java.lang.Object[] executeRefetchRow(java.lang.String[] pQueryColumns,
                                                     java.lang.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

doValidate

public void doValidate(DataBookEvent pEvent)
                throws ModelException
Validates the current record with metadata restrictions.

Parameters:
pEvent - the data book event
Throws:
ModelException - if validation fails

validateWithMetaData

protected void validateWithMetaData()
                             throws ModelException
Validates all columns.

Throws:
ModelException - if validation fails
See Also:
validateWithMetaData(String[], Object[])

validateWithMetaData

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

Parameters:
pColumns - the columns to check
pValues - the column array ordered in the visible columns order
Throws:
ModelException - if 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

setDispatchEventsEnabled

public void setDispatchEventsEnabled(boolean pEnabled)
Sets event dispatching en-/disabled for "before" events. Be careful with this method, because disabled event dispatching will stop storage from working properly.

Parameters:
pEnabled - true to enable event dispatching, false to disable it


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.