Package org.jooq.conf

Examples of org.jooq.conf.MappedSchema


     */
    public void add(String inputSchema, String outputSchema) {
        logDeprecation();

        // Find existing mapped schema
        MappedSchema schema = null;
        for (MappedSchema s : mapping().getSchemata()) {
            if (inputSchema.equals(s.getInput())) {
                schema = s;
                break;
            }
        }

        if (schema == null) {
            schema = new MappedSchema().withInput(inputSchema);
            mapping().getSchemata().add(schema);
        }

        // Add new mapping
        schema.setOutput(outputSchema);
    }
View Full Code Here


     */
    public void add(final Table<?> inputTable, final String outputTable) {
        logDeprecation();

        // Try to find a pre-existing schema mapping in the settings
        MappedSchema schema = null;
        MappedTable table = null;

        for (MappedSchema s : mapping().getSchemata()) {
            if (inputTable.getSchema().getName().equals(s.getInput())) {

                // Find existing mapped table
                tableLoop:
                for (MappedTable t : s.getTables()) {
                    if (inputTable.getName().equals(t.getInput())) {
                        table = t;
                        break tableLoop;
                    }
                }

                schema = s;
                break;
            }
        }

        if (schema == null) {
            schema = new MappedSchema().withInput(inputTable.getSchema().getName());
            mapping().getSchemata().add(schema);
        }

        if (table == null) {
            table = new MappedTable().withInput(inputTable.getName());
            schema.getTables().add(table);
        }

        // Add new mapping
        table.setOutput(outputTable);
    }
View Full Code Here

        assertEquals("\"TABLEX\"", create2.render(TABLE1));
    }

    private RenderMapping mapping() {
        return new RenderMapping().withSchemata(
                   new MappedSchema().withInput("").withTables(
                       new MappedTable().withInput("TABLE1").withOutput("TABLEX")
                   )
               );
    }
View Full Code Here

    public void add(String inputSchema, String outputSchema) {
        if (ignoreMapping) return;
        logDeprecation();

        // Find existing mapped schema
        MappedSchema schema = null;
        for (MappedSchema s : mapping.getSchemata()) {
            if (inputSchema.equals(s.getInput())) {
                schema = s;
                break;
            }
        }

        if (schema == null) {
            schema = new MappedSchema().withInput(inputSchema);
            mapping.getSchemata().add(schema);
        }

        // Add new mapping
        schema.setOutput(outputSchema);
    }
View Full Code Here

    public void add(final Table<?> inputTable, final String outputTable) {
        if (ignoreMapping) return;
        logDeprecation();

        // Try to find a pre-existing schema mapping in the settings
        MappedSchema schema = null;
        MappedTable table = null;

        for (MappedSchema s : mapping.getSchemata()) {
            if (inputTable.getSchema().getName().equals(s.getInput())) {

                // Find existing mapped table
                tableLoop:
                for (MappedTable t : s.getTables()) {
                    if (inputTable.getName().equals(t.getInput())) {
                        table = t;
                        break tableLoop;
                    }
                }

                schema = s;
                break;
            }
        }

        if (schema == null) {
            schema = new MappedSchema().withInput(inputTable.getSchema().getName());
            mapping.getSchemata().add(schema);
        }

        if (table == null) {
            table = new MappedTable().withInput(inputTable.getName());
            schema.getTables().add(table);
        }

        // Add new mapping
        table.setOutput(outputTable);
    }
