com.sibvisions.rad.persist
Class AbstractStorage

java.lang.Object
  extended by com.sibvisions.rad.persist.AbstractStorage
All Implemented Interfaces:
IStorage, INamedObject
Direct Known Subclasses:
AbstractCachedStorage

public abstract class AbstractStorage
extends Object
implements IStorage, INamedObject

The AbstractStorage implements the server side triggers mechnism for different types of Storages. It is the abstract base class for storages which needs a trigger mechanism.


Constructor Summary
AbstractStorage()
           
 
Method Summary
protected  IBean createBean(Object[] pValues)
          Creates a bean with given values.
protected  BeanType createBeanType(String[] pColumnNames)
          Creates a BeanType for the given column names.
 IFileHandle createCSV(String[] pColumnNames, String[] pLabels, ICondition pFilter, SortDefinition pSort)
          Write the current DBStorage with the specified filter and sort to the export.csv file in CSV format and returns the file handle.
 IFileHandle createCSV(String[] pColumnNames, String[] pLabels, ICondition pFilter, SortDefinition pSort, String pLanguage)
          Write the current DBStorage with the specified filter and sort to the export.csv file in CSV format and returns the file handle.
 IFileHandle createCSV(String pFileName, String[] pColumnNames, String[] pLabels, ICondition pFilter, SortDefinition pSort)
          Write the current DBStorage with the specified filter and sort to the export.csv file in CSV format and returns the file handle.
 IBean createEmptyBean()
          Creates a new bean with all column names from the meta data.
<T> T
createPOJO(Class<T> pClass, IBean pBean)
          Creates a POJO from the tiven type and with the values from a bean.
protected
<T> T
createPOJO(Class<T> pClass, Object[] pValues)
          Creates a POJO from the given type and with given values.
protected  void debug(Object... pInfo)
          Logs debug information.
 void delete(Object[] pDeleteDataRow)
          Deletes the specified row from the storage.
<T> void
delete(T pObject)
          Deletes the specified bean/POJO from the storage.
protected  void error(Object... pInfo)
          Logs error information.
 StorageHandler eventAfterDelete()
          Gets the EventHandler for after delete event.
 StorageHandler eventAfterInsert()
          Gets the EventHandler for after insert event.
 StorageHandler eventAfterUpdate()
          Gets the EventHandler for after update event.
 StorageHandler eventBeforeDelete()
          Gets the EventHandler for before delete event.
 StorageHandler eventBeforeInsert()
          Gets the EventHandler for before insert event.
 StorageHandler eventBeforeUpdate()
          Gets the EventHandler for before update event.
 StorageHandler eventCalculateRow()
          Gets the EventHandler for calculate row event.
abstract  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 delete(Object) was called.
abstract  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 fetchBean(ICondition, SortDefinition, int, int) was called.
abstract  MetaData executeGetMetaData()
          This method has to be implemented in the Storage implementation and should have the functionality of the getMetaData method.
abstract  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 insert(Object) was called.
abstract  Object[] executeRefetchRow(Object[] pDataRow)
          This method has to be implemented in the Storage implementation and should have the functionality of the refetchRow method.
 Object[] executeRefetchRowAsBean(Object[] pDataRow)
          This method will be used if refetch(Object) was called.
abstract  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 update(Object) was called.
<T> T
fetch(Class<T> pClass, ICondition pFilter)
          Returns the requested bean/POJO from the storage.
<T> List<T>
fetch(Class<T> pClass, ICondition pFilter, SortDefinition pSort, int pFromRow, int pMinimumRowCount)
          Returns the requested list of beans/POJOs from the storage.
 List<Object[]> fetch(ICondition pFilter, SortDefinition pSort, int pFromRow, int pMinimumRowCount)
          Returns the requested rows as List[Object[]].
 IBean fetchBean(ICondition pFilter)
          Returns the requested bean from the storage.
 List<IBean> fetchBean(ICondition pFilter, SortDefinition pSort, int pFromRow, int pMinimumRowCount)
          Returns the requested list of beans from the storage.
protected  BeanType getAndInitBeanType()
          Gets the bean type based on the meta data.
 MetaData getMetaData()
          Returns the meta data for this AbstractStorage from the storage as MetaData.
 String getName()
          Gets the storage name.
