public abstract class AbstractBusinessObjectMediator extends java.lang.Object implements BusinessObjectMediator
The main function of the business object mediator is to call ID resolver to resolve keys and also determine whether it is a new object or an existing object.
The business object mediator will call the configured DataWriter to write the data out to the data store.
The business object builder will call the business object mediator in the following sequence:
Constructor and Description |
---|
AbstractBusinessObjectMediator() |
Modifier and Type | Method and Description |
---|---|
protected void | addExtraTable(TableDataObject tableDO)
Adds extra table data object to be saved during the mediator close time.
|
protected void | addPhysicalObjects(java.util.List tableDOList)
Add a list of physicall objects to be persisted.
|
protected void | addToBaseTableDataObjects(TableDataObject tableDO)
Add the tableDO to the base table data object list
|
protected boolean | checkId(java.lang.String tableName, java.util.Map primaryKeyMap)
Check the primary key to see if the row exists in the database or not.
|
protected void | clearUniqueID()
This method will clear the unique ID in the noun managed by the mediator.
|
void | close()
This method will perform cleanup on the business object mediator.
|
protected TableDataObject | createBaseTableDataObjectWithUniqueIndex(java.lang.String tableName, java.util.Map uniqueIndexValueMap)
Create the base table object.
|
protected TableDataObject | createTableDataObject(java.lang.String tableName)
This method creates a table data object,TableDataObject representing a physical table.
|
protected TableDataObject | createTableDataObjectWithGenratedPrimaryKey(java.lang.String tableName)
Create a table data object with the generated value of the primary key.
|
protected TableDataObject | createTableDataObjectWithPrimary(java.lang.String tableName, java.util.Map primaryKeyValueMap)
Create a table data object with the primary key data.
|
protected TableDataObject | createTableDataObjectWithUniqueIndex(java.lang.String tableName, java.util.Map uniqueIndexValueMap)
This method creates a table data object,TableDataObject representing a physical table.
|
protected void | deleteTableDataObject(TableDataObject tableDataObject)
This method sets the opMode for the tableDataObject to 'D' if the opMode is not set yet.
|
protected void | determineOperationModeForPhysicalObjects()
This method will determine the correct operation mode data load should use to persist the physical object.
|
protected void | echoChangeHistory(int action)
This method records the changes into the database.
|
void | execute(java.lang.Object obj)
It calls the transform() method to transform the logic noun to a list of physical objects.
|
protected java.lang.String | formatTimestampString(java.lang.String timestampString, java.lang.String fieldName, java.lang.String path)
Checks whether the timestamp value format is of the format, java.sql.Types.TIMESTAMP.
|
protected java.lang.String | getActionString()
It checks the main physical object to see if it is insert, update or delete to return the corresponding action string.
|
ConfigProperties | getConfigProperties()
Returns the instance of the ConfigProperties of the BusinessObjectWriter.
|
protected java.lang.String | getDataLoadMode()
Get the data load mode to be used by the subclasses.
|
protected java.lang.Object | getDataObject(java.lang.Object obj)
Gets the data object from the obj which is a DataLoadBusinessObject.
|
protected DataWriter | getDataWriter()
Gets the data writer.
|
protected boolean | getDeleteFlag(java.lang.Object obj)
Gets the delete flag from the obj which is a DataLoadBusinessObject.
|
java.lang.Long | getEndKey()
Returns the end key.
|
protected IDResolver | getIdResolver()
This method returns an instance of the configured ID resolver for data load.
|
protected java.lang.Object | getInputData()
Gets the input data from the DataReader.
|
protected java.lang.Object | getInputData(java.lang.Object obj)
Gets the input data object from the obj which is a DataLoadBusinessObject.
|
protected TableDataObject | getMainPhysicalObject()
Gets the main physical object.
|
protected java.lang.Object | getMediatorContext(java.lang.String name)
Gets the value from mediator context, which may be set by the previous mediator if there are multiple mediators defined in the configuration file.
|
protected java.util.List | getPhysicalObjects()
This method returns a list of physical objects that this business object mediator will be persisting.
|
java.lang.Long | getStartKey()
Returns the start key.
|
protected java.lang.String | getUniqueId()
It always returns null in this class.
|
protected boolean | handleSoftErrorOnDelete(DataLoadApplicationException ex)
Handles the soft error on delete.
|
void | init()
This method performs some initialization for the business object mediator.
|
ConfigProperties | initConfig(org.w3c.dom.Node businessObjectMediatorNode, ConfigProperties parentConfigProperties)
This method parses the BusinessObjectMediator xml node read in from the business object configuration file and stores the configuration in memory.
|
protected boolean | isDelete()
This method returns true if the delete flag was found in the supplied configuration.
|
protected boolean | isInsertMode()
This method will check if the data load mode is insert.
|
protected boolean | isPhysicalObjectSortRequired()
Check if the list of physical objects need to be sorted before passed to the data writer.
|
protected boolean | isUpdateMode()
Checks if the data load is running in the update mode.
|
protected boolean | isWorkspaceEnabled()
This method returns true if and only if the workspace is enabled.
|
protected void | lock(java.lang.Object nounPart)
This method will lock a business object by calling the lock(nounPart, action) method.
|
protected void | lock(java.lang.Object nounPart, short action)
This method will lock a business object to protect it from conflicting changes.
|
protected void | populateUserData(java.lang.Object nounPart, java.lang.Object userData, TableDataObject parentTableDataObject)
This method will populate the user data for a custom extension table.
|
void | postProcess()
This method performs any post processing of the data after the data has been written to the data store.
|
void | preProcess(java.lang.Object bod)
This method performs any pre-processing of the data if needed.
|
protected void | processDataWriter(DataWriter dataWriter, java.lang.Object physicalObjects)
Calls the data writer to save the physical objects.
|
protected void | reset()
Reset any instance variables.
|
protected java.lang.String | resolveId(java.lang.String tableName, java.util.Map uniqueIndexValueMap, boolean bGenerateNewKey)
This method will call resolveIds() to get the primary key map and then get the primary key value from the map.
|
protected java.util.Map | resolveIds(java.lang.String tableName, java.util.Map uniqueIndexValueMap, boolean generateNewKey)
This method will resolve identifiers for a physical object with multiple primary key columns.
|
protected void | setBaseTableObjectEnabled(boolean enabled)
Sets the base table object feature enabled or not.
|
void | setConfigProperties(ConfigProperties aConfigProperties)
Sets the configuration properties for this business object mediator.
|
protected void | setMediatorContext(java.lang.String name, java.lang.Object value)
Sets the mediator context name and value, which may be used by the next mediator if there are multiple mediators defined in the configuration file.
|
protected void | setNumberOfActiveWorkspaces()
This method retrieves the number of active workspaces from the database table CMFWKSPC.
|
protected java.util.List | sortPhysicalObjects(java.util.List aListOfPhysicalObjects)
Sort the list of physical object if isPhysicalObjectSortRequired() is true, batchSize is 1, and the size of the list is greater than 1.
|
protected abstract void | transform(java.lang.Object dataObject, boolean deleteFlag)
This method is responsible for transforming a logical data object into a list physical objects.
|
protected void | updateOperationModeForWorkspace()
Updates the operation mode for all the TableDataObjects in the list iListOfPhysicalObjects.
|
protected void | validateColumnValueLength(java.lang.String tableName, java.lang.String columnName, java.lang.String columnValue, java.lang.String fieldName, java.lang.String path)
Check the column value to see if it exceeds the column size.
|
protected void | validateColumnValueType(int columnType, java.lang.String columnValue, java.lang.String fieldName, java.lang.String path)
Check the column value format to see if it is valid for the column type.
|
protected void | validateLanguageId(java.lang.String langId)
Validate if the langId is a valid language ID in the language table.
|
public ConfigProperties getConfigProperties()
Returns the instance of the ConfigProperties of the BusinessObjectWriter.
Call this method when you need to get specific properties from the configuration properties.
public java.lang.Long getStartKey()
Returns the start key.
public java.lang.Long getEndKey()
Returns the end key.
public void setConfigProperties(ConfigProperties aConfigProperties)
Sets the configuration properties for this business object mediator.
This method is not normally called unless overriding the configuration properties for this business object mediator is required.
public ConfigProperties initConfig(org.w3c.dom.Node businessObjectMediatorNode, ConfigProperties parentConfigProperties) throws DataLoadException
This method parses the BusinessObjectMediator xml node read in from the business object configuration file and stores the configuration in memory.
public void init() throws DataLoadException
This method performs some initialization for the business object mediator.
The values for the batch size, commit count, start key, end key as well as a list of data writers will be attained from the data load configuration.
If any subclasses wish to override this method, then this init() method should be called from the subclass.
public void preProcess(java.lang.Object bod) throws DataLoadException
This method performs any pre-processing of the data if needed. This default implementation performs no function.
The subclass should implement this method only if any pre-processing of the populated data object is needed.
public void execute(java.lang.Object obj) throws DataLoadException
protected void processDataWriter(DataWriter dataWriter, java.lang.Object physicalObjects) throws DataLoadException
protected void populateUserData(java.lang.Object nounPart, java.lang.Object userData, TableDataObject parentTableDataObject) throws DataLoadException
This method will populate the user data for a custom extension table.
public void postProcess() throws DataLoadException
This method performs any post processing of the data after the data has been written to the data store. This default implementation performs no function.
Sub classes should implement this method only if any post processing of the data loaded is needed.
public void close() throws DataLoadException
This method will perform cleanup on the business object mediator. It will attempt to close all of the data writers configured for this business object mediator.
This method will flush and commit any data waiting to be persisted in the batch as well as clear the ID resolver cache.
protected abstract void transform(java.lang.Object dataObject, boolean deleteFlag) throws DataLoadException
This method is responsible for transforming a logical data object into a list physical objects.
It is called by the execute method.
protected boolean isDelete()
This method returns true if the delete flag was found in the supplied configuration.
protected boolean isInsertMode()
This method will check if the data load mode is insert.
protected TableDataObject createTableDataObject(java.lang.String tableName)
This method creates a table data object,TableDataObject representing a physical table. After the table data object is created, it will be added to the list of physical objects maintained by this business object mediator.
Child business object mediator classes should call this method initially to create a physical table object, and use the TableDataObject to populate additional information about the physical table.
Example:
protected TableDataObject createTableDataObjectWithUniqueIndex(java.lang.String tableName, java.util.Map uniqueIndexValueMap) throws DataLoadException
This method creates a table data object,TableDataObject representing a physical table. After the table data object is created, it will be added to the list of physical objects maintained by this business object mediator.
Child business object mediator classes should call this method initially to create a physical table object, and use the TableDataObject to populate additional information about the physical table.
Example:
protected TableDataObject createBaseTableDataObjectWithUniqueIndex(java.lang.String tableName, java.util.Map uniqueIndexValueMap) throws DataLoadException
Create the base table object. It calls ID resolver to resolve the primary key based on the unique index value map.
After the primary key is resolved, it populates the primary key and unique index data to newly created table data object.
The base table is a table which is the parent table for all other tables during the data load. Each logic noun, it usually has one base table. For example, for a CatalogEntry noun, the CATENTRY table is a base table. For CatalogGroup noun, the CATGROUP table is a base table. If the table is not a base table, the other equivalent method createTableDataObjectWithUniqueIndex should be used.
The main purpose of creating a base table is for performance reason. When a subclass mediator create a base table, and if the base table is new in the database, we assume all other tables are also new. It saves us time to check the database to decide whether we should use insert or update statement for every table data object created by the subclass. If there is no base table created, we need to check each table data object in the database to see whether it is new or old and we generate corresponding insert or update statements. If a table is not a base table and the subclass call this method to create it as a base table, it will potentially cause the duplicate key error.
Example:
protected TableDataObject createTableDataObjectWithPrimary(java.lang.String tableName, java.util.Map primaryKeyValueMap) throws DataLoadException
protected boolean checkId(java.lang.String tableName, java.util.Map primaryKeyMap) throws DataLoadException
protected java.lang.String resolveId(java.lang.String tableName, java.util.Map uniqueIndexValueMap, boolean bGenerateNewKey) throws DataLoadException
This method will call resolveIds() to get the primary key map and then get the primary key value from the map. It can only be called if the primary key only contains one column. If the primary key contains multiple columns, it will return null.
protected java.util.Map resolveIds(java.lang.String tableName, java.util.Map uniqueIndexValueMap, boolean generateNewKey) throws DataLoadException
This method will resolve identifiers for a physical object with multiple primary key columns.
protected IDResolver getIdResolver()
This method returns an instance of the configured ID resolver for data load.
protected java.util.List getPhysicalObjects()
This method returns a list of physical objects that this business object mediator will be persisting.
protected void deleteTableDataObject(TableDataObject tableDataObject) throws DataLoadException
This method sets the opMode for the tableDataObject to 'D' if the opMode is not set yet. It will be deleted by the physical data writer.
protected void determineOperationModeForPhysicalObjects() throws DataLoadException
This method will determine the correct operation mode data load should use to persist the physical object.
The data load operation mode will be set initially from the configuration but will be recalculated.
Supported modes are:
protected java.lang.String getDataLoadMode()
protected boolean isUpdateMode()
protected void validateColumnValueLength(java.lang.String tableName, java.lang.String columnName, java.lang.String columnValue, java.lang.String fieldName, java.lang.String path) throws DataLoadException
protected void validateColumnValueType(int columnType, java.lang.String columnValue, java.lang.String fieldName, java.lang.String path) throws DataLoadException
protected void validateLanguageId(java.lang.String langId) throws DataLoadException
protected java.lang.String formatTimestampString(java.lang.String timestampString, java.lang.String fieldName, java.lang.String path) throws DataLoadException
protected void reset()
protected void addPhysicalObjects(java.util.List tableDOList)
protected void addToBaseTableDataObjects(TableDataObject tableDO)
protected boolean isPhysicalObjectSortRequired()
protected java.util.List sortPhysicalObjects(java.util.List aListOfPhysicalObjects) throws DataLoadException
protected void updateOperationModeForWorkspace() throws DataLoadException
protected boolean isWorkspaceEnabled()
protected void clearUniqueID()
This method will clear the unique ID in the noun managed by the mediator.
This super class will perform no function and this method should be implemented by any extension mediator to clear the unique ID if it is necessary.
protected void lock(java.lang.Object nounPart) throws DataLoadException
This method will lock a business object by calling the lock(nounPart, action) method.
The action is ChangeControlBusinessObjectMediator.ACTION_DELETE if the delete flag is set. Otherwise, the action is ChangeControlBusinessObjectMediator.ACTION_UPDATE.
The noun part can be the noun when locking the noun.
protected void lock(java.lang.Object nounPart, short action) throws DataLoadException
This method will lock a business object to protect it from conflicting changes. The business object will be checked for previous locks before a new lock is obtained.
The action is ChangeControlBusinessObjectMediator.ACTION_DELETE if the delete flag is set. Otherwise, the action is ChangeControlBusinessObjectMediator.ACTION_UPDATE.
The noun part can be the noun when locking the noun.
protected void echoChangeHistory(int action)
protected java.lang.String getActionString()
protected TableDataObject getMainPhysicalObject()
protected void setNumberOfActiveWorkspaces() throws DataLoadException
This method retrieves the number of active workspaces from the database table CMFWKSPC. This value is set to the instance variable iWorkspaceCount for later use.
protected TableDataObject createTableDataObjectWithGenratedPrimaryKey(java.lang.String tableName) throws DataLoadException
protected boolean handleSoftErrorOnDelete(DataLoadApplicationException ex) throws DataLoadApplicationException
protected java.lang.Object getInputData()
protected java.lang.String getUniqueId()
protected void addExtraTable(TableDataObject tableDO)
protected DataWriter getDataWriter()
protected java.lang.Object getDataObject(java.lang.Object obj)
protected java.lang.Object getInputData(java.lang.Object obj)
protected boolean getDeleteFlag(java.lang.Object obj)
protected java.lang.Object getMediatorContext(java.lang.String name)
protected void setMediatorContext(java.lang.String name, java.lang.Object value)
protected void setBaseTableObjectEnabled(boolean enabled)