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 booleanprotected Stringprotected intprotected codebase.Code4jniprotected codebase.Field4infoprotected codebase.Data4jniprotected DBFMappingClassprotected intprotected Mapprotected codebase.Tag4infoprotected codebase.Field4deleteFlagprotected static MessageFormatprotected Listprotected booleanprotected booleanprotected Identifierprotected longprotected booleanprotected DBFSerializableprotected Stringprotected Stringstatic final Doublestatic final Doublestatic final Floatstatic final Floatstatic final Integerstatic final Integerstatic final Longstatic final Longstatic booleanFields 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 TypeMethodDescriptionlongaddNewObject(Object obj) Adds a new object to the end of the DBF file.booleanappendData(Object obj) protected voidassignObjectValues(DBFSerializable dbfObj) booleanbackupData(String backupDir, DataObject obj) creats a backup of the dbf filecallNativeMethod(Object obj) This method is overridden and returns null.voidcompress()This method is used to compress a datafile.static codebase.Tag4infocreateTagInfo(DBFSerializable dbfObj) booleandoesExist(DBFSerializable dbfObj) booleanend()booleanfindObject(String tag, String key) Finds an object in the database for the given tag and contains the given key.intObject[]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 methodNameintgetObjectList(String objClass) booleaninit()initialize this DataStorageprotected ObjectinstantiateDataObject(codebase.Field4 data, Field fieldObj) This is a private method that is used to instantiate a java object based on the DBFSerializable object data.booleanloadObject(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.voidstatic voidprotected voidMaps fields in the table to field variablesvoidbooleanMoves to the next record in the database.intCalculates how many records are in the databasevoidpack()booleanvoidreindex()booleanremoveObject(long[] objIds, String objClass) booleanremoveObject(long objId, String objClass) removes an object from the database.booleansave()Saves the currently loaded record to the database.voidsetCheckForDifferences(boolean runCheck) voidsetInitialized(boolean b) booleanstoreObject(Object obj) Stores an object to the database.booleantop()Moves to the top of the databasevoidunlock()voidvoidReturns 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.Error4unexpectedcodebase.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:
addNewObjectin interfaceDataStorage- Overrides:
addNewObjectin 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:
backupDatain interfaceDataStorage- Overrides:
backupDatain 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:
callNativeMethodin interfaceDataStorage- Overrides:
callNativeMethodin 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:
getDataObjectIdListin interfaceDataStorage- Parameters:
objClass- The string representation of the object class
-
getObjectCount
public int getObjectCount()- Specified by:
getObjectCountin interfaceDataStorage- Overrides:
getObjectCountin classAbstractDataStorage
-
getMethodsByName
Description copied from class:AbstractDataStoragereturn a list of methods that have the methodName- Overrides:
getMethodsByNamein classAbstractDataStorage
-
getObjectList
- Specified by:
getObjectListin 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:DataStorageinitialize this DataStorage- Specified by:
initin 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:
loadObjectin 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:
loadObjectin interfaceDataStorage- Overrides:
loadObjectin 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:
removeObjectin interfaceDataStorage- Overrides:
removeObjectin classAbstractDataStorage
-
pack
public void pack() -
memoCompress
public void memoCompress() -
removeObject
removes an object from the database. and then packs the dbf file.- Specified by:
removeObjectin interfaceDataStorage- Overrides:
removeObjectin 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:
savein interfaceDataStorage- Overrides:
savein 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:
storeObjectin 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:
workspaceClosingin interfaceDataStorage- Overrides:
workspaceClosingin 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:
getFilenamein interfaceDataStorage- Overrides:
getFilenamein classAbstractDataStorage
-
compress
public void compress()Description copied from class:AbstractDataStorageThis 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:
compressin interfaceDataStorage- Overrides:
compressin classAbstractDataStorage
-
reindex
- Throws:
IOException
-