Package repast.simphony.freezedry
Class AbstractDataSource<X>
java.lang.Object
repast.simphony.freezedry.AbstractDataSource<X>
- All Implemented Interfaces:
FreezeDryedDataSource
- Direct Known Subclasses:
DelimitedFileDataSource,JDBCDataSource
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringMarker for byte storage column names (should be appended to the column name).static final StringIn child tables, this is the child's class column.static final StringIn child tables, this is the child's id column.static final StringMarker for child id column names (should be appended to the column name).static final StringMarker for children column names (should be appended to the column name).static final StringMarker for class types column names (should be appended to the column name).static final StringName of the column used to identify objects.static final StringIn child tables, this is the parent's identifier column.static final StringThis should be pre-pended to column names that will be interpreted in a "special" way (IE used to identify an object, or as a reference to another table). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this data source.protected abstract voidendTypeRead(Class clazz) Finishes the reading of the specified class.protected abstract voidEnds the reading of the children for the specifiedFreezeDryedObject.protected abstract voidfinishChildrenWrite(FreezeDryedObject object) Finishes the writing of the children for the specifiedFreezeDryedObject.protected abstract voidfinishTypeWrite(FreezeDryedObject object) Finishes the writing of the specifiedFreezeDryedObject.protected StringgetArrayType(String field) protected ObjectgetArrayValue(String arrayType, Object val) protected StringRetrieves the fields for a specified type.protected abstract ObjectgetFieldValue(X row, String field) Retrieves the value of the specified field in the specified row of data.protected StringgetTrueFieldName(String field, String marker) protected Stringprotected StringgetType(FreezeDryedObject object) protected StringgetValue(char[] value) protected Stringprotected Stringprotected StringgetValueArray(Object value) protected String[]protected FreezeDryedParentChildparseChildRow(FreezeDryedObject fdo, X childsRow) protected FreezeDryedObjectprotected abstract byte[]readByteArray(FreezeDryedObject fdo, String field, Object bytesId) Reads in a byte[] that corresponds to the specified bytesId and will be loaded into the specified fdo through the specified field.protected voidprotected abstract XreadChildsRow(FreezeDryedObject parent, String id) Reads in a row of data about a child of the specifiedFreezeDryedObject.protected FreezeDryedParentChildreadFreezeDryedParentChild(FreezeDryedObject parent, String className, String childId) protected abstract XReads in a row of data that will be parsed by the use ofgetFieldValue(X, String)andgetFields(String).voidreset()Resets this data source.protected abstract voidInitializes the reading of the children of a specifiedFreezeDryedObject.protected abstract voidInitiates the writing of the children for the specifiedFreezeDryedObject.protected abstract voidstartTypeRead(Class clazz) Initiates the reading of the specified class.protected abstract voidThis is called at the start of a call to write.voidwrite(FreezeDryedObject object) protected abstract ObjectwriteByteArray(FreezeDryedObject fdo, String fieldName, byte[] bs) Writes a byte array retrieved from the specifiedFreezeDryedObjectwith the specified fieldName.protected abstract voidwriteChildData(FreezeDryedObject fdo, HashMap<String, Object> child) Writes the data for a child of the specifiedFreezeDryedObject.protected voidprotected abstract voidwriteRow(FreezeDryedObject object, Map<String, Object> row) This writes a row of data out which was generated by the specifiedFreezeDryedObject.
-
Field Details
-
SPECIAL_COL_MARKER
This should be pre-pended to column names that will be interpreted in a "special" way (IE used to identify an object, or as a reference to another table).- See Also:
-
CHILDREN_MARKER
Marker for children column names (should be appended to the column name).- See Also:
-
BYTES_MARKER
Marker for byte storage column names (should be appended to the column name).- See Also:
-
CLASS_MARKER
Marker for class types column names (should be appended to the column name).- See Also:
-
CHILD_ID_MARKER
Marker for child id column names (should be appended to the column name).- See Also:
-
ID_COL
Name of the column used to identify objects.- See Also:
-
PARENT_ID_COL
In child tables, this is the parent's identifier column.- See Also:
-
CHILD_CLASS_COL
In child tables, this is the child's class column.- See Also:
-
CHILD_ID_COL
In child tables, this is the child's id column.- See Also:
-
ARRAY_MARKER
- See Also:
-
-
Constructor Details
-
AbstractDataSource
public AbstractDataSource()
-
-
Method Details
-
startTypeWrite
This is called at the start of a call to write. This should cause any needed preparation for reading this type to occur. It will be followed by calls towriteRow(FreezeDryedObject, Map)and a call tofinishTypeWrite(FreezeDryedObject).- Parameters:
fdo- theFreezeDryedObjectwho will begin to be written- Throws:
FreezeDryingException- when there's an error
-
writeRow
protected abstract void writeRow(FreezeDryedObject object, Map<String, Object> row) throws FreezeDryingExceptionThis writes a row of data out which was generated by the specifiedFreezeDryedObject. This will be preceded by acall and will be followed by calls to {@link #writeRow(FreezeDryedObject, Map)} and a call to {@link #finishTypeWrite(FreezeDryedObject)}.- Parameters:
fdo- theFreezeDryedObjectthat the row of data came fromrow- the data for the specifiedFreezeDryedObject- Throws:
FreezeDryingException- when there's an error
-
writeByteArray
protected abstract Object writeByteArray(FreezeDryedObject fdo, String fieldName, byte[] bs) throws FreezeDryingException Writes a byte array retrieved from the specifiedFreezeDryedObjectwith the specified fieldName.- Parameters:
fdo- the source of the datafieldName- the field this data is assosciated withbs- the data itself- Returns:
- the value to be written to the subclass for the fieldName (this could potentially just be an id, or it could just be the bytes themselves)
- Throws:
FreezeDryingException
-
startChildrenWrite
Initiates the writing of the children for the specifiedFreezeDryedObject.- Parameters:
fdo- thewhose children will be written- Throws:
FreezeDryingException
-
writeChildData
protected abstract void writeChildData(FreezeDryedObject fdo, HashMap<String, Object> child) throws FreezeDryingExceptionWrites the data for a child of the specifiedFreezeDryedObject.- Parameters:
fdo- the parentchild- the data from the child- Throws:
FreezeDryingException
-
finishChildrenWrite
Finishes the writing of the children for the specifiedFreezeDryedObject.- Parameters:
fdo- thewhose children were written- Throws:
FreezeDryingException
-
finishTypeWrite
Finishes the writing of the specifiedFreezeDryedObject. This will be preceded by acall and calls to {@link #writeRow(FreezeDryedObject, Map)} (along with the other child and byte methods).- Parameters:
fdo- theFreezeDryedObjectthat the row of data came from- Throws:
FreezeDryingException- when there's an error
-
startTypeRead
Initiates the reading of the specified class. This class represents is of a type that was at some point written out through aFreezeDryedObject.- Parameters:
clazz- the class that was the type returned byFreezeDryedObject.getType()- Throws:
FreezeDryingException
-
readRow
Reads in a row of data that will be parsed by the use ofgetFieldValue(X, String)andgetFields(String). If the data source can find an object with the specified key it should return data for reading that object, otherwise it may return any object.- Parameters:
clazz- the class the data will be used forkey- the key of the object we're looking for, if null it should be ignored- Returns:
- a row of data
- Throws:
FreezeDryingException
-
readByteArray
protected abstract byte[] readByteArray(FreezeDryedObject fdo, String field, Object bytesId) throws FreezeDryingException Reads in a byte[] that corresponds to the specified bytesId and will be loaded into the specified fdo through the specified field.- Parameters:
fdo- the object that the bytes are going to be stored infield- the field the bytes[] are forcolumnValue- the value in the row of data for the field (the return of awriteByteArray(FreezeDryedObject, String, byte[])- Returns:
- the read in byte[]
- Throws:
FreezeDryingException
-
getFields
Retrieves the fields for a specified type. Generally these should be read in and stored during thestartTypeRead(Class)call.- Parameters:
type- the type of theFreezeDryedObject(fromgetType(Class)).- Returns:
- the list of fields of that type
- Throws:
FreezeDryingException
-
getFieldValue
Retrieves the value of the specified field in the specified row of data.- Parameters:
row- the row (returned by#readRow(Class)).field- the field we're reading- Returns:
- the value of that field
- Throws:
FreezeDryingException
-
startChildrenRead
Initializes the reading of the children of a specifiedFreezeDryedObject.- Parameters:
fdo- theFreezeDryedObjectwhose children will be read- Throws:
FreezeDryingException
-
readChildsRow
protected abstract X readChildsRow(FreezeDryedObject parent, String id) throws FreezeDryingException Reads in a row of data about a child of the specifiedFreezeDryedObject.- Parameters:
parent- the parent of the child that will be readid- the id of the child we're concerned with- Returns:
- a row of data on the child
- Throws:
FreezeDryingException
-
finishChildrenRead
Ends the reading of the children for the specifiedFreezeDryedObject.- Parameters:
fdo- theFreezeDryedObjectwhose children have been read
-
endTypeRead
Finishes the reading of the specified class.- Parameters:
clazz- the class whose reading has completed
-
reset
public void reset()Resets this data source.- Specified by:
resetin interfaceFreezeDryedDataSource
-
close
Closes this data source.- Specified by:
closein interfaceFreezeDryedDataSource- Throws:
FreezeDryingException
-
write
- Specified by:
writein interfaceFreezeDryedDataSource- Throws:
FreezeDryingException
-
getValueArray
-
writeChildren
- Throws:
FreezeDryingException
-
getType
-
getType
-
getValue
-
getValue
-
getValue
-
getColumns
-
pair
-
getColumnKeysetPairs
-
parseRow
- Throws:
FreezeDryingException
-
getArrayValue
-
getArrayType
-
getTrueFieldName
-
readFreezeDryedParentChild
protected FreezeDryedParentChild readFreezeDryedParentChild(FreezeDryedObject parent, String className, String childId) throws ClassNotFoundException - Throws:
ClassNotFoundException
-
readChildren
protected void readChildren(FreezeDryedObject fdo) throws ClassNotFoundException, FreezeDryingException -
parseChildRow
protected FreezeDryedParentChild parseChildRow(FreezeDryedObject fdo, X childsRow) throws ClassNotFoundException, FreezeDryingException -
read
- Specified by:
readin interfaceFreezeDryedDataSource- Throws:
FreezeDryingException
-
read
- Specified by:
readin interfaceFreezeDryedDataSource- Throws:
FreezeDryingException
-
getChildrenColumnName
-