protected  void info(Object... pInfo)
          Logs information.
 Object[] insert(Object[] pDataRow)
          Returns the newly inserted row for this IStorage.
<T> T
insert(T pObject)
          Inserts the new bean/POJO and returns a bean/POJO with current values from the storage.
<T> T
refetch(T pObject)
          Refetchs the specified bean/POJO and returns a bean/POJO with current values from the storage.
 Object[] refetchRow(Object[] pDataRow)
          It refetchs the specified row and returns it as Object[] from the storage.
 void setName(String pName)
          Sets the storage name.
 void setPropertyNameForColumn(String pColumnName, String pPropertyName)
          Sets the property name (Java standard) for a given column name.
 Object[] update(Object[] pOldDataRow, Object[] pNewDataRow)
          Return the updated row as Object[].
<T> T
update(T pObject)
          Updates a bean/POJO with the PrimaryKey columns and provides values.
 void updateBean(IBean pBean, Object pPOJO)
          Updates a bean with values from a POJO.
abstract  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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.rad.persist.IStorage
getEstimatedRowCount
 

Constructor Detail

AbstractStorage

public AbstractStorage()
Method Detail

getMetaData

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

Specified by:
getMetaData in interface IStorage
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.

fetch

public final List<Object[]> fetch(ICondition pFilter,
                                  SortDefinition pSort,
                                  int pFromRow,
                                  int pMinimumRowCount)
                           throws DataSourceException
Returns the requested rows as List[Object[]]. Optimization can also return more then the minimum row count. If possible all in a certain time.

Specified by:
fetch in interface IStorage
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.

refetchRow

public final Object[] refetchRow(Object[] pDataRow)
                          throws DataSourceException
It refetchs the specified row and returns it as Object[] from the storage.
Before the user starts editing in the GUI, the IDataRow in the storage should be locked for updates.

Specified by:
refetchRow in interface IStorage
Parameters:
pDataRow - the specified row as Object[].
Returns:
the refetched row as Object[].
Throws:
DataSourceException - if an Exception occur during interacting with the storage.

insert

public final Object[] insert(Object[] pDataRow)
                      throws DataSourceException
Returns the newly inserted row for this IStorage.

Specified by:
insert in interface IStorage
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

update

public final Object[] update(Object[] pOldDataRow,
                             Object[] pNewDataRow)
                      throws DataSourceException
Return the updated row as Object[].

Specified by:
update in interface IStorage
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.

delete

public final void delete(Object[] pDeleteDataRow)
                  throws DataSourceException
Deletes the specified row from the storage.

Specified by:
delete in interface IStorage
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.

writeCSV

public abstract 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.

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 abstract MetaData executeGetMetaData()
                                     throws DataSourceException
This method has to be implemented in the Storage implementation and should have the functionality of the getMetaData method.

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

executeRefetchRow

public abstract 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.

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[])

executeFetch

public abstract 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.

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)

executeInsert

public abstract 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.

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 abstract 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.

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 abstract 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.

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[])

setName

public void setName(String pName)
Sets the storage name.

Specified by:
setName in interface INamedObject
Parameters:
pName - the name

getName

public String getName()
Gets the storage name.

Specified by:
getName in interface INamedObject
Returns:
the name

debug

protected void debug(Object... pInfo)
Logs debug information.

Parameters:
pInfo - the debug information

info

protected void info(Object... pInfo)
Logs information.

Parameters:
pInfo - the information

error

protected void error(Object... pInfo)
Logs error information.

Parameters:
pInfo - the error information

createCSV

public IFileHandle createCSV(String[] pColumnNames,
                             String[] pLabels,
                             ICondition pFilter,
                             SortDefinition pSort)
                      throws Exception
Write the current DBStorage with the specified filter and sort to the export.csv file in CSV format and returns the file handle. The filename will be built depending of the object name from the SessionContext.

Parameters:
pColumnNames - the column names to include in the export
pLabels - the labels to show as header in the export
pFilter - the filter to use on the DBStorage
pSort - the sort to use
Returns:
the file handle for the new generated CSV file.
Throws:
Exception - if the CSV output couldn't written to stream.

createCSV

