Search in sources :

Example 21 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database in project molgenis-emx2 by molgenis.

the class TestImportTableTask method setup.

@BeforeClass
public static void setup() {
    Database database = TestDatabaseFactory.getTestDatabase();
    schema = database.dropCreateSchema(TestImportTableTask.class.getSimpleName());
}
Also used : Database(org.molgenis.emx2.Database) BeforeClass(org.junit.BeforeClass)

Example 22 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database in project molgenis-emx2 by molgenis.

the class TestTruncate method testTruncate.

@Test
public void testTruncate() {
    Database db = TestDatabaseFactory.getTestDatabase();
    Schema schema = db.dropCreateSchema(TestTruncate.class.getSimpleName());
    // create simple table, add data, and truncate
    Table table1 = schema.create(table("Table1", column("name").setPkey()));
    table1.insert(row("name", "a"));
    Assert.assertEquals(1, table1.retrieveRows().size());
    table1.truncate();
    Assert.assertEquals(0, table1.retrieveRows().size());
    // create with subclass
    Table table2 = schema.create(table("Table2").setInherit("Table1").add(column("col1")));
    table1.insert(row("name", "a"));
    table2.insert(row("name", "b", "col1", "checkb"));
    Assert.assertEquals(2, table1.retrieveRows().size());
    Assert.assertEquals(1, table2.retrieveRows().size());
    table1.truncate();
    Assert.assertEquals(1, table1.retrieveRows().size());
    Assert.assertEquals(1, table2.retrieveRows().size());
    table2.truncate();
    Assert.assertEquals(0, table1.retrieveRows().size());
    Assert.assertEquals(0, table2.retrieveRows().size());
    // create with subclass of a subclass
    Table table3 = schema.create(table("Table3").setInherit("Table2").add(column("col2")));
    table1.insert(row("name", "a"));
    table2.insert(row("name", "b", "col1", "checkb"));
    table3.insert(row("name", "c", "col1", "checkc", "col2", "checkc"));
    Assert.assertEquals(3, table1.retrieveRows().size());
    Assert.assertEquals(2, table2.retrieveRows().size());
    Assert.assertEquals(1, table3.retrieveRows().size());
    // leaves subclass?!!! is this expected behavior?
    table2.truncate();
    Assert.assertEquals(2, table1.retrieveRows().size());
    // !!!
    Assert.assertEquals(1, table2.retrieveRows().size());
    Assert.assertEquals(1, table3.retrieveRows().size());
    table3.truncate();
    Assert.assertEquals(1, table1.retrieveRows().size());
    Assert.assertEquals(0, table2.retrieveRows().size());
    Assert.assertEquals(0, table3.retrieveRows().size());
    table1.truncate();
    Assert.assertEquals(0, table1.retrieveRows().size());
    Assert.assertEquals(0, table2.retrieveRows().size());
    Assert.assertEquals(0, table3.retrieveRows().size());
}
Also used : Table(org.molgenis.emx2.Table) Schema(org.molgenis.emx2.Schema) Database(org.molgenis.emx2.Database) Test(org.junit.Test)

Example 23 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database in project jaxdb by jaxdb.

the class ReverseTest method testRecreateSchema.

@Test
public void testRecreateSchema(final Connection connection) throws GeneratorExecutionException, IOException, MarshalException, SAXException, SQLException, TransformerException, XPathExpressionException {
    final Schema expected = recreateSchema(connection, "reverse", true);
    sort(expected);
    // logger.info(expected);
    Schema actual = Decompiler.createDDL(connection);
    // FIXME: Need to restrict which database/schema/tablespace we're looking at.
    final Iterator<$Table> iterator = actual.getTable().iterator();
    while (iterator.hasNext()) if (!iterator.next().getName$().text().startsWith("t_"))
        iterator.remove();
    sort(actual);
    // logger.info(actual);
    assertEqual(DBVendor.valueOf(connection.getMetaData()), expected, actual);
// logger.info(DOMs.domToString(actual.marshal(), Collections.singletonMap("http://www.jaxdb.org/ddlx.xsd", "http://www.jaxdb.org/ddlx.xsd"), DOMStyle.INDENT));
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table) Schema(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.Schema) Test(org.junit.Test)

Example 24 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database in project jaxdb by jaxdb.

the class Generator method getColumnMeta.

