classModel.setEnumList("INSTANCE");
classModel.setPackageName(this.packageName);
classModel.addImport("org.byteliberi.easydriver.*");
classModel.addImport("org.byteliberi.easydriver.fields.*");
classModel.addProperty(new PropertyModel(Visibility.PRIVATE, DBTable.class.getSimpleName(), "table"));
// Let's look for the fields
final List<FieldPropertyAssociation> fieldAssoc = tableInfo.getFields();
final HashSet<String> usedFields = new HashSet<String>();
for (FieldPropertyAssociation fa : fieldAssoc) {
final String fieldName = fa.getFieldName();
if (!usedFields.contains(fieldName)) {
classModel.addProperty(fa.getProp());
usedFields.add(fieldName);
}
}
// Let's look for the relationships
final Collection<List<RelationModel>> rels = tableInfo.getRelationships();
// Now we add the properties for the relationships that we have found
final HashSet<String> ext = new HashSet<String>();
if ((rels != null) && (rels.size() > 0)) {
Iterator<List<RelationModel>> relsIterator = rels.iterator();
while (relsIterator.hasNext()) {
final List<RelationModel> relList = relsIterator.next();
if (relList.size() > 0) {
final String oneTable = relList.get(0).getOneTable();
ext.add(oneTable);
}
}
}
for (String name : ext) {
classModel.addProperty(new PropertyModel(Visibility.PRIVATE,
ManyToOne.class.getSimpleName(),
"fk" + Utils.getCamelNameFirstCapital(name)));
}
classModel.setConstructorGenerator(new TableStructureConstructor(tableName, fieldAssoc, rels, tableInfo.getPrimaryKey()));