Package hec.io

Class DBFDataStorage

All Implemented Interfaces:
AsciiSerializableConstants, DataStorage

public class DBFDataStorage extends AbstractDataStorage implements AsciiSerializableConstants
This is the base class for writing to DBF Files. The methods in this class should be overidden in each base clase, because each DBF file has its own format (ie column names) that need to be know. Unfortunately this class cannot be generic for each DBF file. This object maintains the pointer to the database for all dbf storage subclasses. There only needs to be one pointer. Each subclass is free to create/close/open its pointer to its particular dbf file.

Since:
14 November 2000
  • Field Details

    • _errorCodeFormat

      protected static MessageFormat _errorCodeFormat
    • _checkForDifferences

      protected boolean _checkForDifferences
    • DEBUG

      public static boolean DEBUG
    • _database

      protected codebase.Code4jni _database
    • _dbfFile

      protected codebase.Data4jni _dbfFile
    • _dbfSubFileTable

      protected Map _dbfSubFileTable
    • _dbfFields

      protected codebase.Field4info _dbfFields
    • _dbfTags

      protected codebase.Tag4info _dbfTags
    • _dbfMap

      protected DBFMappingClass _dbfMap
    • _field4List

      protected List _field4List
    • _hasBeenInit

      protected boolean _hasBeenInit
    • _hasTags

      protected boolean _hasTags
    • _id

      protected Identifier _id
    • _TAGID

      protected String _TAGID
    • _TAGNAME

      protected String _TAGNAME
    • _deleteFlag

      protected codebase.Field4deleteFlag _deleteFlag
    • _jName2FieldMap

      protected Map<String,Field> _jName2FieldMap
    • _nextId

      protected long _nextId
    • _classType

      protected String _classType
    • _serializedObj

      protected DBFSerializable _serializedObj
    • _dbfRefCount

      protected int _dbfRefCount
    • _currentRow

      protected int _currentRow
    • _recordDeleted

      protected boolean _recordDeleted
    • DBF_UNDEF_INT

      public static final Integer DBF_UNDEF_INT
    • DBF_UNDEF_LONG

      public static final Long DBF_UNDEF_LONG
    • DBF_UNDEF_DOUBLE

      public static final Double DBF_UNDEF_DOUBLE
    • DBF_UNDEF_FLOAT

      public static final Float DBF_UNDEF_FLOAT
    • DBF_UNDEF_INT2

      public static final Integer DBF_UNDEF_INT2
    • DBF_UNDEF_LONG2

      public static final Long DBF_UNDEF_LONG2
    • DBF_UNDEF_DOUBLE2

      public static final Double DBF_UNDEF_DOUBLE2
    • DBF_UNDEF_FLOAT2

      public static final Float DBF_UNDEF_FLOAT2
  • Constructor Details

    • DBFDataStorage

      public DBFDataStorage(String workspacePath, String clsType)
      Constructor for the DBFDataStorage object. Takes a reference to the owner data list, in order to construct the object

      Parameters:
      workspacePath - The reference to the owner data list.
    • DBFDataStorage

      public DBFDataStorage(String filePath, String clsType, String notUsed)
  • Method Details

    • setCheckForDifferences

      public void setCheckForDifferences(boolean runCheck)
    • getCurrentRowIndex

      public int getCurrentRowIndex()
    • main

      public static void main(String[] args) throws codebase.Error4unexpected, codebase.Error4relateMatch
      Throws:
      codebase.Error4unexpected
      codebase.Error4relateMatch
    • setInitialized

      public void setInitialized(boolean b)
    • createTagInfo

      public static codebase.Tag4info createTagInfo(DBFSerializable dbfObj) throws codebase.Error4usage
      Throws:
      codebase.Error4usage
    • addNewObject

      public long addNewObject(Object obj)
      Adds a new object to the end of the DBF file. The id is autogenerated by the DBF table as the next row in the table.

      Specified by:
      addNewObject in interface DataStorage
      Overrides:
      addNewObject in class AbstractDataStorage
      Parameters:
      obj - The data object to add to the file

      Returns:
      returns the id of the object added to the file
    • backupData

      public boolean backupData(String backupDir, DataObject obj)
      creats a backup of the dbf file

      Specified by:
      backupData in interface DataStorage
      Overrides:
      backupData in class AbstractDataStorage
      Parameters:
      backupDir - The backup directory to write to
      obj -
    • callNativeMethod

      public Object callNativeMethod(Object obj)
      This method is overridden and returns null. These classes and subclasses should not have any Natives methods that need to be called

      Specified by:
      callNativeMethod in interface DataStorage
      Overrides:
      callNativeMethod in class AbstractDataStorage
      Parameters:
      obj - The object that represents the native method to call

      Returns:
      NULL
    • getDataObjectIdList

      public Object[] getDataObjectIdList(String objClass)
      Returns a List of data objects that are in this storage

      Specified by:
      getDataObjectIdList in interface DataStorage
      Parameters:
      objClass - The string representation of the object class
    • getObjectCount

      public int getObjectCount()
      Specified by:
      getObjectCount in interface DataStorage
      Overrides:
      getObjectCount in class AbstractDataStorage
    • getMethodsByName

      public Method[] getMethodsByName(String methodName)
      Description copied from class: AbstractDataStorage
      return a list of methods that have the methodName
      Overrides:
      getMethodsByName in class AbstractDataStorage
    • getObjectList

      public DataStruct[] getObjectList(String objClass)
      Specified by:
      getObjectList in interface DataStorage
      Parameters:
      objClass -
    • lockAddAll

      public void lockAddAll()
    • unlock

      public void unlock()
    • numberRecords

      public int numberRecords()
      Calculates how many records are in the database
    • isInitialized

      public boolean isInitialized()
    • init

      public boolean init()
      Description copied from interface: DataStorage
      initialize this DataStorage
      Specified by:
      init in interface DataStorage
    • mapBaseFields

      protected void mapBaseFields()
      Maps fields in the table to field variables
    • loadObject

      public Object loadObject(long id, String objClass)
      loads a record from the database into the given data object.

      Specified by:
      loadObject in interface DataStorage
      Parameters:
      id - The identifier of the record/object to load
      objClass - The class of the object to load

      Returns:
      the loaded data object
    • loadObject

      public Object loadObject(long id, DBFSerializable dbfObj)
    • loadObjects

      public <T> DBFDataStorage.DBFIterator<T> loadObjects(String expression, Class<T> clazz)
      Uses a DBF expression to load a set of objects. An Iterator is returned that will iterator over all of the returned objects. The returned set is unmodifiable and the remove() method throws an exceptions. The Iterator is closed automatically when the last row is is passed.

      Parameters:
      expression -
      clazz -

      Returns:
    • assignObjectValues

      protected void assignObjectValues(DBFSerializable dbfObj)
    • instantiateDataObject

      protected Object instantiateDataObject(codebase.Field4 data, Field fieldObj)
      This is a private method that is used to instantiate a java object based on the DBFSerializable object data. This method only builds objects that are supported by DBF such as Long, Integer, Double, Boolean, Byte, Short, Char, Float, String, java.util.Date

      Parameters:
      data - - represents that data that is being retrieved
      fieldObj - - represents the class that holds the data
    • loadObject

      public Object loadObject(String name, String objClass)
      loads and object from the database based on the name of the object

      Specified by:
      loadObject in interface DataStorage
      Overrides:
      loadObject in class AbstractDataStorage
      Parameters:
      name - The name of the object to load
      objClass - the class of the object to load

      Returns:
      returns the loaded object
    • findObject

      public boolean findObject(String tag, String key)
      Finds an object in the database for the given tag and contains the given key. All fields are updated to the record that is found.

    • removeObject

      public boolean removeObject(long[] objIds, String objClass)
      Specified by:
      removeObject in interface DataStorage
      Overrides:
      removeObject in class AbstractDataStorage
    • pack

      public void pack()
    • memoCompress

      public void memoCompress()
    • removeObject

      public boolean removeObject(long objId, String objClass)
      removes an object from the database. and then packs the dbf file.

      Specified by:
      removeObject in interface DataStorage
      Overrides:
      removeObject in class AbstractDataStorage
      Parameters:
      objId - The object identifier of the object to remove
      objClass - The class representation of the object to remove

      Returns:
      true if the operation was successfull
    • save

      public boolean save()
      Saves the currently loaded record to the database.

      Specified by:
      save in interface DataStorage
      Overrides:
      save in class AbstractDataStorage
      Returns:
      true if successfull, otherwise false
    • doesExist

      public boolean doesExist(DBFSerializable dbfObj)
    • storeObject

      public boolean storeObject(Object obj)
      Stores an object to the database. If the object already exists, then the database is updated to reflect the object. If the object does not exist then it appends the object to the end of the database. The object must also implement DBFSerializeable and be the same object which was used to setup the table.

      Specified by:
      storeObject in interface DataStorage
    • appendData

      public boolean appendData(Object obj)
    • writeCollection

      public void writeCollection(Collection c)
      Returns the milisecond time of the last time that the DBF File was modified. The modification time is in day granularity.

    • workspaceClosing

      public void workspaceClosing()
      Specified by:
      workspaceClosing in interface DataStorage
      Overrides:
      workspaceClosing in class AbstractDataStorage
    • nextRecord

      public boolean nextRecord()
      Moves to the next record in the database.

      Returns:
      true if successful, otherwise returns false, IE move past end of file
    • previousRecord

      public boolean previousRecord()
    • loadCurrentObject

      public Object loadCurrentObject()
    • top

      public boolean top()
      Moves to the top of the database
    • end

      public boolean end()
    • getFilename

      public String getFilename()
      Specified by:
      getFilename in interface DataStorage
      Overrides:
      getFilename in class AbstractDataStorage
    • compress

      public void compress()
      Description copied from class: AbstractDataStorage
      This method is used to compress a datafile. Some data storage implemenations will buffer the record deletes by marking a delete flag. Call this to remove those records.
      Specified by:
      compress in interface DataStorage
      Overrides:
      compress in class AbstractDataStorage
    • reindex

      public void reindex() throws IOException
      Throws:
      IOException