Search in sources :

Example 1 with Dialect

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;
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal) Schema(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.Schema) Dialect(org.jaxdb.vendor.Dialect) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column) URL(java.net.URL)

Aggregations

URL (java.net.URL)1 Dialect (org.jaxdb.vendor.Dialect)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Column)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal)1 org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table)1 Schema (org.jaxdb.www.ddlx_0_5.xLygluGCXAA.Schema)1