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
Modifier and TypeFieldDescriptionstatic final String
static final String
Marker for byte storage column names (should be appended to the column name).static final String
In child tables, this is the child's class column.static final String
In child tables, this is the child's id column.static final String
Marker for child id column names (should be appended to the column name).static final String
Marker for children column names (should be appended to the column name).static final String
Marker for class types column names (should be appended to the column name).static final String
Name of the column used to identify objects.static final String
In child tables, this is the parent's identifier column.static final String
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). -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this data source.protected abstract void
endTypeRead
(Class clazz) Finishes the reading of the specified class.protected abstract void
Ends the reading of the children for the specifiedFreezeDryedObject
.protected abstract void
finishChildrenWrite
(FreezeDryedObject object) Finishes the writing of the children for the specifiedFreezeDryedObject
.protected abstract void
finishTypeWrite
(FreezeDryedObject object) Finishes the writing of the specifiedFreezeDryedObject
.protected String
getArrayType
(String field) protected Object
getArrayValue
(String arrayType, Object val) protected String
Retrieves the fields for a specified type.protected abstract Object
getFieldValue
(X row, String field) Retrieves the value of the specified field in the specified row of data.protected String
getTrueFieldName
(String field, String marker) protected String
protected String
getType
(FreezeDryedObject object) protected String
getValue
(char[] value) protected String
protected String
protected String
getValueArray
(Object value) protected String[]
protected FreezeDryedParentChild
parseChildRow
(FreezeDryedObject fdo, X childsRow) protected FreezeDryedObject
protected 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 void
protected abstract X
readChildsRow
(FreezeDryedObject parent, String id) Reads in a row of data about a child of the specifiedFreezeDryedObject
.protected FreezeDryedParentChild
readFreezeDryedParentChild
(FreezeDryedObject parent, String className, String childId) protected abstract X
Reads in a row of data that will be parsed by the use ofgetFieldValue(X, String)
andgetFields(String)
.void
reset()
Resets this data source.protected abstract void
Initializes the reading of the children of a specifiedFreezeDryedObject
.protected abstract void
Initiates the writing of the children for the specifiedFreezeDryedObject
.protected abstract void
startTypeRead
(Class clazz) Initiates the reading of the specified class.protected abstract void
This is called at the start of a call to write.void
write
(FreezeDryedObject object) protected abstract Object
writeByteArray
(FreezeDryedObject fdo, String fieldName, byte[] bs) Writes a byte array retrieved from the specifiedFreezeDryedObject
with the specified fieldName.protected abstract void
writeChildData
(FreezeDryedObject fdo, HashMap<String, Object> child) Writes the data for a child of the specifiedFreezeDryedObject
.protected void
protected abstract void
writeRow
(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
- theFreezeDryedObject
who 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
- theFreezeDryedObject
that 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 specifiedFreezeDryedObject
with 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
- theFreezeDryedObject
that 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
- theFreezeDryedObject
whose 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
- theFreezeDryedObject
whose 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:
reset
in interfaceFreezeDryedDataSource
-
close
Closes this data source.- Specified by:
close
in interfaceFreezeDryedDataSource
- Throws:
FreezeDryingException
-
write
- Specified by:
write
in 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:
read
in interfaceFreezeDryedDataSource
- Throws:
FreezeDryingException
-
read
- Specified by:
read
in interfaceFreezeDryedDataSource
- Throws:
FreezeDryingException
-
getChildrenColumnName
-