private ColumnMeta getColumnMeta(final Table table, final $Column column) throws GeneratorExecutionException {
    final String columnName = column.getName$().text();
    boolean isKeyForUpdate = false;
    // FIXME: Make efficient
    if (table.getJsqlKeyForUpdate() != null)
        for (final xLygluGCXAA.$Named col : table.getJsqlKeyForUpdate().getColumn()) if (isKeyForUpdate = columnName.equals(col.getName$().text()))
            break;
    final Class<?> cls = column.getClass().getSuperclass();
    GenerateOn<?> generateOnInsert = null;
    GenerateOn<?> generateOnUpdate = null;
    final boolean isPrimary = ddlx.isPrimary(table, column);
    final Object[] commonParams = { THIS, MUTABLE, "\"" + column.getName$().text() + "\"", ddlx.isUnique(table, column), isPrimary, isNull(column) };
    if (column instanceof $Char) {
        final $Char col = ($Char) column;
        if (col.getSqlxGenerateOnInsert$() != null) {
            if ($Char.GenerateOnInsert$.UUID.text().equals(col.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.UUID;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + col.getSqlxGenerateOnInsert$().text());
        }
        return new ColumnMeta(table, column, isPrimary, data.CHAR.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, col.getLength$() == null ? null : col.getLength$().text(), isVarying(col.getVarying$()));
    }
    if (column instanceof $Clob) {
        final $Clob col = ($Clob) column;
        return new ColumnMeta(table, column, isPrimary, data.CLOB.class, commonParams, null, generateOnInsert, generateOnUpdate, isKeyForUpdate, col.getLength$() == null ? null : col.getLength$().text());
    }
    if (column instanceof $Binary) {
        final $Binary col = ($Binary) column;
        return new ColumnMeta(table, column, isPrimary, data.BINARY.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, col.getLength$() == null ? null : col.getLength$().text(), isVarying(col.getVarying$()));
    }
    if (column instanceof $Blob) {
        final $Blob col = ($Blob) column;
        return new ColumnMeta(table, column, isPrimary, data.BLOB.class, commonParams, null, generateOnInsert, generateOnUpdate, isKeyForUpdate, col.getLength$() == null ? null : col.getLength$().text());
    }
    if (column instanceof $Integer) {
        final $Integer integerColumn = ($Integer) column;
        if (integerColumn.getGenerateOnInsert$() != null) {
            if ($Integer.GenerateOnInsert$.AUTO_5FINCREMENT.text().equals(integerColumn.getGenerateOnInsert$().text())) {
                generateOnInsert = GenerateOn.AUTO_GENERATED;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integerColumn.getGenerateOnInsert$().text());
            }
        }
        if (column instanceof $Tinyint) {
            final $Tinyint integer = ($Tinyint) column;
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if ($Tinyint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (isPrimary)
                        throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new ColumnMeta(table, column, isPrimary, data.TINYINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Smallint) {
            final $Smallint integer = ($Smallint) column;
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if ($Smallint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (isPrimary)
                        throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new ColumnMeta(table, column, isPrimary, data.SMALLINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Int) {
            final $Int integer = ($Int) column;
            if (integer.getSqlxGenerateOnInsert$() != null) {
                if (generateOnInsert != null)
                    throw new GeneratorExecutionException("ddlx:generateOnInsert and sqlx:generateOnInsert are mutually exclusive");
                if ($Int.GenerateOnInsert$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnInsert = GenerateOn.EPOCH_MINUTES;
                } else if ($Int.GenerateOnInsert$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnInsert = GenerateOn.EPOCH_SECONDS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integer.getSqlxGenerateOnInsert$().text());
                }
            }
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                if ($Int.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else if ($Int.GenerateOnUpdate$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnUpdate = GenerateOn.EPOCH_MINUTES;
                } else if ($Int.GenerateOnUpdate$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("INT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnUpdate = GenerateOn.EPOCH_SECONDS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new ColumnMeta(table, column, isPrimary, data.INT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
        if (column instanceof $Bigint) {
            final $Bigint integer = ($Bigint) column;
            if (integer.getSqlxGenerateOnInsert$() != null) {
                if (generateOnInsert != null)
                    throw new GeneratorExecutionException("ddlx:generateOnInsert and sqlx:generateOnInsert are mutually exclusive");
                if ($Bigint.GenerateOnInsert$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnInsert = GenerateOn.EPOCH_MINUTES;
                } else if ($Bigint.GenerateOnInsert$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnInsert = GenerateOn.EPOCH_SECONDS;
                } else if ($Bigint.GenerateOnInsert$.EPOCH_5FMILLIS.text().equals(integer.getSqlxGenerateOnInsert$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 13)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 13 for EPOCH_MILLIS");
                    generateOnInsert = GenerateOn.EPOCH_MILLIS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + integer.getSqlxGenerateOnInsert$().text());
                }
            }
            if (integer.getSqlxGenerateOnUpdate$() != null) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                if ($Bigint.GenerateOnUpdate$.INCREMENT.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    generateOnUpdate = GenerateOn.INCREMENT;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FMINUTES.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 8)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 8 for EPOCH_MINUTES");
                    generateOnUpdate = GenerateOn.EPOCH_MINUTES;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FSECONDS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 10)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 10 for EPOCH_SECONDS");
                    generateOnUpdate = GenerateOn.EPOCH_SECONDS;
                } else if ($Bigint.GenerateOnUpdate$.EPOCH_5FMILLIS.text().equals(integer.getSqlxGenerateOnUpdate$().text())) {
                    if (integer.getPrecision$().text() != null && integer.getPrecision$().text() < 13)
                        throw new GeneratorExecutionException("BIGINT(" + integer.getPrecision$().text() + ") requires minimum precision of 13 for EPOCH_MILLIS");
                    generateOnUpdate = GenerateOn.EPOCH_MILLIS;
                } else {
                    throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + integer.getSqlxGenerateOnUpdate$().text());
                }
            }
            return new ColumnMeta(table, column, isPrimary, data.BIGINT.class, commonParams, integer.getDefault$() == null ? null : integer.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, integer.getPrecision$() == null ? null : integer.getPrecision$().text().intValue(), integer.getMin$() == null ? null : integer.getMin$().text(), integer.getMax$() == null ? null : integer.getMax$().text());
        }
    }
    if (column instanceof $Float) {
        final $Float col = ($Float) column;
        final Number min = col.getMin$() != null ? col.getMin$().text() : null;
        final Number max = col.getMax$() != null ? col.getMax$().text() : null;
        return new ColumnMeta(table, column, isPrimary, data.FLOAT.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, min, max);
    }
    if (column instanceof $Double) {
        final $Double col = ($Double) column;
        final Number min = col.getMin$() != null ? col.getMin$().text() : null;
        final Number max = col.getMax$() != null ? col.getMax$().text() : null;
        return new ColumnMeta(table, column, isPrimary, data.DOUBLE.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, min, max);
    }
    if (column instanceof $Decimal) {
        final $Decimal col = ($Decimal) column;
        return new ColumnMeta(table, column, isPrimary, data.DECIMAL.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, col.getPrecision$() == null ? null : col.getPrecision$().text().intValue(), col.getScale$() == null ? null : col.getScale$().text().intValue(), col.getMin$() == null ? null : col.getMin$().text(), col.getMax$() == null ? null : col.getMax$().text());
    }
    if (column instanceof $Date) {
        final $Date col = ($Date) column;
        if (col.getSqlxGenerateOnInsert$() != null) {
            if ($Date.GenerateOnInsert$.TIMESTAMP.text().equals(col.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + col.getSqlxGenerateOnInsert$().text());
        }
        if (col.getSqlxGenerateOnUpdate$() != null) {
            if ($Date.GenerateOnUpdate$.TIMESTAMP.text().equals(col.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + col.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new ColumnMeta(table, column, isPrimary, data.DATE.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    if (column instanceof $Time) {
        final $Time col = ($Time) column;
        if (col.getSqlxGenerateOnInsert$() != null) {
            if ($Time.GenerateOnInsert$.TIMESTAMP.text().equals(col.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + col.getSqlxGenerateOnInsert$().text());
        }
        if (col.getSqlxGenerateOnUpdate$() != null) {
            if ($Time.GenerateOnUpdate$.TIMESTAMP.text().equals(col.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + col.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new ColumnMeta(table, column, isPrimary, data.TIME.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, col.getPrecision$() == null ? null : col.getPrecision$().text());
    }
    if (column instanceof $Datetime) {
        final $Datetime col = ($Datetime) column;
        if (col.getSqlxGenerateOnInsert$() != null) {
            if ($Datetime.GenerateOnInsert$.TIMESTAMP.text().equals(col.getSqlxGenerateOnInsert$().text()))
                generateOnInsert = GenerateOn.TIMESTAMP;
            else
                throw new GeneratorExecutionException("Unknown generateOnInsert specification: " + col.getSqlxGenerateOnInsert$().text());
        }
        if (col.getSqlxGenerateOnUpdate$() != null) {
            if ($Datetime.GenerateOnUpdate$.TIMESTAMP.text().equals(col.getSqlxGenerateOnUpdate$().text())) {
                if (isPrimary)
                    throw new GeneratorExecutionException("Primary column \"" + table.getName$().text() + "." + column.getName$().text() + "\" cannot specify generateOnUpdate");
                generateOnUpdate = GenerateOn.TIMESTAMP;
            } else {
                throw new GeneratorExecutionException("Unknown generateOnUpdate specification: " + col.getSqlxGenerateOnUpdate$().text());
            }
        }
        return new ColumnMeta(table, column, isPrimary, data.DATETIME.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate, col.getPrecision$() == null ? null : col.getPrecision$().text());
    }
    if (column instanceof $Boolean) {
        final $Boolean col = ($Boolean) column;
        return new ColumnMeta(table, column, isPrimary, data.BOOLEAN.class, commonParams, col.getDefault$() == null ? null : col.getDefault$().text(), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    if (column instanceof $Enum) {
        final $Enum col = ($Enum) column;
        return new ColumnMeta(table, column, isPrimary, data.ENUM.class, commonParams, col.getDefault$() == null ? null : getClassNameOfEnum(table, col).append('.').append(enumStringToEnum(col.getDefault$().text())), generateOnInsert, generateOnUpdate, isKeyForUpdate);
    }
    throw new IllegalArgumentException("Unknown class: " + cls);
}
Also used : org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Char) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Tinyint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Decimal) org.jaxdb.jsql.data(org.jaxdb.jsql.data) GeneratorExecutionException(org.jaxdb.ddlx.GeneratorExecutionException) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Bigint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Named) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Enum) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Boolean) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Clob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Datetime) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Smallint) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Integer) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Float) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Double) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Date) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Time) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Int) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Blob) org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary(org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Binary)

