Package hec.io
Class DBFDataStorage
java.lang.Object
hec.io.AbstractDataStorage
hec.io.DBFDataStorage
- All Implemented Interfaces:
AsciiSerializableConstants
,DataStorage
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected String
protected int
protected codebase.Code4jni
protected codebase.Field4info
protected codebase.Data4jni
protected DBFMappingClass
protected int
protected Map
protected codebase.Tag4info
protected codebase.Field4deleteFlag
protected static MessageFormat
protected List
protected boolean
protected boolean
protected Identifier
protected long
protected boolean
protected DBFSerializable
protected String
protected String
static final Double
static final Double
static final Float
static final Float
static final Integer
static final Integer
static final Long
static final Long
static boolean
Fields inherited from interface hec.io.AsciiSerializableConstants
ARRAY, BEGIN, BEGIN_ARRAY, BEGIN_COLLECTION, BEGIN_ENUM_TYPE, BEGIN_HASH, BEGIN_MAP, BEGIN_OBJECT, BEGIN_VECTOR, BOOLEAN, BOOLEAN_TYPE, BYTE, BYTE_TYPE, CHAR, CHAR_TYPE, CLASS, DELIM, DOUBLE, DOUBLE_TYPE, DSSFILEPATH, DSSPATH, END, END_ARRAY, END_COLLECTION, END_ENUM_TYPE, END_HASH, END_MAP, END_OBJECT, END_VECTOR, FIELD, FILEPATH, FLOAT, FLOAT_TYPE, HEADER, ID, INT, INT_TYPE, LONG, LONG_TYPE, NAN, NEGATIVE_INFINITY, OBJECT_ARRAY, OLD_BEGIN, OLD_BEGIN_ARRAY, OLD_BEGIN_HASH, OLD_BEGIN_OBJECT, OLD_BEGIN_VECTOR, OLD_END, OLD_END_ARRAY, OLD_END_HASH, OLD_END_OBJECT, OLD_END_VECTOR, OLD_FIELD, OLD_REFERENCE, OLD_STRING, OLD_VALUE, POSITIVE_INFINITY, REFERENCE, SHORT, SHORT_TYPE, STRING, VALUE, VOID
-
Constructor Summary
ConstructorsConstructorDescriptionDBFDataStorage
(String workspacePath, String clsType) Constructor for the DBFDataStorage object.DBFDataStorage
(String filePath, String clsType, String notUsed) -
Method Summary
Modifier and TypeMethodDescriptionlong
addNewObject
(Object obj) Adds a new object to the end of the DBF file.boolean
appendData
(Object obj) protected void
assignObjectValues
(DBFSerializable dbfObj) boolean
backupData
(String backupDir, DataObject obj) creats a backup of the dbf filecallNativeMethod
(Object obj) This method is overridden and returns null.void
compress()
This method is used to compress a datafile.static codebase.Tag4info
createTagInfo
(DBFSerializable dbfObj) boolean
doesExist
(DBFSerializable dbfObj) boolean
end()
boolean
findObject
(String tag, String key) Finds an object in the database for the given tag and contains the given key.int
Object[]
getDataObjectIdList
(String objClass) Returns a List of data objects that are in this storageMethod[]
getMethodsByName
(String methodName) return a list of methods that have the methodNameint
getObjectList
(String objClass) boolean
init()
initialize this DataStorageprotected 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.boolean
loadObject
(long id, DBFSerializable dbfObj) loadObject
(long id, String objClass) loads a record from the database into the given data object.loadObject
(String name, String objClass) loads and object from the database based on the name of the object<T> DBFDataStorage.DBFIterator<T>
loadObjects
(String expression, Class<T> clazz) Uses a DBF expression to load a set of objects.void
static void
protected void
Maps fields in the table to field variablesvoid
boolean
Moves to the next record in the database.int
Calculates how many records are in the databasevoid
pack()
boolean
void
reindex()
boolean
removeObject
(long[] objIds, String objClass) boolean
removeObject
(long objId, String objClass) removes an object from the database.boolean
save()
Saves the currently loaded record to the database.void
setCheckForDifferences
(boolean runCheck) void
setInitialized
(boolean b) boolean
storeObject
(Object obj) Stores an object to the database.boolean
top()
Moves to the top of the databasevoid
unlock()
void
void
Returns the milisecond time of the last time that the DBF File was modified.Methods inherited from class hec.io.AbstractDataStorage
addNewObject2, getLastModifiedTime, reload
-
Field Details
-
_errorCodeFormat
-
_checkForDifferences
protected boolean _checkForDifferences -
DEBUG
public static boolean DEBUG -
_database
protected codebase.Code4jni _database -
_dbfFile
protected codebase.Data4jni _dbfFile -
_dbfSubFileTable
-
_dbfFields
protected codebase.Field4info _dbfFields -
_dbfTags
protected codebase.Tag4info _dbfTags -
_dbfMap
-
_field4List
-
_hasBeenInit
protected boolean _hasBeenInit -
_hasTags
protected boolean _hasTags -
_id
-
_TAGID
-
_TAGNAME
-
_deleteFlag
protected codebase.Field4deleteFlag _deleteFlag -
_jName2FieldMap
-
_nextId
protected long _nextId -
_classType
-
_serializedObj
-
_dbfRefCount
protected int _dbfRefCount -
_currentRow
protected int _currentRow -
_recordDeleted
protected boolean _recordDeleted -
DBF_UNDEF_INT
-
DBF_UNDEF_LONG
-
DBF_UNDEF_DOUBLE
-
DBF_UNDEF_FLOAT
-
DBF_UNDEF_INT2
-
DBF_UNDEF_LONG2
-
DBF_UNDEF_DOUBLE2
-
DBF_UNDEF_FLOAT2
-
-
Constructor Details
-
DBFDataStorage
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
-
-
Method Details
-
setCheckForDifferences
public void setCheckForDifferences(boolean runCheck) -
getCurrentRowIndex
public int getCurrentRowIndex() -
main
- Throws:
codebase.Error4unexpected
codebase.Error4relateMatch
-
setInitialized
public void setInitialized(boolean b) -
createTagInfo
- Throws:
codebase.Error4usage
-
addNewObject
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 interfaceDataStorage
- Overrides:
addNewObject
in classAbstractDataStorage
- Parameters:
obj
- The data object to add to the file- Returns:
- returns the id of the object added to the file
-
backupData
creats a backup of the dbf file- Specified by:
backupData
in interfaceDataStorage
- Overrides:
backupData
in classAbstractDataStorage
- Parameters:
backupDir
- The backup directory to write toobj
-
-
callNativeMethod
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 interfaceDataStorage
- Overrides:
callNativeMethod
in classAbstractDataStorage
- Parameters:
obj
- The object that represents the native method to call- Returns:
- NULL
-
getDataObjectIdList
Returns a List of data objects that are in this storage- Specified by:
getDataObjectIdList
in interfaceDataStorage
- Parameters:
objClass
- The string representation of the object class
-
getObjectCount
public int getObjectCount()- Specified by:
getObjectCount
in interfaceDataStorage
- Overrides:
getObjectCount
in classAbstractDataStorage
-
getMethodsByName
Description copied from class:AbstractDataStorage
return a list of methods that have the methodName- Overrides:
getMethodsByName
in classAbstractDataStorage
-
getObjectList
- Specified by:
getObjectList
in interfaceDataStorage
- 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 interfaceDataStorage
-
mapBaseFields
protected void mapBaseFields()Maps fields in the table to field variables -
loadObject
loads a record from the database into the given data object.- Specified by:
loadObject
in interfaceDataStorage
- Parameters:
id
- The identifier of the record/object to loadobjClass
- The class of the object to load- Returns:
- the loaded data object
-
loadObject
-
loadObjects
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
-
instantiateDataObject
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 retrievedfieldObj
- - represents the class that holds the data
-
loadObject
loads and object from the database based on the name of the object- Specified by:
loadObject
in interfaceDataStorage
- Overrides:
loadObject
in classAbstractDataStorage
- Parameters:
name
- The name of the object to loadobjClass
- the class of the object to load- Returns:
- returns the loaded object
-
findObject
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
- Specified by:
removeObject
in interfaceDataStorage
- Overrides:
removeObject
in classAbstractDataStorage
-
pack
public void pack() -
memoCompress
public void memoCompress() -
removeObject
removes an object from the database. and then packs the dbf file.- Specified by:
removeObject
in interfaceDataStorage
- Overrides:
removeObject
in classAbstractDataStorage
- Parameters:
objId
- The object identifier of the object to removeobjClass
- 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 interfaceDataStorage
- Overrides:
save
in classAbstractDataStorage
- Returns:
- true if successfull, otherwise false
-
doesExist
-
storeObject
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 interfaceDataStorage
-
appendData
-
writeCollection
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 interfaceDataStorage
- Overrides:
workspaceClosing
in classAbstractDataStorage
-
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
-
top
public boolean top()Moves to the top of the database -
end
public boolean end() -
getFilename
- Specified by:
getFilename
in interfaceDataStorage
- Overrides:
getFilename
in classAbstractDataStorage
-
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 interfaceDataStorage
- Overrides:
compress
in classAbstractDataStorage
-
reindex
- Throws:
IOException
-