es.prodevelop.gvsig.mobile.fmap.driver.vect.dbf
Class DbfMemoryDataSource

java.lang.Object
  extended byes.prodevelop.gvsig.mobile.fmap.driver.vect.dbf.DbfMemoryDataSource
All Implemented Interfaces:
com.hardcode.gdbms.engine.data.DataSource, com.hardcode.gdbms.engine.data.driver.ReadAccess

public class DbfMemoryDataSource
extends java.lang.Object
implements com.hardcode.gdbms.engine.data.DataSource

This class implements a DataSource which is based on a DBF file fully loaded into memory.

Author:
jldominguez
See Also:
DbaseFileNIO

Field Summary
 
Fields inherited from interface com.hardcode.gdbms.engine.data.driver.ReadAccess
FIELD_TYPE_BOOLEAN, FIELD_TYPE_DOUBLE, FIELD_TYPE_FLOAT, FIELD_TYPE_INT, FIELD_TYPE_LONGINT, FIELD_TYPE_STRING
 
Constructor Summary
DbfMemoryDataSource(java.io.File _dbFile)
          Constructor
 
Method Summary
 void addDataSourceListener(com.hardcode.gdbms.engine.data.IDataSourceListener arg0)
          Adds a datasource listener.
 java.lang.String getAsString()
           
 com.hardcode.gdbms.engine.data.DataSourceFactory getDataSourceFactory()
           
 com.hardcode.gdbms.engine.data.edition.DataWare getDataWare(int arg0)
          Gets the data ware associated with the given index.
 com.hardcode.driverManager.Driver getDriver()
           
 int getFieldCount()
           
 int getFieldIndexByName(java.lang.String arg0)
          Gets the idnex of a field, provided its name.
 java.lang.String getFieldName(int arg0)
          Gets the name of the field with the given index.
 java.lang.String[] getFieldNames()
           
 int getFieldType(int arg0)
          Gets the type of the field with the given index.
 com.hardcode.gdbms.engine.values.Value getFieldValue(long arg0, int arg1)
          Gets a value from thsi data source.
 int getFieldWidth(int arg0)
          Gets the width of the field with the given index.
 com.hardcode.gdbms.engine.data.persistence.Memento getMemento()
           
 java.lang.String getName()
           
 int getPKCardinality()
           
 java.lang.String getPKName(int arg0)
          Gets the name of one of the fields that compose the PK.
 java.lang.String[] getPKNames()
           
 int getPKType(int arg0)
          Gets the type of one of the fields that compose the PK.
 com.hardcode.gdbms.engine.values.ValueCollection getPKValue(long arg0)
          Gets the primary key value for a row
 int[] getPrimaryKeys()
           
 com.hardcode.gdbms.engine.values.Value[] getRow(long rowind)
          Gets a row of this data source.
 long getRowCount()
           
 com.hardcode.gdbms.engine.data.SourceInfo getSourceInfo()
           
 long[] getWhereFilter()
           
 boolean isVirtualField(int arg0)
          Gets whether the referenced field is virtual or not.
 void reload()
          Reloads the data source (stops and starts)
 void remove()
          Called when the layer is removed.
 void removeDataSourceListener(com.hardcode.gdbms.engine.data.IDataSourceListener arg0)
          Removes a datasource listener.
 void setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory arg0)
          Sets the datasource factory.
 void setSourceInfo(com.hardcode.gdbms.engine.data.SourceInfo arg0)
          Sets the source info.
 void start()
          Initializes the dfata source (reads the file into memory)
 void stop()
          Stops the datasource.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbfMemoryDataSource

public DbfMemoryDataSource(java.io.File _dbFile)
Constructor

Parameters:
_dbFile - the DBF file to read
Method Detail

start

public void start()
           throws com.hardcode.gdbms.engine.data.driver.DriverException
Initializes the dfata source (reads the file into memory)

Specified by:
start in interface com.hardcode.gdbms.engine.data.DataSource
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

stop

public void stop()
          throws com.hardcode.gdbms.engine.data.driver.DriverException
Stops the datasource. Tries to close the DBF file.

Specified by:
stop in interface com.hardcode.gdbms.engine.data.DataSource
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getName

public java.lang.String getName()
Specified by:
getName in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
the data source generic name

getWhereFilter

public long[] getWhereFilter()
                      throws java.io.IOException
Specified by:
getWhereFilter in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
an array representing the WHERE filter. Currently unused.
Throws:
java.io.IOException

getDataSourceFactory

public com.hardcode.gdbms.engine.data.DataSourceFactory getDataSourceFactory()
Specified by:
getDataSourceFactory in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
the associated datasource factory. Currently unused.

getMemento

public com.hardcode.gdbms.engine.data.persistence.Memento getMemento()
                                                              throws com.hardcode.gdbms.engine.data.persistence.MementoException
Specified by:
getMemento in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
the memento. Currently unused.
Throws:
com.hardcode.gdbms.engine.data.persistence.MementoException

setDataSourceFactory

public void setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory arg0)
Sets the datasource factory. Currently unused.

Specified by:
setDataSourceFactory in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the new data source factory

setSourceInfo

public void setSourceInfo(com.hardcode.gdbms.engine.data.SourceInfo arg0)
Sets the source info. Currently unused.

Specified by:
setSourceInfo in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the new source info

getSourceInfo

public com.hardcode.gdbms.engine.data.SourceInfo getSourceInfo()
Specified by:
getSourceInfo in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
the source info. Currently unused.

getAsString

public java.lang.String getAsString()
                             throws com.hardcode.gdbms.engine.data.driver.DriverException
