Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,85 +32,86 @@

public class RevengMetadataCollector {

private MetadataBuildingContext metadataBuildingContext = null;
private final Map<TableIdentifier, Table> tables;
private Map<String, List<ForeignKey>> oneToManyCandidates;
private final Map<TableIdentifier, String> suggestedIdentifierStrategies;

public RevengMetadataCollector(MetadataBuildingContext metadataBuildingContext) {
this();
this.metadataBuildingContext = metadataBuildingContext;
}

public RevengMetadataCollector() {
this.tables = new HashMap<TableIdentifier, Table>();
this.suggestedIdentifierStrategies = new HashMap<TableIdentifier, String>();
}

public Iterator<Table> iterateTables() {
return tables.values().iterator();
}

// TableIdentifier's catalog, schema and name should be quoted
public Table addTable(TableIdentifier tableIdentifier) {
Table result = null;
String catalog = tableIdentifier.getCatalog();
String schema = tableIdentifier.getSchema();
String name = tableIdentifier.getName();
InFlightMetadataCollector metadataCollector = getMetadataCollector();
if (metadataCollector != null) {
result = metadataCollector.addTable(schema, catalog, name, null, false, metadataBuildingContext);
} else {
result = createTable(catalog, schema, name);
}
if (tables.containsKey(tableIdentifier)) {
throw new RuntimeException(
"Attempt to add a double entry for table: " +
TableNameQualifier.qualify(catalog, schema, name));
}
tables.put(tableIdentifier, result);
return result;
}

public Table getTable(TableIdentifier tableIdentifier) {
return tables.get(tableIdentifier);
}

public Collection<Table> getTables() {
return tables.values();
}

public void setOneToManyCandidates(Map<String, List<ForeignKey>> oneToManyCandidates) {
this.oneToManyCandidates = oneToManyCandidates;
}

public Map<String, List<ForeignKey>> getOneToManyCandidates() {
return oneToManyCandidates;
}

public String getSuggestedIdentifierStrategy(String catalog, String schema, String name) {
return (String) suggestedIdentifierStrategies.get(TableIdentifier.create(catalog, schema, name));
}

public void addSuggestedIdentifierStrategy(String catalog, String schema, String name, String idstrategy) {
suggestedIdentifierStrategies.put(TableIdentifier.create(catalog, schema, name), idstrategy);
}

private Table createTable(String catalog, String schema, String name) {
Table table = new Table("Hibernate Tools");
table.setAbstract(false);
table.setName(name);
table.setSchema(schema);
table.setCatalog(catalog);
return table;
}

private InFlightMetadataCollector getMetadataCollector() {
InFlightMetadataCollector result = null;
if (metadataBuildingContext != null) {
result = metadataBuildingContext.getMetadataCollector();
}
return result;
}

private MetadataBuildingContext metadataBuildingContext = null;
private final Map<TableIdentifier, Table> tables;
private Map<String, List<ForeignKey>> oneToManyCandidates;
private final Map<TableIdentifier, String> suggestedIdentifierStrategies;

public RevengMetadataCollector(MetadataBuildingContext metadataBuildingContext) {
this();
this.metadataBuildingContext = metadataBuildingContext;
}

public RevengMetadataCollector() {
this.tables = new HashMap<>();
this.suggestedIdentifierStrategies = new HashMap<>();
}

public Iterator<Table> iterateTables() {
return tables.values().iterator();
}

// TableIdentifier's catalog, schema and name should be quoted
public Table addTable(TableIdentifier tableIdentifier) {
Table result;
String catalog = tableIdentifier.getCatalog();
String schema = tableIdentifier.getSchema();
String name = tableIdentifier.getName();
InFlightMetadataCollector metadataCollector = getMetadataCollector();
if (metadataCollector != null) {
result = metadataCollector.addTable(schema, catalog, name, null, false, metadataBuildingContext);
}
else {
result = createTable(catalog, schema, name);
}
if (tables.containsKey(tableIdentifier)) {
throw new RuntimeException(
"Attempt to add a double entry for table: " +
TableNameQualifier.qualify(catalog, schema, name));
}
tables.put(tableIdentifier, result);
return result;
}

public Table getTable(TableIdentifier tableIdentifier) {
return tables.get(tableIdentifier);
}

public Collection<Table> getTables() {
return tables.values();
}

public void setOneToManyCandidates(Map<String, List<ForeignKey>> oneToManyCandidates) {
this.oneToManyCandidates = oneToManyCandidates;
}

public Map<String, List<ForeignKey>> getOneToManyCandidates() {
return oneToManyCandidates;
}

public String getSuggestedIdentifierStrategy(String catalog, String schema, String name) {
return suggestedIdentifierStrategies.get(TableIdentifier.create(catalog, schema, name));
}

public void addSuggestedIdentifierStrategy(String catalog, String schema, String name, String idstrategy) {
suggestedIdentifierStrategies.put(TableIdentifier.create(catalog, schema, name), idstrategy);
}

private Table createTable(String catalog, String schema, String name) {
Table table = new Table("Hibernate Tools");
table.setAbstract(false);
table.setName(name);
table.setSchema(schema);
table.setCatalog(catalog);
return table;
}

private InFlightMetadataCollector getMetadataCollector() {
InFlightMetadataCollector result = null;
if (metadataBuildingContext != null) {
result = metadataBuildingContext.getMetadataCollector();
}
return result;
}

}
Loading