tblDef = getTableDefFromDBTable(dbTbl);
}
//build each field definition and figure out which table it goes
Iterator fieldIter = desc.getFields().iterator();
DatabaseField dbField = null;
while (fieldIter.hasNext()) {
dbField = (DatabaseField) fieldIter.next();
boolean isPKField = false;
//first check if the filed is a pk field in the default table.
isPKField = desc.getPrimaryKeyFields().contains(dbField);
//then check if the field is a pk field in the secondary table(s), this is only applied to the multiple tables case.
Map secondaryKeyMap = (Map) desc.getAdditionalTablePrimaryKeyFields().get(dbField.getTable());
if (secondaryKeyMap != null) {
isPKField = isPKField || secondaryKeyMap.containsValue(dbField);
}
//build or retrieve the field definition.
FieldDefinition fieldDef = getFieldDefFromDBField(dbField, isPKField);
if (isPKField) {
// Check if the generation strategy is IDENTITY
String sequenceName = desc.getSequenceNumberName();
DatabaseLogin login = project.getLogin();
Sequence seq = login.getSequence(sequenceName);
if(seq instanceof DefaultSequence) {
seq = login.getDefaultSequence();
}
//The native sequence whose value should be aquired after insert is identity sequence
boolean isIdentity = seq instanceof NativeSequence && seq.shouldAcquireValueAfterInsert();
fieldDef.setIsIdentity(isIdentity);
}
//find the table the field belongs to, and add it to the table, ony if not already added.
tblDef = tableMap.get(dbField.getTableName());
if (!tblDef.getFields().contains(fieldDef)) {
tblDef.addField(fieldDef);
}
}