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 @@ -23,21 +23,22 @@
import org.hibernate.tool.util.ReflectionUtil;

public class ExporterFactory {

public static Exporter createExporter(String exporterClassName) {
Exporter result = null;
try {
Class<?> exporterClass = ReflectionUtil.classForName(exporterClassName);
Constructor<?> exporterConstructor = exporterClass.getConstructor(new Class[] {});
result = (Exporter)exporterConstructor.newInstance();
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException exception) {
throw new RuntimeException("An exporter of class '" + exporterClassName + "' could not be created", exception);
}
return result;
}

public static Exporter createExporter(ExporterType exporterType) {
return createExporter(exporterType.className());
}

public static Exporter createExporter(String exporterClassName) {
Exporter result;
try {
Class<?> exporterClass = ReflectionUtil.classForName(exporterClassName);
Constructor<?> exporterConstructor = exporterClass.getConstructor();
result = (Exporter)exporterConstructor.newInstance();
}
catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException exception) {
throw new RuntimeException("An exporter of class '" + exporterClassName + "' could not be created", exception);
}
return result;
}

public static Exporter createExporter(ExporterType exporterType) {
return createExporter(exporterType.className());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Map;

import com.google.googlejavaformat.java.Formatter;
import com.google.googlejavaformat.java.FormatterException;

public class DefaultJavaPrettyPrinterStrategy {

public boolean formatFile(File file) {
try {
Formatter formatter = new Formatter();
String toFormat = new String(Files.readAllBytes(file.toPath()));
String toWrite = formatter.formatSource(toFormat);
Files.write(file.toPath(), toWrite.getBytes());
return true;
} catch (IOException | FormatterException e) {
throw new RuntimeException(e);
}
}
public boolean formatFile(File file) {
try {
Formatter formatter = new Formatter();
String toFormat = new String(Files.readAllBytes(file.toPath()));
String toWrite = formatter.formatSource(toFormat);
Files.write(file.toPath(), toWrite.getBytes());
return true;
}
catch (IOException | FormatterException e) {
throw new RuntimeException(e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,78 +35,82 @@
import org.hibernate.tool.internal.reveng.dialect.SQLServerMetaDataDialect;

public class RevengDialectFactory {

private RevengDialectFactory() {}

public static RevengDialect createMetaDataDialect(Dialect dialect, Properties cfg) {
String property = cfg.getProperty( "hibernatetool.metadatadialect" );
RevengDialect mdd = fromClassName(property);
if(mdd==null) {
mdd = fromDialect(dialect);
}
if(mdd==null) {
mdd = fromDialectName(dialect.getClass().getName());
}
if(mdd==null) {
mdd = new JDBCMetaDataDialect();
}
return mdd;
}
private RevengDialectFactory() {}

public static RevengDialect fromClassName(String property) {
if ( property != null ) {
try {
Class<?> revengDialectClass = ReflectHelper.classForName(
property,
RevengDialectFactory.class );
Constructor<?> revengDialectConstructor = revengDialectClass.getConstructor(
new Class[] {});
return (RevengDialect)revengDialectConstructor.newInstance();
}
catch (Throwable e) {
throw new RuntimeException(
"Could not load MetaDataDialect: " + property, e );
}
} else {
return null;
}
}

public static RevengDialect fromDialect(Dialect dialect) {
if(dialect!=null) {
if(dialect instanceof OracleDialect) {
return new OracleMetaDataDialect();
} else if (dialect instanceof H2Dialect) {
return new H2MetaDataDialect();
} else if (dialect instanceof MySQLDialect) {
return new MySQLMetaDataDialect();
} else if (dialect instanceof HSQLDialect) {
return new HSQLMetaDataDialect();
}else if (dialect instanceof SQLServerDialect) {
return new SQLServerMetaDataDialect();
}
}
return null;
}

public static RevengDialect fromDialectName(String dialect) {
if (dialect.toLowerCase().contains("oracle")) {
return new OracleMetaDataDialect();
}
if (dialect.toLowerCase().contains("mysql")) {
return new MySQLMetaDataDialect();
}
if (dialect.toLowerCase().contains("h2")) {
return new H2MetaDataDialect();
}
if (dialect.toLowerCase().contains("hsql")) {
return new HSQLMetaDataDialect();
}
if (dialect.toLowerCase().contains("sqlserver")) {
return new SQLServerMetaDataDialect();
}
return null;
}
public static RevengDialect createMetaDataDialect(Dialect dialect, Properties cfg) {
String property = cfg.getProperty( "hibernatetool.metadatadialect" );
RevengDialect mdd = fromClassName(property);
if(mdd==null) {
mdd = fromDialect(dialect);
}
if(mdd==null) {
mdd = fromDialectName(dialect.getClass().getName());
}
if(mdd==null) {
mdd = new JDBCMetaDataDialect();
}
return mdd;
}

public static RevengDialect fromClassName(String property) {
if ( property != null ) {
try {
Class<?> revengDialectClass = ReflectHelper.classForName(
property,
RevengDialectFactory.class );
Constructor<?> revengDialectConstructor = revengDialectClass.getConstructor();
return (RevengDialect)revengDialectConstructor.newInstance();
}
catch (Throwable e) {
throw new RuntimeException(
"Could not load MetaDataDialect: " + property, e );
}
}
else {
return null;
}
}

public static RevengDialect fromDialect(Dialect dialect) {
if(dialect!=null) {
if(dialect instanceof OracleDialect) {
return new OracleMetaDataDialect();
}
else if (dialect instanceof H2Dialect) {
return new H2MetaDataDialect();
}
else if (dialect instanceof MySQLDialect) {
return new MySQLMetaDataDialect();
}
else if (dialect instanceof HSQLDialect) {
return new HSQLMetaDataDialect();
}
else if (dialect instanceof SQLServerDialect) {
return new SQLServerMetaDataDialect();
}
}
return null;
}

public static RevengDialect fromDialectName(String dialect) {
if (dialect.toLowerCase().contains("oracle")) {
return new OracleMetaDataDialect();
}
if (dialect.toLowerCase().contains("mysql")) {
return new MySQLMetaDataDialect();
}
if (dialect.toLowerCase().contains("h2")) {
return new H2MetaDataDialect();
}
if (dialect.toLowerCase().contains("hsql")) {
return new HSQLMetaDataDialect();
}
if (dialect.toLowerCase().contains("sqlserver")) {
return new SQLServerMetaDataDialect();
}
return null;
}


}
Loading