com.hardcode.gdbms.engine.data
Class AutomaticDataSource

java.lang.Object
  extended by com.hardcode.gdbms.engine.data.AutomaticDataSource
All Implemented Interfaces:
AlphanumericDataSource, DataSource, ReadAccess

public class AutomaticDataSource
extends java.lang.Object
implements AlphanumericDataSource

Decorator over data sources in order to apply a automatic opening mode

Author:
Fernando González Cortés

Field Summary
 
Fields inherited from interface com.hardcode.gdbms.engine.data.DataSource
COHERENT_ROW_ORDER, DIRECT_MODE, DISPATCH, IGNORE, STORE
 
Constructor Summary
AutomaticDataSource(AlphanumericDataSource ds, long timeout)
          Creates a new AutomaticDataSource.
 
Method Summary
 void addEditionListener(EditionListener listener)
          Adds an EditionListener to the DataSource
 void addField(java.lang.String name, java.lang.String type)
          Adds a field to the DataSource
 void addField(java.lang.String name, java.lang.String driverType, java.lang.String[] paramNames, java.lang.String[] paramValues)
          Adds a field to the DataSource
 void addMetadataEditionListener(MetadataEditionListener listener)
          Adds a listener for the Metadata edition events
 void addSelectionListener(SelectionListener listener)
          Adds an SelectionListener to the DataSource
 void beginTrans()
          Begins a transaction
 boolean canRedo()
           
 boolean canUndo()
           
 java.lang.String check(int fieldId, Value value)
          Checks if this value is a valid one for the specified field.
 void commitTrans()
          Commits the changes made during the transaction.
 void deleteRow(long rowId)
          Deletes the ith row of the DataSource
 java.lang.String getAlias()
          Returns the alias used in this DataSource
 java.lang.String getAsString()
          Gets the string representation of this DataSource
 DataSourceFactory getDataSourceFactory()
          gets a reference to the factory object that created the DataSource
 Metadata getDataSourceMetadata()
          Gets the meta data about the source of this DataSource
 int getDispatchingMode()
          Gets the dispatchingMode property
 GDBMSDriver getDriver()
          Gets the driver which this DataSource is over.
 DriverMetadata getDriverMetadata()
          Gets the driver metadata
 int getFieldIndexByName(java.lang.String fieldName)
          Obtiene el indice de un campo a partir de su nombre o -1 si no existe un campo con ese nombre
 java.lang.String[] getFieldNames()
          Gets the field names array
 Value getFieldValue(long rowIndex, int fieldId)
          Obtiene el valor que se encuentra en la fila y columna indicada
 Memento getMemento()
          Gets a memento object with the current status of the DataSource
 java.lang.String getName()
          Devuelve el nombre del DataSource
 Value[] getRow(long rowIndex)
          Gets the value of all fields at the specified row
 long getRowCount()
          Obtiene el número de registros del DataSource
 int[] getSelectedRows()
          Gets the row selection
 long[] getWhereFilter()
          Devuelve el filtro que resultó de la cláusula where de la instrucción que dió como resultado este DataSource.
 void insertEmptyRow()
          Inserts a row at the end of the dataware
 void insertEmptyRowAt(long index)
          Inserts a row at the end of the dataware
 void insertFilledRow(Value[] values)
          Inserts a row at the end of the dataware with the specified values
 void insertFilledRowAt(long index, Value[] values)
          Inserts a row at the end of the dataware with the specified values
 boolean isModified()
          Returns true if the DataSource has been modified since it was created.
 void redo()
          Redoes the last undone edition action
 void remove()
          Removes from the system the data source this DataSource instance represents.
 void removeEditionListener(EditionListener listener)
          Removes an EditionListener from the DataSource
 void removeField(int index)
          Removes the field at the indexth position
 void removeMetadataEditionListener(MetadataEditionListener listener)
          Removes a listener for the Metadata edition events
 void removeSelectionListener(SelectionListener listener)
          Removes an SelectionListener from the DataSource
 void rollBackTrans()
          Cancels the changes made during the transaction
 void saveData(DataSource ds)
          Saves the data in the parameter DataSource in the source of this DataSource.
 void setDataSourceFactory(DataSourceFactory dsf)
          Sets the DataSourceFactory that created the DataSource instance
 void setDispatchingMode(int dispatchingMode)
          Defines the behaviour of the DataSource when an edition event happens.
 void setFieldName(int index, java.lang.String name)
          Sets the name of the field at the indexth position
 void setFieldValue(long row, int fieldId, Value value)
          Sets the value of a cell of the table.
 void setSelectedRows(int[] sel)
          Sets the row selection
 void start()
          Opens the DataSource to access the data it contains.
 void stop()
          Closes the DataSource.
 void undo()
          Undoes the last edition action
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutomaticDataSource

