Search in sources :

Example 1 with DDLx

use of org.jaxdb.ddlx.DDLx in project jaxdb by jaxdb.

the class SQL method ddlx2xsd.

public static void ddlx2xsd(final URL ddlxUrl, final File xsdFile) throws IOException, TransformerException {
    xsdFile.getParentFile().mkdirs();
    try {
        final DDLx ddlx = new DDLx(ddlxUrl);
        Transformer.transform(resource, ddlx.getMergedXml(), ddlx.getUrl().toString(), xsdFile);
    } catch (final SAXException e) {
        throw new RuntimeException(e);
    }
}
Also used : DDLx(org.jaxdb.ddlx.DDLx) SAXException(org.xml.sax.SAXException)

Example 2 with DDLx

use of org.jaxdb.ddlx.DDLx in project jaxdb by jaxdb.

the class SQLxTest method loadData.

public static int[] loadData(final Connection connection, final String name) throws IOException, SAXException, SQLException, TransformerException {
    final DDLx ddlx = new DDLx(ClassLoader.getSystemClassLoader().getResource(name + ".ddlx"));
    Schemas.truncate(connection, ddlx.getMergedSchema().getTable());
    final URL sqlx = ClassLoader.getSystemClassLoader().getResource("jaxdb/" + name + ".sqlx");
    assertNotNull(name, sqlx);
    return SQL.INSERT(connection, ($Database) Bindings.parse(sqlx));
}
Also used : DDLx(org.jaxdb.ddlx.DDLx) URL(java.net.URL)

Example 3 with DDLx

use of org.jaxdb.ddlx.DDLx in project jaxdb by jaxdb.

the class JSqlTest method createEntities.

static void createEntities(final String name) throws CompilationException, GeneratorExecutionException, IOException, SAXException, TransformerException {
    final URL url = assertNotNull(ClassLoader.getSystemClassLoader().getResource(name + ".ddlx"));
    final File destDir = new File("target/generated-test-sources/jaxdb");
    Generator.generate(url, name, destDir);
    final InMemoryCompiler compiler = new InMemoryCompiler();
    Files.walk(destDir.toPath()).filter(p -> p.getFileName().toString().endsWith(".java")).forEach(rethrow((Path p) -> compiler.addSource(new String(Files.readAllBytes(p)))));
    compiler.compile(destDir, "-g");
}
Also used : Bindings(org.jaxsb.runtime.Bindings) Connection(java.sql.Connection) DDLx(org.jaxdb.ddlx.DDLx) InMemoryCompiler(org.libj.jci.InMemoryCompiler) TransformerException(javax.xml.transform.TransformerException) Files(java.nio.file.Files) URL(java.net.URL) org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database(org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database) IOException(java.io.IOException) File(java.io.File) SQLException(java.sql.SQLException) GeneratorExecutionException(org.jaxdb.ddlx.GeneratorExecutionException) DML(org.jaxdb.jsql.DML) Schemas(org.jaxdb.ddlx.Schemas) Generator(org.jaxdb.jsql.generator.Generator) SAXException(org.xml.sax.SAXException) DBVendor(org.jaxdb.vendor.DBVendor) Throwing(org.libj.util.function.Throwing) CompilationException(org.libj.jci.CompilationException) Assert(org.junit.Assert) Path(java.nio.file.Path) Assertions.assertNotNull(org.libj.lang.Assertions.assertNotNull) Path(java.nio.file.Path) InMemoryCompiler(org.libj.jci.InMemoryCompiler) File(java.io.File) URL(java.net.URL)

Example 4 with DDLx

use of org.jaxdb.ddlx.DDLx in project jaxdb by jaxdb.

the class JSqlTest method loadEntitiesJaxSB.

@SuppressWarnings("unchecked")
static int loadEntitiesJaxSB(final Connection connection, final String name) throws ClassNotFoundException, IOException, SAXException, SQLException, TransformerException {
    Database.threadLocal((Class<? extends Schema>) Class.forName(Entities.class.getPackage().getName() + "." + name)).connectPrepared(() -> connection);
    final URL sqlx = ClassLoader.getSystemClassLoader().getResource("jaxdb/" + name + ".sqlx");
    assertNotNull(sqlx);
    final $Database database = ($Database) Bindings.parse(sqlx);
    final DDLx ddlx = new DDLx(ClassLoader.getSystemClassLoader().getResource(name + ".ddlx"));
    Schemas.truncate(connection, ddlx.getMergedSchema().getTable());
    final Batch batch = new Batch();
    final int expectedCount = DBVendor.valueOf(connection.getMetaData()) == DBVendor.ORACLE ? 0 : 1;
    for (final data.Table<?> table : Entities.toEntities(database)) batch.addStatement(INSERT(table), (e, c) -> assertEquals(expectedCount, c));
    return batch.execute();
}
Also used : Bindings(org.jaxsb.runtime.Bindings) Connection(java.sql.Connection) DDLx(org.jaxdb.ddlx.DDLx) InMemoryCompiler(org.libj.jci.InMemoryCompiler) TransformerException(javax.xml.transform.TransformerException) Files(java.nio.file.Files) URL(java.net.URL) org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database(org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database) IOException(java.io.IOException) File(java.io.File) SQLException(java.sql.SQLException) GeneratorExecutionException(org.jaxdb.ddlx.GeneratorExecutionException) DML(org.jaxdb.jsql.DML) Schemas(org.jaxdb.ddlx.Schemas) Generator(org.jaxdb.jsql.generator.Generator) SAXException(org.xml.sax.SAXException) DBVendor(org.jaxdb.vendor.DBVendor) Throwing(org.libj.util.function.Throwing) CompilationException(org.libj.jci.CompilationException) Assert(org.junit.Assert) Path(java.nio.file.Path) Assertions.assertNotNull(org.libj.lang.Assertions.assertNotNull) DDLx(org.jaxdb.ddlx.DDLx) org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database(org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database) URL(java.net.URL)

Aggregations

DDLx (org.jaxdb.ddlx.DDLx)4 URL (java.net.URL)3 SAXException (org.xml.sax.SAXException)3 File (java.io.File)2 IOException (java.io.IOException)2 Files (java.nio.file.Files)2 Path (java.nio.file.Path)2 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 TransformerException (javax.xml.transform.TransformerException)2 GeneratorExecutionException (org.jaxdb.ddlx.GeneratorExecutionException)2 Schemas (org.jaxdb.ddlx.Schemas)2 DML (org.jaxdb.jsql.DML)2 Generator (org.jaxdb.jsql.generator.Generator)2 DBVendor (org.jaxdb.vendor.DBVendor)2 org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database (org.jaxdb.www.sqlx_0_5.xLygluGCXAA.$Database)2 Bindings (org.jaxsb.runtime.Bindings)2 Assert (org.junit.Assert)2 CompilationException (org.libj.jci.CompilationException)2 InMemoryCompiler (org.libj.jci.InMemoryCompiler)2