String valuesList = "'";
// 3 for each field, depending on his data type choose the right generator type to use
for(int j=0;j<tableFieldsInfoList.size();j++)
{
MetadataTableInfoBean field = tableFieldsInfoList.get(j);
currentFieldName = field.getFieldName();
fieldHasChild = false;
// the type of the current field ( eg varchar(10) bigint(10) )
String fieldType = field.getFieldType();
String childColumn = null;
String childTable = null;
if(Log4jManager.IS_LOGGING_CONFIGURED)
logger.debug("Current field: "+currentFieldName +" of Type:"+fieldType);
// check if the current field has child
for(TableFKconstraintsBean fkInfoList:tableFKinfoList)
{
//true if the current field point another table
if(fkInfoList.getParentColumnName().equalsIgnoreCase(currentFieldName)) {
fieldHasChild = true;
//get who is the referenced column+table pair
childColumn = fkInfoList.getReferencedColumnName();
childTable = fkInfoList.getReferencedTableName();
}
}
/**
* Note the child table is already filled because our table list is in the filling order
*/
if(fieldHasChild && childTable !=null && childColumn !=null)
{
if(Log4jManager.IS_LOGGING_CONFIGURED)
logger.info("- Table "+currentTable+"("+currentFieldName+") references the Table:"+childTable+"("+childColumn+") ");
/* the fields with "auto_increment" option don't appear in the insert query: is mysql that generate his value */
if(!field.getExtraInfo().equalsIgnoreCase("auto_increment")) {
columnNameList += field.getFieldName()+",";
// Get the allowed values for the current field from the child column
ArrayList<String> allowedValues = databaseTableUtils.getColumnValue(childTable,childColumn);
String chosenValue = allowedValues.get(k); //use the 'k' index because all the table have the same total row
valuesList +=chosenValue+"','";
}
}else {
fieldHasChild = false; // current field has no child to other tables
if(Log4jManager.IS_LOGGING_CONFIGURED)
logger.info("The field: "+currentFieldName+" has no references to other tables");
//TODO: next release improve the field type above....
/* fields with "auto_increment" option don't appear in the insert query: is mysql that generate their value */
if(!field.getExtraInfo().equalsIgnoreCase("auto_increment"))
{
columnNameList += field.getFieldName()+",";
/* PREMISE: the dimension of a some field is not mandatory, depends on the field type */
if(fieldType.startsWith("tinyint")){ //tinyint(x) values 0-255 (or -128 to 127)