public IFileHandle createCSV(String[] pColumnNames,
                             String[] pLabels,
                             ICondition pFilter,
                             SortDefinition pSort,
                             String pLanguage)
                      throws Exception
Write the current DBStorage with the specified filter and sort to the export.csv file in CSV format and returns the file handle. The filename will be built depending of the object name from the SessionContext.

Parameters:
pColumnNames - the column names to include in the export
pLabels - the labels to show as header in the export
pFilter - the filter to use on the DBStorage
pSort - the sort to use
pLanguage - the language to use
Returns:
the file handle for the new generated CSV file.
Throws:
Exception - if the CSV output couldn't written to stream.

createCSV

public IFileHandle createCSV(String pFileName,
                             String[] pColumnNames,
                             String[] pLabels,
                             ICondition pFilter,
                             SortDefinition pSort)
                      throws Exception
Write the current DBStorage with the specified filter and sort to the export.csv file in CSV format and returns the file handle.

Parameters:
pFileName - the filename to use.
pColumnNames - the column names to include in the export
pLabels - the labels to show as header in the export
pFilter - the filter to use on the DBStorage
pSort - the sort to use
Returns:
the file handle for the new generated CSV file.
Throws:
Exception - if the CSV output couldn't written to stream.

eventCalculateRow

public StorageHandler eventCalculateRow()
Gets the EventHandler for calculate row event. This is called after fetch, refetchRow, insert and update method calls.

Returns:
the EventHandler for after deleted event.

eventBeforeInsert

public StorageHandler eventBeforeInsert()
Gets the EventHandler for before insert event.

Returns:
the EventHandler for before insert event.

eventAfterInsert

public StorageHandler eventAfterInsert()
Gets the EventHandler for after insert event.

Returns:
the EventHandler for after insert event.

eventBeforeUpdate

public StorageHandler eventBeforeUpdate()
Gets the EventHandler for before update event.

Returns:
the EventHandler for before update event.

eventAfterUpdate

public StorageHandler eventAfterUpdate()
Gets the EventHandler for after update event.

Returns:
the EventHandler for after update event.

eventBeforeDelete

public StorageHandler eventBeforeDelete()
Gets the EventHandler for before delete event.

Returns:
the EventHandler for before delete event.

eventAfterDelete

public StorageHandler eventAfterDelete()
Gets the EventHandler for after delete event.

Returns:
the EventHandler for after delete event.

getAndInitBeanType

protected BeanType getAndInitBeanType()
                               throws DataSourceException
Gets the bean type based on the meta data.

Returns:
the bean type
Throws:
DataSourceException - if an Exception occurs during interacting with the storage

createBeanType

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

Parameters:
pColumnNames - the column names which are allowed for beans
Returns:
the bean type

createEmptyBean

public IBean createEmptyBean()
                      throws DataSourceException
Creates a new bean with all column names from the meta data. Only this column names are allowed.

Returns:
a new instance of an IBean implementation
Throws:
DataSourceException - if an Exception occurs during interacting with the storage

createBean

protected IBean createBean(Object[] pValues)
                    throws DataSourceException
Creates a bean with given values. The bean contains the property names from the column meta data and not more.

Parameters:
pValues - the values in same order as the meta data
Returns:
a new bean
Throws:
DataSourceException - if an Exception occurs during interacting with the storage

createPOJO

protected <T> T createPOJO(Class<T> pClass,
                           Object[] pValues)
                throws DataSourceException
Creates a POJO from the given type and with given values.

Type Parameters:
T - the type of the POJO
Parameters:
pClass - the class of the POJO
pValues - the values for the properties in the same order as the meta data
Returns:
the POJO
Throws:
DataSourceException - if an Exception occurs during interacting with the storage

createPOJO

public <T> T createPOJO(Class<T> pClass,
                        IBean pBean)
             throws DataSourceException
Creates a POJO from the tiven type and with the values from a bean.

Type Parameters:
T - the type of the POJO
Parameters:
pClass - the class of the POJO
pBean - the bean with values for the POJO
Returns:
the POJO
Throws:
DataSourceException - if an Exception occurs during interacting with the storage

updateBean

public void updateBean(IBean pBean,
                       Object pPOJO)
                throws DataSourceException
Updates a bean with values from a POJO. Only values from known properties will be updated. The property names from the meta data will be used.