public AutomaticDataSource(AlphanumericDataSource ds,
                           long timeout)
Creates a new AutomaticDataSource.

Parameters:
ds - DataSource to decorate
timeout - DataSource will close if there is no operation int timeout milliseconds
Method Detail

start

public void start()
           throws DriverException
Description copied from interface: DataSource
Opens the DataSource to access the data it contains. If the data is accessed without a previous opening a ClosedDataSourceException is thrown. If this method is invoked twice then only the second call to stop will close the DataSource.
If the DataSource was obtained with an AUTOMATIC_OPENING mode, there's no need to open the DataSource. Indeed start calls are ignored. It's possible to close the DataSource by a single call to the close method

Specified by:
start in interface DataSource
Throws:
DriverException - if the operation fails
See Also:
DataSource.start()

stop

public void stop()
          throws DriverException
Description copied from interface: DataSource
Closes the DataSource. After a DataSource is closed it's data cannot be retrieved. Any attempt to do so will result in a DataSourceClosedException

Specified by:
stop in interface DataSource
Throws:
DriverException - If the operation fails
See Also:
DataSource.stop()

getName

public java.lang.String getName()
Description copied from interface: DataSource
Devuelve el nombre del DataSource

Specified by:
getName in interface DataSource
Returns:
nombre de la tabla
See Also:
DataSource.getName()

getWhereFilter

public long[] getWhereFilter()
                      throws java.io.IOException
Description copied from interface: DataSource
Devuelve el filtro que resultó de la cláusula where de la instrucción que dió como resultado este DataSource.

Specified by:
getWhereFilter in interface DataSource
Returns:
Filtro de la cláusula where o null si el DataSource no es resultado de una instrucción con cláusula where
Throws:
java.io.IOException - Si se produce un error accediendo a las estructuras de datos internas
See Also:
DataSource.getWhereFilter()

getDataSourceFactory

public DataSourceFactory getDataSourceFactory()
Description copied from interface: DataSource
gets a reference to the factory object that created the DataSource

Specified by:
getDataSourceFactory in interface DataSource
Returns:
DataSourceFactory
See Also:
DataSource.getDataSourceFactory()

getMemento

public Memento getMemento()
                   throws MementoException
Description copied from interface: DataSource
Gets a memento object with the current status of the DataSource

Specified by:
getMemento in interface DataSource
Returns:
DataSourceMemento
Throws:
MementoException - If the state cannot be obtained
See Also:
DataSource.getMemento()

setDataSourceFactory

public void setDataSourceFactory(DataSourceFactory dsf)
Description copied from interface: DataSource
Sets the DataSourceFactory that created the DataSource instance

Specified by:
setDataSourceFactory in interface DataSource
Parameters:
dsf - DataSourceFactory
See Also:
DataSource.setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)

getFieldIndexByName

public int getFieldIndexByName(java.lang.String fieldName)
                        throws DriverException
Description copied from interface: DataSource
Obtiene el indice de un campo a partir de su nombre o -1 si no existe un campo con ese nombre

Specified by:
getFieldIndexByName in interface DataSource
Parameters:
fieldName - Nombre del campo
Returns:
Indice del campo con el nombre dado o -1 si el campo no existe
Throws:
DriverException - Si se produce un error accediendo a los datos
See Also:
com.hardcode.gdbms.engine.data.FieldNameAccess#getFieldIndexByName(java.lang.String)

getFieldValue

public Value getFieldValue(long rowIndex,
                           int fieldId)
                    throws DriverException
Description copied from interface: ReadAccess
Obtiene el valor que se encuentra en la fila y columna indicada

Specified by:
getFieldValue in interface ReadAccess
Parameters:
rowIndex - fila
fieldId - columna
Returns:
subclase de Value con el valor del origen de datos. Never null (use ValueFactory.createNullValue() instead)
Throws:
DriverException - Si se produce un error accediendo al DataSource
See Also:
ReadAccess.getFieldValue(long, int)

getRowCount

public long getRowCount()
                 throws DriverException
Description copied from interface: ReadAccess
Obtiene el número de registros del DataSource

Specified by:
getRowCount in interface ReadAccess
Returns:
Throws:
DriverException - Si se produce algún error accediendo al DataSource
See Also:
ReadAccess.getRowCount()

getAsString

public java.lang.String getAsString()
                             throws DriverException
Description copied from interface: DataSource
Gets the string representation of this DataSource

Specified by:
getAsString in interface DataSource
Returns:
String
Throws:
DriverException
See Also:
DataSource.getAsString()

remove

public void remove()
            throws DriverException
Description copied from interface: DataSource
Removes from the system the data source this DataSource instance represents. No method can be called and no DataSource instance can be obtained from the system after calling this method.

