*/
private void createPersistentClasses(DatabaseCollector collector, Mapping mapping) {
Map manyToOneCandidates = collector.getOneToManyCandidates();
for (Iterator iter = mappings.iterateTables(); iter.hasNext();) {
Table table = (Table) iter.next();
if(table.getColumnSpan()==0) {
log.warn("Cannot create persistent class for " + table + " as no columns were found.");
continue;
}
// TODO: this naively just create an entity per table
// should have an opt-out option to mark some as helper tables, subclasses etc.
/*if(table.getPrimaryKey()==null || table.getPrimaryKey().getColumnSpan()==0) {
log.warn("Cannot create persistent class for " + table + " as no primary key was found.");
continue;
// TODO: just create one big embedded composite id instead.
}*/
if(revengStrategy.isManyToManyTable(table)) {
log.debug( "Ignoring " + table + " as class since rev.eng. says it is a many-to-many" );
continue;
}
RootClass rc = new RootClass();
TableIdentifier tableIdentifier = TableIdentifier.create(table);
String className = revengStrategy.tableToClassName( tableIdentifier );
log.debug("Building entity " + className + " based on " + tableIdentifier);
rc.setEntityName( className );
rc.setClassName( className );
rc.setProxyInterfaceName( rc.getEntityName() ); // TODO: configurable ?
rc.setLazy(true);
rc.setMetaAttributes( safeMeta(revengStrategy.tableToMetaAttributes( tableIdentifier )) );
rc.setDiscriminatorValue( rc.getEntityName() );
rc.setTable(table);
try {
mappings.addClass(rc);
} catch(DuplicateMappingException dme) {
// TODO: detect this and generate a "permutation" of it ?
PersistentClass class1 = mappings.getClass(dme.getName());
Table table2 = class1.getTable();
throw new JDBCBinderException("Duplicate class name '" + rc.getEntityName() + "' generated for '" + table + "'. Same name where generated for '" + table2 + "'");
}
mappings.addImport( rc.getEntityName(), rc.getEntityName() );
Set processed = new HashSet();