Specified by:
getAsString in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
a string representing the datasource. Unused. Simply redirects to getName()
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

remove

public void remove()
            throws com.hardcode.gdbms.engine.data.driver.DriverException
Called when the layer is removed. Tries to prevent memory leaks.

Specified by:
remove in interface com.hardcode.gdbms.engine.data.DataSource
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getPrimaryKeys

public int[] getPrimaryKeys()
                     throws com.hardcode.gdbms.engine.data.driver.DriverException
Specified by:
getPrimaryKeys in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
an array with the indices of the primary keys.
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getPKValue

public com.hardcode.gdbms.engine.values.ValueCollection getPKValue(long arg0)
                                                            throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets the primary key value for a row

Specified by:
getPKValue in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the row of interest
Returns:
a collection representing the primary key
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getPKName

public java.lang.String getPKName(int arg0)
                           throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets the name of one of the fields that compose the PK.

Specified by:
getPKName in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the index of the PK field of interest
Returns:
the name of the field of interest
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getPKNames

public java.lang.String[] getPKNames()
                              throws com.hardcode.gdbms.engine.data.driver.DriverException
Specified by:
getPKNames in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
the names of the fields that compose the PK.
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getPKType

public int getPKType(int arg0)
              throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets the type of one of the fields that compose the PK.

Specified by:
getPKType in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the index of the field of interest
Returns:
the type of the field of interest
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getPKCardinality

public int getPKCardinality()
                     throws com.hardcode.gdbms.engine.data.driver.DriverException
Specified by:
getPKCardinality in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
the cumber of fields that compose the PK.
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getRow

public com.hardcode.gdbms.engine.values.Value[] getRow(long rowind)
                                                throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets a row of this data source.

Specified by:
getRow in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
rowind - the index of the row of interest
Returns:
the row as an array of values
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getFieldNames

public java.lang.String[] getFieldNames()
                                 throws com.hardcode.gdbms.engine.data.driver.DriverException
Specified by:
getFieldNames in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
an array with all the field names
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getFieldIndexByName

public int getFieldIndexByName(java.lang.String arg0)
                        throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets the idnex of a field, provided its name.

Specified by:
getFieldIndexByName in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the name of the field of interest
Returns:
the index of the field of interest
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getDataWare

public com.hardcode.gdbms.engine.data.edition.DataWare getDataWare(int arg0)
                                                            throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets the data ware associated with the given index. Currently unused.

Specified by:
getDataWare in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the index of interest
Returns:
the associated data ware
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

isVirtualField

public boolean isVirtualField(int arg0)
                       throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets whether the referenced field is virtual or not.

Specified by:
isVirtualField in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the index of the field of interest
Returns:
whether it is a virtual field.
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getDriver

public com.hardcode.driverManager.Driver getDriver()
Specified by:
getDriver in interface com.hardcode.gdbms.engine.data.DataSource
Returns:
the associated driver, currently unused.

reload

public void reload()
            throws com.hardcode.gdbms.engine.data.driver.DriverException,
                   java.io.IOException
Reloads the data source (stops and starts)

Specified by:
reload in interface com.hardcode.gdbms.engine.data.DataSource
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException
java.io.IOException

addDataSourceListener

public void addDataSourceListener(com.hardcode.gdbms.engine.data.IDataSourceListener arg0)
Adds a datasource listener. Currently unused.

Specified by:
addDataSourceListener in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the listener to be added.

removeDataSourceListener

public void removeDataSourceListener(com.hardcode.gdbms.engine.data.IDataSourceListener arg0)
Removes a datasource listener. Currently unused.

Specified by:
removeDataSourceListener in interface com.hardcode.gdbms.engine.data.DataSource
Parameters:
arg0 - the listener to be removed.

getFieldValue

public com.hardcode.gdbms.engine.values.Value getFieldValue(long arg0,
                                                            int arg1)
                                                     throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets a value from thsi data source.

Specified by:
getFieldValue in interface com.hardcode.gdbms.engine.data.driver.ReadAccess
Parameters:
arg0 - the row of interest
arg1 - the index of the field of interest
Returns:
the value of the given row and field
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getFieldCount

public int getFieldCount()
                  throws com.hardcode.gdbms.engine.data.driver.DriverException
Specified by:
getFieldCount in interface com.hardcode.gdbms.engine.data.driver.ReadAccess
Returns:
the number of fields in this datasource
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getFieldName

public java.lang.String getFieldName(int arg0)
                              throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets the name of the field with the given index.

Specified by:
getFieldName in interface com.hardcode.gdbms.engine.data.driver.ReadAccess
Parameters:
arg0 - the index of the field of interest
Returns:
the name of the field
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getRowCount

public long getRowCount()
                 throws com.hardcode.gdbms.engine.data.driver.DriverException
Specified by:
getRowCount in interface com.hardcode.gdbms.engine.data.driver.ReadAccess
Returns:
the number of rows in this data source
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getFieldType

public int getFieldType(int arg0)
                 throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets the type of the field with the given index.

Specified by:
getFieldType in interface com.hardcode.gdbms.engine.data.driver.ReadAccess
Parameters:
arg0 - the index of the field of interest
Returns:
teh field type
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException

getFieldWidth

public int getFieldWidth(int arg0)
                  throws com.hardcode.gdbms.engine.data.driver.DriverException
Gets the width of the field with the given index.

Specified by:
getFieldWidth in interface com.hardcode.gdbms.engine.data.driver.ReadAccess
Parameters:
arg0 - the index of the field of interest
Returns:
teh field width
Throws:
com.hardcode.gdbms.engine.data.driver.DriverException