Skip to content
Closed
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
@@ -1,10 +1,6 @@
package org.hibernate.tool.internal.export.common;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.io.*;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -32,19 +28,31 @@ public void produce(Map<String,Object> additionalContext, String templateName, F
log.warn("Generated output is empty. Skipped creation for file " + destination);
return;
}
FileWriter fileWriter = null;
FileOutputStream destinationStream = null;
OutputStreamWriter fileWriter = null;
try {

th.ensureExistence( destination );

ac.addFile(destination, fileType);
log.debug("Writing " + identifier + " to " + destination.getAbsolutePath() );
fileWriter = new FileWriter(destination);
destinationStream = new FileOutputStream(destination);
// Output encoding set to UTF-8, in order to support international character sets.
fileWriter = new OutputStreamWriter(destinationStream, "UTF-8");;
fileWriter.write(tempResult);
}
catch (Exception e) {
throw new RuntimeException("Error while writing result to file", e);
} finally {
if(destinationStream != null){
try {
destinationStream.flush();
destinationStream.close();
}
catch (IOException e) {
log.warn("Exception while flushing/closing " + destinationStream,e);
}
}
if(fileWriter!=null) {
try {
fileWriter.flush();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,28 @@ protected boolean excludeTable(TableIdentifier identifier) {
}
}

private void combineAttributeMaps(final Map<String,MetaAttribute> source, final Map<String,MetaAttribute> destination) {
for(Map.Entry<String,MetaAttribute> attributeEntry : destination.entrySet()){
// Matching key in both reveng strategy and overrideRepository. Need to combine.
if(source.containsKey(attributeEntry.getKey())) {
MetaAttribute overrideMeta = source.get(attributeEntry.getKey());
// Add any values to those generated in the RevengStrategy for a combined result.
overrideMeta.getValues().forEach(value -> {
if(!attributeEntry.getValue().getValues().contains(value)){
attributeEntry.getValue().addValue((String)value);
}
});
}
}
// Now move over attributes from overrideRepository that were not present
// in the value generated by revengStrategy
for(Map.Entry<String,MetaAttribute> attributeEntry : source.entrySet()){
if(!destination.containsKey(attributeEntry.getKey())){
destination.put(attributeEntry.getKey(),attributeEntry.getValue());
}
}
}

public void addTableFilter(TableFilter filter) {
tableFilters.add(filter);
}
Expand All @@ -290,11 +312,34 @@ public boolean excludeTable(TableIdentifier ti) {
}

public Map<String,MetaAttribute> tableToMetaAttributes(TableIdentifier tableIdentifier) {
return OverrideRepository.this.tableToMetaAttributes(tableIdentifier);
Map<String,MetaAttribute> metaAttributeMap = super.tableToMetaAttributes(tableIdentifier);
if(null != metaAttributeMap && !metaAttributeMap.isEmpty()) {
Map<String,MetaAttribute> configFileAttributeMap =
OverrideRepository.this.tableToMetaAttributes(tableIdentifier);
// If there are attributes from both RevengStrategy and OverrideRepository, combine them together.
if(null != configFileAttributeMap && !configFileAttributeMap.isEmpty()) {
OverrideRepository.this.combineAttributeMaps(configFileAttributeMap, metaAttributeMap);
}
// Return combined map
return metaAttributeMap;
}
else return OverrideRepository.this.tableToMetaAttributes(tableIdentifier);
}

public Map<String, MetaAttribute> columnToMetaAttributes(TableIdentifier tableIdentifier, String column) {
return OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column);
Map<String,MetaAttribute> metaAttributeMap = super.columnToMetaAttributes(tableIdentifier, column);
if(null != metaAttributeMap && !metaAttributeMap.isEmpty()) {
Map<String,MetaAttribute> configFileAttributeMap =
OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column);

// If there are attributes from both RevengStrategy and OverrideRepository, combine them together.
if(null != configFileAttributeMap && !configFileAttributeMap.isEmpty()) {
OverrideRepository.this.combineAttributeMaps(configFileAttributeMap, metaAttributeMap);
}
// Return combined map
return metaAttributeMap;
}
else return OverrideRepository.this.columnToMetaAttributes(tableIdentifier, column);
}

public boolean excludeColumn(TableIdentifier identifier, String columnName) {
Expand Down