View Full Code Here

      settings = (settings != null) ? settings : new Settings();
        RenderMapping mapping = SettingsTools.getRenderMapping(settings);
        List<MappedSchema> schemata = mapping.getSchemata();

        if (schemata.size() == 0) {
            schemata.add(new MappedSchema()
                .withInput(TAuthor().getSchema().getName())
                .withOutput(Public.PUBLIC.getName()));
        }
        else {
            schemata.get(0)
View Full Code Here

        settings = (settings != null) ? settings : new Settings();
        RenderMapping mapping = SettingsTools.getRenderMapping(settings);
        List<MappedSchema> schemata = mapping.getSchemata();

        if (schemata.size() == 0) {
            schemata.add(new MappedSchema()
                .withInput(TAuthor().getSchema().getName())
                .withOutput(TAuthor().getSchema().getName() + getSchemaSuffix()));
        }
        else {
            schemata.get(0)
View Full Code Here

    @Test
    public void testTableMapping() throws Exception {
        Settings settings = new Settings()
            .withRenderMapping(new RenderMapping()
            .withSchemata(new MappedSchema()
            .withInput(TAuthor().getSchema() == null ? "" : TAuthor().getSchema().getName())
            .withTables(
                new MappedTable().withInput(TAuthor().getName()).withOutput(VAuthor().getName()),
                new MappedTable().withInput(TBook().getName()).withOutput(VBook().getName()))));
View Full Code Here

        // Map to self. This will work even for single-schema RDBMS
        // ---------------------------------------------------------------------
        Settings settings = new Settings()
            .withRenderMapping(new RenderMapping()
            .withSchemata(new MappedSchema()
            .withInput(TAuthor().getSchema().getName())
            .withOutput(TAuthor().getSchema().getName())
            .withTables(
                new MappedTable().withInput(TAuthor().getName()).withOutput(TAuthor().getName()),
                new MappedTable().withInput(TBook().getName()).withOutput(TBook().getName()))));

        Select<Record> query =
        create(settings).select(TBook_TITLE())
                       .from(TAuthor())
                       .join(TBook())
                       .on(TAuthor_ID().equal(TBook_AUTHOR_ID()))
                       .orderBy(TBook_ID().asc());

        Result<Record> result = query.fetch();

        assertEquals("1984", result.getValue(0, TBook_TITLE()));
        assertEquals("Animal Farm", result.getValue(1, TBook_TITLE()));
        assertEquals("O Alquimista", result.getValue(2, TBook_TITLE()));
        assertEquals("Brida", result.getValue(3, TBook_TITLE()));

        // Check for consistency when executing SQL manually
        String sql = query.getSQL();
        log.info("Executing", sql);
        assertEquals(result, create().fetch(sql, query.getBindValues().toArray()));

        // Schema mapping is supported in many RDBMS. But maintaining several
        // databases is non-trivial in some of them.
        switch (getDialect()) {
            case ASE:
            case CUBRID:
            case DB2:
            case DERBY:
            case H2:
            case HSQLDB:
            case INGRES:
            case ORACLE:
            case POSTGRES:
            case SQLITE:
            case SQLSERVER:
            case SYBASE:
                log.info("SKIPPING", "Schema mapping test");
                return;

            // Currently, only MySQL is tested with SchemaMapping
            case MYSQL:

                // But not when the schema is already re-written
                if (delegate.getClass() == jOOQMySQLTestSchemaRewrite.class) {
                    log.info("SKIPPING", "Schema mapping test");
                    return;
                }
        }

        // Map to a second schema
        // ---------------------------------------------------------------------
        settings = new Settings()
            .withRenderMapping(new RenderMapping()
            .withSchemata(new MappedSchema()
            .withInput(TAuthor().getSchema().getName())
            .withOutput(TAuthor().getSchema().getName() + "2")));

        Select<Record> q =
        create(settings).select(TBook_TITLE())
                       .from(TAuthor())
                       .join(TBook())
                       .on(TAuthor_ID().equal(TBook_AUTHOR_ID()))
                       .orderBy(TBook_ID().asc());

        // Assure that schema is replaced
        assertTrue(create(settings).render(q).contains(TAuthor().getSchema().getName() + "2"));
        assertTrue(q.getSQL().contains(TAuthor().getSchema().getName() + "2"));
        assertEquals(create(settings).render(q), q.getSQL());

        // Assure that results are correct
        result = q.fetch();
        assertEquals("1984", result.getValue(0, TBook_TITLE()));
        assertEquals("Animal Farm", result.getValue(1, TBook_TITLE()));
        assertEquals("O Alquimista", result.getValue(2, TBook_TITLE()));
        assertEquals("Brida", result.getValue(3, TBook_TITLE()));

        // [#995] Schema mapping in stored functions
        // -----------------------------------------
        Field<Integer> f1 = FOneField().cast(Integer.class);
        Field<Integer> f2 = FNumberField(42).cast(Integer.class);

        q =
        create(settings).select(f1, f2);

        // Assure that schema is replaced
        assertTrue(create(settings).render(q).contains(TAuthor().getSchema().getName() + "2"));
        assertTrue(q.getSQL().contains(TAuthor().getSchema().getName() + "2"));
        assertEquals(create(settings).render(q), q.getSQL());

        // Assure that results are correct
        Record record = q.fetchOne();
        assertEquals(1, (int) record.getValue(f1));
        assertEquals(42, (int) record.getValue(f2));

        // Map both schema AND tables
        // --------------------------
        settings = new Settings()
            .withRenderMapping(new RenderMapping()
            .withSchemata(new MappedSchema()
            .withInput(TAuthor().getSchema().getName())
            .withOutput(TAuthor().getSchema().getName() + "2")
            .withTables(
                new MappedTable().withInput(TAuthor().getName()).withOutput(VAuthor().getName()),
                new MappedTable().withInput(TBook().getName()).withOutput(VBook().getName()))));
View Full Code Here

        out.println(using(H2, new Settings().withRenderKeywordStyle(RenderKeywordStyle.LOWER)).render(select));

        Tools.title("A couple of settings at work - Mapping");
        out.println(using(H2, new Settings()
            .withRenderMapping(new RenderMapping()
                .withSchemata(new MappedSchema()
                    .withInput("PUBLIC")
                    .withOutput("test")
                    .withTables(new MappedTable()
                        .withInput("AUTHOR")
                        .withOutput("test-author"))
View Full Code Here

TOP

Related Classes of org.jooq.conf.MappedSchema

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.