Specified by:
remove in interface DataSource
Throws:
DriverException
See Also:
DataSource.remove()

getRow

public Value[] getRow(long rowIndex)
               throws DriverException
Description copied from interface: DataSource
Gets the value of all fields at the specified row

Specified by:
getRow in interface DataSource
Parameters:
rowIndex - index of the row to be retrieved
Returns:
Value[]
Throws:
DriverException - If the access fails
See Also:
DataSource.getRow(long)

getFieldNames

public java.lang.String[] getFieldNames()
                                 throws DriverException
Description copied from interface: DataSource
Gets the field names array

Specified by:
getFieldNames in interface DataSource
Returns:
String[]
Throws:
DriverException - if the access fails
See Also:
DataSource.getFieldNames()

deleteRow

public void deleteRow(long rowId)
               throws DriverException
Description copied from interface: AlphanumericDataSource
Deletes the ith row of the DataSource

Specified by:
deleteRow in interface AlphanumericDataSource
Parameters:
rowId - index of the row to be deleted
Throws:
DriverException - if the row could not be deleted

insertFilledRow

public void insertFilledRow(Value[] values)
                     throws DriverException
Description copied from interface: DataSource
Inserts a row at the end of the dataware with the specified values

Specified by:
insertFilledRow in interface DataSource
Parameters:
values - Values of the inserted row fields in the field order
Throws:
DriverException - if the row could not be inserted

insertEmptyRow

public void insertEmptyRow()
                    throws DriverException
Description copied from interface: DataSource
Inserts a row at the end of the dataware

Specified by:
insertEmptyRow in interface DataSource
Throws:
DriverException - if the row could not be inserted

beginTrans

public void beginTrans()
                throws DriverException
Description copied from interface: DataSource
Begins a transaction

Specified by:
beginTrans in interface DataSource
Throws:
DriverException - If the transaction could not be started

commitTrans

public void commitTrans()
                 throws DriverException,
                        FreeingResourcesException
Description copied from interface: DataSource
Commits the changes made during the transaction. The DataSource is closed after the commit so any spatial or alphanumeric index will be cleared

Specified by:
commitTrans in interface DataSource
Throws:
DriverException - If the transaction could not be commited
FreeingResourcesException - The commit was correctly done but a problem occured while freeing resources

rollBackTrans

public void rollBackTrans()
                   throws DriverException
Description copied from interface: DataSource
Cancels the changes made during the transaction

Specified by:
rollBackTrans in interface DataSource
Throws:
DriverException - If the transaction could not be cancelled

setFieldValue

public void setFieldValue(long row,
                          int fieldId,
                          Value value)
                   throws DriverException
Description copied from interface: DataSource
Sets the value of a cell of the table. Cannot be called outside a beginTrans-commintTrans or beginTrans-rollBackTrans

Specified by:
setFieldValue in interface DataSource
Parameters:
row - row to update
fieldId - field to update
value - Value to update
Throws:
DriverException - If the operation failed

getAlias

public java.lang.String getAlias()
Description copied from interface: DataSource
Returns the alias used in this DataSource

Specified by:
getAlias in interface DataSource
Returns:
String

insertFilledRowAt

public void insertFilledRowAt(long index,
                              Value[] values)
                       throws DriverException
Description copied from interface: AlphanumericDataSource
Inserts a row at the end of the dataware with the specified values

Specified by:
insertFilledRowAt in interface AlphanumericDataSource
Parameters:
index - index where the row will be inserted. No data is lost.
values - Values of the inserted row fields in the field order
Throws:
DriverException - if the row could not be inserted

insertEmptyRowAt

public void insertEmptyRowAt(long index)
                      throws DriverException
Description copied from interface: AlphanumericDataSource
Inserts a row at the end of the dataware

Specified by:
insertEmptyRowAt in interface AlphanumericDataSource
Parameters:
index - index where the row will be inserted. No data is lost.
Throws:
DriverException - if the row could not be inserted

getDataSourceMetadata

public Metadata getDataSourceMetadata()
                               throws DriverException
Description copied from interface: DataSource
Gets the meta data about the source of this DataSource

Specified by:
getDataSourceMetadata in interface DataSource
Returns:
DataSourceMetadata
Throws:
DriverException - If cannot get the DataSource metadata

saveData

public void saveData(DataSource ds)
              throws DriverException
Description copied from interface: DataSource
Saves the data in the parameter DataSource in the source of this DataSource. Both DataSource's must have the same schema, the same metadata. This DataSource must be closed before any call to this method

Specified by:
saveData in interface DataSource
Parameters:
ds - DataSource with the data
Throws:
DriverException - if the operation fails

canRedo

