{
File[] schemaFiles = getSchemaFiles();
if ( schemaFiles.length > 0)
{
Database model = readModel(schemaFiles);
Platform platforms[] = new Platform[databases.length];
if ( databases.length == 0 )
{
getLog().warn("No databases specified, no ddl generated");
}
else
{
for ( int i = 0; i < databases.length; i++ )
{
try
{
platforms[i] = PlatformFactory.createNewPlatformInstance(databases[i]);
}
catch (Exception ex)
{
throw new MojoExecutionException("Database type "+databases[i]+" is not supported.", ex);
}
if (platforms[i] == null)
{
throw new MojoExecutionException("Database type "+databases[i]+" is not supported.");
}
platforms[i].setDelimitedIdentifierModeOn(useDelimitedSqlIdentifiers);
platforms[i].setForeignKeysSorted(sortForeignKeys);
}
for (int i = 0; i < platforms.length; i++ )
{
Platform platform = platforms[i];
platform.setScriptModeOn(true);
File outputDir = new File(outputTarget,databases[i].toLowerCase());
if ( !outputDir.exists() )
{
outputDir.mkdirs();
}
if (platform.getPlatformInfo().isSqlCommentsSupported())
{
// we're generating SQL comments if possible
platform.setSqlCommentsOn(true);
}
if ( platform instanceof Oracle8Platform )
{
// hack to map LONGVARCHAR to VARCHAR2(4000) on Oracle, the predefined CLOB type really isn't usable
platform.getPlatformInfo().addNativeTypeMapping("LONGVARCHAR", "VARCHAR2(4000)");
}
CreationParameters params = getFilteredParameters(model, platform.getName(), useDelimitedSqlIdentifiers);
try
{
StringWriter stringWriter = new StringWriter();
platform.getSqlBuilder().setWriter(stringWriter);
// use cglib enhanced wrapper for SqlBuilder to allow overriding ddlutils 1.0 behavior at runtime for
// https://issues.apache.org/jira/browse/DDLUTILS-75 which is fixed in ddlutils 1.1 but hasn't been released yet.
SqlBuilder sqlBuilder = new EnhancedSqlBuilder(platform.getSqlBuilder());
sqlBuilder.createTables(model, params, false);
int createSchemaLength = stringWriter.getBuffer().length();
writeOutput(new File(outputDir,"create-schema.sql"),stringWriter.toString());
stringWriter.getBuffer().setLength(0);
sqlBuilder.createTables(model, params, true);