public class RecordLoader
extends java.lang.Object
PropertyMapper
objects, in the order the
mapped data is expected to be encountered in the export file for
each record (one per column, or one per subscript value for extent
columns);
An instance of this class is created for each table which needs to be
imported. The above properties are set as necessary, using the various
set, put, and add methods. Once the instance is fully configured, nextRecord(com.goldencode.p2j.util.Stream)
should be called repeatedly, until there are no more records
to process in the input data file.
Modifier and Type | Field and Description |
---|---|
private boolean |
checkTypes
Flag to enable assertions of type match for each data field
|
private java.io.File |
dataFile
Input data file - a Progress export (*.d) file
|
private java.util.Map<java.lang.String,PropertyMapper> |
mappersByProp
Property mappers which define column data, by property name
|
private java.util.List<PropertyMapper> |
properties
Property mappers which define column data
|
private java.lang.Class<?> |
recordClass
Class which is instantiated for each import record
|
Constructor and Description |
---|
RecordLoader(java.lang.Class recordClass,
java.io.File dataFile,
boolean checkTypes)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addProperty(PropertyMapper mapper)
Add a mapping for an individual column of data.
|
(package private) java.io.File |
getDataFile()
Retrieve the file containing the export data for the current table.
|
protected java.lang.String |
getDMOName()
Get the unqualified name of the DMO class associated with this record
loader.
|
PropertyMapper |
getProperty(java.lang.String property)
Get the mapper for a given property.
|
java.lang.Object |
nextRecord(Stream input)
Read a single record from the current location in a Progress export
file and store its data in a bean-like object.
|
protected void |
processNextValue(PropertyMapper mapper,
java.lang.Object record,
java.lang.Object value)
Process the data value most recently read from the data export file.
|
private final java.util.List<PropertyMapper> properties
private final java.util.Map<java.lang.String,PropertyMapper> mappersByProp
private java.lang.Class<?> recordClass
private java.io.File dataFile
private boolean checkTypes
public RecordLoader(java.lang.Class recordClass, java.io.File dataFile, boolean checkTypes)
Note: the checkTypes
flag should be set to
false
for normal operations. It is expensive and should
be enabled for debug purposes only.
recordClass
- Class which is instantiated for each record imported.dataFile
- Data input file.checkTypes
- true
to assert that the data type of each
field read matches the expected type.public void addProperty(PropertyMapper mapper)
mapper
- The helper object which defines the mapping.public PropertyMapper getProperty(java.lang.String property)
property
- The property name.public java.lang.Object nextRecord(Stream input) throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
PropertyMapper
objects stored in this loader
instance.
The checkTypes
functionality is not honored here
although this would be the correct location to add that feature.
input
- The export file to be read.null
if no more
records are available.java.lang.InstantiationException
- if any error occurs creating a new instance of the DMO
class.java.lang.IllegalAccessException
- if the record class, its default constructor, or a setter
method which we invoke is not accessible.java.lang.reflect.InvocationTargetException
- if there is any error invoking a setter method for an
individual record field.protected void processNextValue(PropertyMapper mapper, java.lang.Object record, java.lang.Object value) throws java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
mapper
- Mapping object associated with the current property.record
- Java-bean-like object which holds the contents of the record
currently being loaded.value
- Data value read from the data export file for the current
property. It has not yet been stored in the
record
object.java.lang.IllegalAccessException
- if the setter method which we invoke is not accessible.java.lang.reflect.InvocationTargetException
- if there is any error invoking the appropriate setter method.protected java.lang.String getDMOName()
java.io.File getDataFile()