Parameters:
pBean - the bean
pPOJO - the POJO
Throws:
DataSourceException - if an Exception occurs during interacting with the storage

setPropertyNameForColumn

public void setPropertyNameForColumn(String pColumnName,
                                     String pPropertyName)
                              throws DataSourceException
Sets the property name (Java standard) for a given column name. The name will be used for synchronizing POJOs with beans.

Parameters:
pColumnName - the column name
pPropertyName - the java property name e.g. firstName instead of FIRST_NAME
Throws:
DataSourceException - if meta data access failed

fetchBean

public IBean fetchBean(ICondition pFilter)
                throws DataSourceException
Returns the requested bean from the storage.

Parameters:
pFilter - the filter as ICondition to get exactly one Bean.
Returns:
the requested rows as IBeans, or null if no row was found
Throws:
DataSourceException - if an Exception occurs during interacting with the storage or more than one Bean were found

fetch

public <T> T fetch(Class<T> pClass,
                   ICondition pFilter)
        throws DataSourceException
Returns the requested bean/POJO from the storage.

Type Parameters:
T - the type of the POJO or bean.
Parameters:
pClass - the class of the POJO or bean.
pFilter - the filter as ICondition to use get exactly one Bean.
Returns:
the requested Bean/POJO, or null if no Bean/POJO was found
Throws:
DataSourceException - if an Exception occur during interacting with the storage or more than one Bean/POJO were found

fetchBean

public List<IBean> fetchBean(ICondition pFilter,
                             SortDefinition pSort,
                             int pFromRow,
                             int pMinimumRowCount)
                      throws DataSourceException
Returns the requested list of beans from the storage. It uses the filter to reduce the result, and the sort for the order.

Parameters:
pFilter - the filter as 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 list of Beans from the storage.
Throws:
DataSourceException - if an Exception occur during interacting with the storage.

fetch

public <T> List<T> fetch(Class<T> pClass,
                         ICondition pFilter,
                         SortDefinition pSort,
                         int pFromRow,
                         int pMinimumRowCount)
              throws DataSourceException
Returns the requested list of beans/POJOs from the storage. It uses the filter to reduce the result, and the sort for the order.

Type Parameters:
T - the type of the POJO or bean.
Parameters:
pClass - the class of the POJO or bean.
pFilter - the filter as 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 list of Beans/POJOs from the storage.
Throws:
DataSourceException - if an Exception occur during interacting with the storage.

refetch

public <T> T refetch(T pObject)
          throws DataSourceException
Refetchs the specified bean/POJO and returns a bean/POJO with current values from the storage.

Type Parameters:
T - the type of the POJO or bean.
Parameters:
pObject - the specified bean/POJO to refetch from the storage.
Returns:
the refetched bean/POJO with all values from the storage.
Throws:
DataSourceException - if an Exception occur during interacting with the Storage.

insert

public <T> T insert(T pObject)
         throws DataSourceException
Inserts the new bean/POJO and returns a bean/POJO with current values from the storage.

Type Parameters:
T - the type of the POJO or bean.
Parameters:
pObject - the new IBean/POJO to insert to the storage.
Returns:
the newly inserted IBean/POJO with all automatically filled in values from the storage.
Throws:
DataSourceException - if an Exception occur during insert into the storage

update

public <T> T update(T pObject)
         throws DataSourceException
Updates a bean/POJO with the PrimaryKey columns and provides values. It returns a bean/POJO with the current values from the storage.

Type Parameters:
T - the type of the POJO or bean.
Parameters:
pObject - the new IBean/POJO to use for the update
Returns:
the updated IBean/POJO from the storage.
Throws:
DataSourceException - if an Exception occur during updating process in the storage.

delete

public <T> void delete(T pObject)
            throws DataSourceException
Deletes the specified bean/POJO from the storage.

Type Parameters:
T - the type of the POJO or bean.
Parameters:
pObject - the bean/POJO to delete from the storage.
Throws:
DataSourceException - if an Exception occur during the delete operation in the storage.

executeRefetchRowAsBean

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

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[])

executeFetchAsBean

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

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)

executeInsertAsBean

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

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[])

executeUpdateAsBean

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

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[])

executeDeleteAsBean

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

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[])


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.