Example 25 with org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database

use of org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database in project jaxdb by jaxdb.

the class SqlJaxSBLoader method sqlx2sql.

static void sqlx2sql(final DBVendor vendor, final $Database database, final File sqlOutputFile) throws IOException {
    sqlOutputFile.getParentFile().mkdirs();
    final ArrayList<Row> rows = new ArrayList<>();
    final RowIterator iterator = new RowIterator(database);
    final Compiler compiler = Compiler.getCompiler(vendor);
    final TableToColumnToIncrement tableToColumnToIncrement = new TableToColumnToIncrement();
    while (iterator.hasNext()) {
        loadRow(rows, iterator.next(), vendor.getDialect(), compiler, tableToColumnToIncrement);
    }
    rows.sort(null);
    final Iterator<Row> rowIterator = rows.iterator();
    try (final OutputStreamWriter out = new FileWriter(sqlOutputFile)) {
        for (int i = 0; rowIterator.hasNext(); ++i) {
            if (i > 0)
                out.write('\n');
            out.append(rowIterator.next().toString()).append(';');
        }
        if (tableToColumnToIncrement.size() > 0)
            for (final Map.Entry<String, Map<String, Integer>> entry : tableToColumnToIncrement.entrySet()) for (final Map.Entry<String, Integer> columnToIncrement : entry.getValue().entrySet()) compiler.sequenceReset(null, out, entry.getKey(), columnToIncrement.getKey(), columnToIncrement.getValue() + 1);
    } catch (final SQLException e) {
        throw new RuntimeException(e);
    }
}
Also used : SQLException(java.sql.SQLException) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) org.jaxdb.www.datatypes_0_5.xL3gluGCXAA.$Tinyint(org.jaxdb.www.datatypes_0_5.xL3gluGCXAA.$Tinyint) org.jaxdb.www.datatypes_0_5.xL3gluGCXAA.$Smallint(org.jaxdb.www.datatypes_0_5.xL3gluGCXAA.$Smallint) org.jaxdb.www.datatypes_0_5.xL3gluGCXAA.$Bigint(org.jaxdb.www.datatypes_0_5.xL3gluGCXAA.$Bigint) OutputStreamWriter(java.io.OutputStreamWriter) org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row(org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Row) Map(java.util.Map)

