use of org.jaxdb.vendor.Dialect in project jaxdb by jaxdb.
the class DDLxTest method recreateSchema.
// FIXME: The efficiency of this is TERRIBLE!
public static Schema recreateSchema(final Connection connection, final String ddlxFileName, final boolean unaltered) throws GeneratorExecutionException, IOException, SAXException, SQLException, TransformerException {
final DDLx ddlx = new DDLx(ClassLoader.getSystemClassLoader().getResource(ddlxFileName + ".ddlx"));
final Schema schema = ddlx.getMergedSchema();
if (!unaltered) {
final Dialect dialect = DBVendor.valueOf(connection.getMetaData()).getDialect();
for (final $Table table : schema.getTable()) {
if (table.getColumn() != null) {
for (final $Column column : table.getColumn()) {
if (column instanceof $Decimal) {
final $Decimal decimal = ($Decimal) column;
final int maxPrecision = dialect.decimalMaxPrecision();
decimal.setPrecision$(new $Decimal.Precision$(maxPrecision));
if (decimal.getScale$() != null && decimal.getScale$().text() > maxPrecision)
decimal.setScale$(new $Decimal.Scale$(maxPrecision));
}
}
}
}
}
final URL url = MemoryURLStreamHandler.createURL(schema.toString().getBytes());
Schemas.recreate(connection, url);
return schema;
}
Aggregations