net.sourceforge.datagenerator
Class EntityGenerator

java.lang.Object
  extended bynet.sourceforge.datagenerator.EntityGenerator

public class EntityGenerator
extends java.lang.Object

The EntityGenerator generates data for all the given entities. It manages the dependencies between each entity.

Version:
0.6
Author:
Chris Nagy

Field Summary
protected static org.apache.commons.logging.Log LOG
          The log for debug information.
 
Constructor Summary
EntityGenerator()
           
 
Method Summary
 void addDataGeneratorListener(DataGeneratorListener listener)
          Adds a data generator listener.
 void buildDependencyMap(GenerateEntityDef[] entities)
          Build the dependency map between entities.
protected  void deleteRowFromDisk(java.lang.String entityName, int row)
          Delete a given row from temporary storage.
protected  void fillInColumnTypes(EntityDef entityDef)
          Fill in the column SQL Types that are missing.
protected  ColumnValue[] fillInValues(EntityDef entityDef, ColumnValue[] values)
          Returns the transformed column values.
protected  net.sourceforge.datagenerator.GenerateColumnState findColumn(net.sourceforge.datagenerator.GenerateEntityState entityState, java.lang.String columnName)
          Find the state of the column's generation of data.
protected  void fireDataGeneratorEntityEvent(DataGeneratorEntityEvent e)
          Fire a data generator entity event to the listeners.
protected  void fireDataGeneratorRowEvent(DataGeneratorRowEvent e)
          Fire a data generator row event to the listeners.
protected  int loadExportSourceValues(net.sourceforge.datagenerator.GenerateEntityState entityState)
          Load the source values for a given entity from the database.
protected  int loadImportSourceValues(net.sourceforge.datagenerator.GenerateEntityState entityState)
          Load the source values for a given entity from a file.
protected  void loadSourceValues(net.sourceforge.datagenerator.GenerateColumnState state)
          Load the source values for a given column.
 void processEntities(GenerateEntityDef[] entities)
          Process the given entity definitions.
protected  void processEntity(net.sourceforge.datagenerator.GenerateEntityState entityState, boolean readFromTmp)
          Process the current entity state by generating data for the columns.
protected  void readRowFromDisk(java.lang.String entityName, int row, ColumnValue[] values)
          Read a given row to from a temporary file.
 void removeDataGeneratorListener(DataGeneratorListener listener)
          Removes a data generator listener.
 void setConnection(java.sql.Connection con)
          Set the connection.
 void setSourceEntities(EntityDef[] entities)
          Sets the source entities whose data will be used to fill dependent column values.
protected  void writeRowToDisk(java.lang.String entityName, int row, ColumnValue[] values)
          Write a given row to a temporary file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static org.apache.commons.logging.Log LOG
The log for debug information.

Constructor Detail

EntityGenerator

public EntityGenerator()
Method Detail

setConnection

public void setConnection(java.sql.Connection con)
Set the connection.

Parameters:
con - the connection

setSourceEntities

public void setSourceEntities(EntityDef[] entities)
Sets the source entities whose data will be used to fill dependent column values.

Parameters:
entities - the list of entities

buildDependencyMap

public void buildDependencyMap(GenerateEntityDef[] entities)
Build the dependency map between entities.

Parameters:
entities - the entity definitions

findColumn

protected net.sourceforge.datagenerator.GenerateColumnState findColumn(net.sourceforge.datagenerator.GenerateEntityState entityState,
                                                                       java.lang.String columnName)
Find the state of the column's generation of data.

Parameters:
entityState - the entity state that is requesting the state
columnName - the name of the column (could be fully qualified or local to the given entity state)
Returns:
the state of the column's generator of data.

processEntities

public void processEntities(GenerateEntityDef[] entities)
Process the given entity definitions.

Parameters:
entities - the entity definitions

addDataGeneratorListener

public void addDataGeneratorListener(DataGeneratorListener listener)
Adds a data generator listener.

Parameters:
listener - the listener

removeDataGeneratorListener

public void removeDataGeneratorListener(DataGeneratorListener listener)
Removes a data generator listener.

Parameters:
listener - the listener

fireDataGeneratorRowEvent

protected void fireDataGeneratorRowEvent(DataGeneratorRowEvent e)
Fire a data generator row event to the listeners.

Parameters:
e - the data generator row event

fireDataGeneratorEntityEvent

protected void fireDataGeneratorEntityEvent(DataGeneratorEntityEvent e)
Fire a data generator entity event to the listeners.

Parameters:
e - the data generator entity event

processEntity

protected void processEntity(net.sourceforge.datagenerator.GenerateEntityState entityState,
                             boolean readFromTmp)
Process the current entity state by generating data for the columns.

Parameters:
entityState - the current entity state
readFromTmp - whether to read the already generated column values from a tmp file.

loadSourceValues

protected void loadSourceValues(net.sourceforge.datagenerator.GenerateColumnState state)
Load the source values for a given column.

Parameters:
state - The column's state

loadImportSourceValues

protected int loadImportSourceValues(net.sourceforge.datagenerator.GenerateEntityState entityState)
                              throws java.sql.SQLException,
                                     java.io.IOException
Load the source values for a given entity from a file.

Parameters:
entityState - the entity's state
Returns:
the number of rows loaded
Throws:
java.sql.SQLException - thrown if the db column translators could not be setup or cleaned up
java.io.IOException - thrown if the file could not be parsed properly

loadExportSourceValues

protected int loadExportSourceValues(net.sourceforge.datagenerator.GenerateEntityState entityState)
                              throws java.sql.SQLException
Load the source values for a given entity from the database.

Parameters:
entityState - the entity's state
Returns:
the number of rows loaded
Throws:
java.sql.SQLException - thrown if the data could not be retrieved from the database

deleteRowFromDisk

protected void deleteRowFromDisk(java.lang.String entityName,
                                 int row)
Delete a given row from temporary storage.

Parameters:
entityName - the name of the entity
row - the row number

writeRowToDisk

protected void writeRowToDisk(java.lang.String entityName,
                              int row,
                              ColumnValue[] values)
Write a given row to a temporary file.

Parameters:
entityName - the name of the entity
row - the row number
values - the values

readRowFromDisk

protected void readRowFromDisk(java.lang.String entityName,
                               int row,
                               ColumnValue[] values)
Read a given row to from a temporary file.

Parameters:
entityName - the name of the entity
row - the row number
values - the values to read into

fillInColumnTypes

protected void fillInColumnTypes(EntityDef entityDef)
                          throws java.sql.SQLException
Fill in the column SQL Types that are missing.

Parameters:
entityDef - the entity definition
Throws:
java.sql.SQLException - thrown if the SQL Types could not be retrieved

fillInValues

protected ColumnValue[] fillInValues(EntityDef entityDef,
                                     ColumnValue[] values)
                              throws MalformedDataException
Returns the transformed column values.

Parameters:
entityDef - the entity definition
values - the rows' values
Returns:
column values the rows' values with defaults and column transformers applied.
Throws:
MalformedDataException - if the rows' values are incorrect