Aggregations

Database (com.google.spanner.admin.database.v1.Database)21 Test (org.junit.Test)20 Database (org.molgenis.emx2.Database)14 ArrayList (java.util.ArrayList)11 AbstractMessage (com.google.protobuf.AbstractMessage)10 ByteString (com.google.protobuf.ByteString)8 Operation (com.google.longrunning.Operation)7 RestoreDatabaseRequest (com.google.spanner.admin.database.v1.RestoreDatabaseRequest)7 BeforeClass (org.junit.BeforeClass)6 Schema (org.molgenis.emx2.Schema)6 CreateDatabaseRequest (com.google.spanner.admin.database.v1.CreateDatabaseRequest)4 InstanceName (com.google.spanner.admin.database.v1.InstanceName)4 ListDatabasesPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse)3 CreateDatabaseMetadata (com.google.spanner.admin.database.v1.CreateDatabaseMetadata)3 RestoreDatabaseMetadata (com.google.spanner.admin.database.v1.RestoreDatabaseMetadata)3 GeneratorExecutionException (org.jaxdb.ddlx.GeneratorExecutionException)3 BackupName (com.google.spanner.admin.database.v1.BackupName)2 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)2 GetDatabaseRequest (com.google.spanner.admin.database.v1.GetDatabaseRequest)2 org.jaxdb.jsql.data (org.jaxdb.jsql.data)2