public boolean canRedo()
Specified by:
canRedo in interface DataSource
Returns:
true if there is an edition action to redo

canUndo

public boolean canUndo()
Specified by:
canUndo in interface DataSource
Returns:
true if there is an edition action to undo

redo

public void redo()
          throws DriverException
Description copied from interface: DataSource
Redoes the last undone edition action

Specified by:
redo in interface DataSource
Throws:
DriverException

undo

public void undo()
          throws DriverException
Description copied from interface: DataSource
Undoes the last edition action

Specified by:
undo in interface DataSource
Throws:
DriverException

addEditionListener

public void addEditionListener(EditionListener listener)
Description copied from interface: DataSource
Adds an EditionListener to the DataSource

Specified by:
addEditionListener in interface DataSource

removeEditionListener

public void removeEditionListener(EditionListener listener)
Description copied from interface: DataSource
Removes an EditionListener from the DataSource

Specified by:
removeEditionListener in interface DataSource

setDispatchingMode

public void setDispatchingMode(int dispatchingMode)
Description copied from interface: DataSource
Defines the behaviour of the DataSource when an edition event happens. It can be set to DISPATCH, STORE, IGNORE. It's set to DISPATCH when the DataSource opens

Specified by:
setDispatchingMode in interface DataSource

getDispatchingMode

public int getDispatchingMode()
Description copied from interface: DataSource
Gets the dispatchingMode property

Specified by:
getDispatchingMode in interface DataSource

addField

public void addField(java.lang.String name,
                     java.lang.String type)
              throws DriverException
Description copied from interface: DataSource
Adds a field to the DataSource

Specified by:
addField in interface DataSource
Parameters:
name - name of the field
type - driver specific type name
Throws:
DriverException

removeField

public void removeField(int index)
                 throws DriverException
Description copied from interface: DataSource
Removes the field at the indexth position

Specified by:
removeField in interface DataSource
Throws:
DriverException

setFieldName

public void setFieldName(int index,
                         java.lang.String name)
                  throws DriverException
Description copied from interface: DataSource
Sets the name of the field at the indexth position

Specified by:
setFieldName in interface DataSource
Throws:
DriverException

addMetadataEditionListener

public void addMetadataEditionListener(MetadataEditionListener listener)
Description copied from interface: DataSource
Adds a listener for the Metadata edition events

Specified by:
addMetadataEditionListener in interface DataSource

removeMetadataEditionListener

public void removeMetadataEditionListener(MetadataEditionListener listener)
Description copied from interface: DataSource
Removes a listener for the Metadata edition events

Specified by:
removeMetadataEditionListener in interface DataSource

getDriverMetadata

public DriverMetadata getDriverMetadata()
                                 throws DriverException
Description copied from interface: DataSource
Gets the driver metadata

Specified by:
getDriverMetadata in interface DataSource
Returns:
Throws:
DriverException

addField

public void addField(java.lang.String name,
                     java.lang.String driverType,
                     java.lang.String[] paramNames,
                     java.lang.String[] paramValues)
              throws DriverException
Description copied from interface: DataSource
Adds a field to the DataSource

Specified by:
addField in interface DataSource
Parameters:
name - name of the field
driverType - driver specific type name
Throws:
DriverException

check

public java.lang.String check(int fieldId,
                              Value value)
                       throws DriverException
Description copied from interface: DataSource
Checks if this value is a valid one for the specified field. Returns null if the field contains a valid value and returns a String with a message to the user if it is not

Specified by:
check in interface DataSource
Returns:
Throws:
DriverException

getDriver

public GDBMSDriver getDriver()
Description copied from interface: DataSource
Gets the driver which this DataSource is over. Can be null

Specified by:
getDriver in interface DataSource
Returns:

isModified

public boolean isModified()
Description copied from interface: DataSource
Returns true if the DataSource has been modified since it was created. Notice that it doesn't check the source and only checks wheter the source has been modified through this instance

Specified by:
isModified in interface DataSource
Returns:

getSelectedRows

public int[] getSelectedRows()
Description copied from interface: DataSource
Gets the row selection

Specified by:
getSelectedRows in interface DataSource
Returns:

setSelectedRows

public void setSelectedRows(int[] sel)
Description copied from interface: DataSource
Sets the row selection

Specified by:
setSelectedRows in interface DataSource

addSelectionListener

public void addSelectionListener(SelectionListener listener)
Description copied from interface: DataSource
Adds an SelectionListener to the DataSource

Specified by:
addSelectionListener in interface DataSource

removeSelectionListener

public void removeSelectionListener(SelectionListener listener)
Description copied from interface: DataSource
Removes an SelectionListener from the DataSource

Specified by:
removeSelectionListener in interface DataSource


Copyright © 2005-2006 . All Rights Reserved.