Package org.jooq

Examples of org.jooq.Schema


        return result;
    }

    protected final Table<?> getTable(String name) throws Exception {
        Schema schema = TAuthor().getSchema();

        if (schema == null) {
            Class<?> tables = Class.forName("org.jooq.test." + getDialect().getName().toLowerCase() + ".generatedclasses.Tables");
            return (Table<?>) tables.getField(name).get(tables);
        }
        else {
            Table<?> result = schema.getTable(name);

            if (result == null) {
                result = schema.getTable(name.toUpperCase());
            }

            if (result == null) {
                result = schema.getTable(name.toLowerCase());
            }

            return result;
        }
    }
View Full Code Here


    @Test
    public void testMetaModel() throws Exception {

        // Test correct source code generation for the meta model
        Schema schema = TAuthor().getSchema();
        if (schema != null) {
            int sequences = 0;

            if (cSequences() != null) {
                sequences++;

                // DB2 has an additional sequence for the T_TRIGGERS table
                if (getDialect() == DB2 ||
                    getDialect() == H2) {

                    sequences++;
                }

                // CUBRID generates sequences for AUTO_INCREMENT columns
                else if (getDialect() == CUBRID) {
                    sequences += 3;
                }

                // Oracle has additional sequences for [#961]
                else if (getDialect() == ORACLE) {
                    sequences += 5;
                }
            }

            assertEquals(sequences, schema.getSequences().size());
            for (Table<?> table : schema.getTables()) {
                assertEquals(table, schema.getTable(table.getName()));
            }
            for (UDT<?> udt : schema.getUDTs()) {
                assertEquals(udt, schema.getUDT(udt.getName()));
            }
            for (Sequence<?> sequence : schema.getSequences()) {
                assertEquals(sequence, schema.getSequence(sequence.getName()));
            }

            int tables = 17;

            // The additional T_DIRECTORY table for recursive queries
            if (supportsRecursiveQueries()) {
                tables++;
            }

            // The additional T_TRIGGERS table for INSERT .. RETURNING
            if (TTriggers() != null) {
                tables++;
            }

            // The additional T_UNSIGNED table
            if (TUnsigned() != null) {
                tables++;
            }

            // The additional T_IDENTITY table
            if (TIdentity() != null) {
                tables++;
            }

            // The additional T_IDENTITY_PK table
            if (TIdentityPK() != null) {
                tables++;
            }

            // [#959] The T_959 table for enum collisions with Java keywords
            if (getDialect() == MYSQL ||
                getDialect() == POSTGRES) {
                tables++;
            }

            // [#986] Some foreign key name collision checks
            if (getDialect() == ASE ||
                getDialect() == CUBRID ||
                getDialect() == DB2 ||
                getDialect() == POSTGRES ||
                getDialect() == SQLITE ||
                getDialect() == SYBASE) {

                tables += 2;
            }

            if (TArrays() == null) {
                assertEquals(tables, schema.getTables().size());
            }

            // [#624] The V_INCOMPLETE view is only available in Oracle
            // [#877] The T_877 table is only available in H2
            else if (getDialect() == ORACLE ||
                     getDialect() == H2) {
                assertEquals(tables + 2, schema.getTables().size());
            }

            // [#610] Collision-prone entities are only available in HSQLDB
            else if (getDialect() == HSQLDB) {
                assertEquals(tables + 11, schema.getTables().size());
            }

            else {
                assertEquals(tables + 1, schema.getTables().size());
            }

            if (cUAddressType() == null) {
                assertEquals(0, schema.getUDTs().size());
            }
            // [#643] The U_INVALID types are only available in Oracle
            // [#799] The member procedure UDT's too
            else if (getDialect() == ORACLE) {
                assertEquals(7, schema.getUDTs().size());
            }
            else {
                assertEquals(2, schema.getUDTs().size());
            }
        }

        // Test correct source code generation for identity columns
        assertNull(TAuthor().getIdentity());
View Full Code Here

    public final void toSQL(RenderContext context) {
        if (alias != null) {
            alias.toSQL(context);
        }
        else {
            Schema mappedSchema = Util.getMappedSchema(context, getSchema());

            if (mappedSchema != null) {
                context.sql(mappedSchema);
                context.sql(".");
            }
View Full Code Here

        context.sql(value);
    }

    private final void toSQLQualifiedName(RenderContext context) {
        Schema mappedSchema = Util.getMappedSchema(context, getSchema());

        if (mappedSchema != null) {
            context.sql(mappedSchema);
            context.sql(".");
        }
View Full Code Here

            case DB2:

            // Assume default behaviour if dialect is not available
            default: {
                UDT<?> udt = record.getUDT();
                Schema mappedSchema = Util.getMappedSchema(context, udt.getSchema());

                if (mappedSchema != null) {
                    return mappedSchema + "." + udt.getName();
                }
                else {
View Full Code Here

        // [#1693] This needs to return the fully qualified SQL type name, in
        // case the connected user is not the owner of the UDT
        Configuration configuration = localConfiguration();
        if (configuration != null) {
            Schema schema = Utils.getMappedSchema(configuration, getUDT().getSchema());

            if (schema != null) {
                sb.append(schema.getName());
                sb.append(".");
            }
        }

        sb.append(getUDT().getName());
View Full Code Here

    public final void accept(Context<?> ctx) {
        accept0(ctx, false);
    }

    private final void accept0(Context<?> ctx, boolean asStringLiterals) {
        Schema mappedSchema = Utils.getMappedSchema(ctx.configuration(), schema);

        if (mappedSchema != null && ctx.family() != CUBRID) {
            if (asStringLiterals) {
                ctx.visit(inline(mappedSchema.getName()))
                   .sql(", ");
            }
            else {
                ctx.visit(mappedSchema)
                   .sql(".");
View Full Code Here

            else if (EnumType.class.isAssignableFrom(type)) {
                render.sql(getBindVariable(render));

                // [#968] Don't cast "synthetic" enum types (note, val can be null!)
                EnumType e = (EnumType) type.getEnumConstants()[0];
                Schema schema = e.getSchema();

                if (schema != null) {
                    render.sql("::");

                    schema = using(render.configuration()).map(schema);
View Full Code Here

TOP

Related Classes of org.jooq.Schema

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.