Package org.jooq

Examples of org.jooq.RenderContext


        Param<String> i1 = inline("abc'def");
        Param<Integer> i2 = inline(123);
        Param<Double> i3 = inline(123.0);
        Param<Date> i4 = inline(Date.valueOf("1981-07-10"));

        RenderContext r_refI = r_refI();
        RenderContext r_refP = r_refP();
        RenderContext r_ref = r_ref();

        assertEquals("'abc''def'", r_refI.render(i1));
        assertEquals("'abc''def'", r_refP.render(i1));
        assertEquals("'abc''def'", r_ref.render(i1));

        assertEquals("123", r_refI.render(i2));
        assertEquals("123", r_refP.render(i2));
        assertEquals("123", r_ref.render(i2));

        assertEquals("123.0", r_refI.render(i3));
        assertEquals("123.0", r_refP.render(i3));
        assertEquals("123.0", r_ref.render(i3));

        assertEquals("{d '1981-07-10'}", r_refI.render(i4));
        assertEquals("{d '1981-07-10'}", r_refP.render(i4));
        assertEquals("{d '1981-07-10'}", r_ref.render(i4));
    }
View Full Code Here


    @Test
    public void testRenderNameStyle() {
        Query q = create.select(val(1)).from(TABLE1).where(FIELD_ID1.equal(2));

        RenderContext r_refI = r_refI();
        RenderContext r_refP = r_refP();
        RenderContext r_ref = r_ref();

        r_refI.configuration().settings().setRenderNameStyle(RenderNameStyle.AS_IS);
        r_refP.configuration().settings().setRenderNameStyle(RenderNameStyle.AS_IS);
        r_ref.configuration().settings().setRenderNameStyle(RenderNameStyle.AS_IS);

        assertEquals("select 1 from TABLE1 where TABLE1.ID1 = 2", r_refI.render(q));
        assertEquals("select :1 from TABLE1 where TABLE1.ID1 = :2", r_refP.render(q));
        assertEquals("select ? from TABLE1 where TABLE1.ID1 = ?", r_ref.render(q));

        r_refI.configuration().settings().setRenderNameStyle(RenderNameStyle.LOWER);
        r_refP.configuration().settings().setRenderNameStyle(RenderNameStyle.LOWER);
        r_ref.configuration().settings().setRenderNameStyle(RenderNameStyle.LOWER);

        assertEquals("select 1 from table1 where table1.id1 = 2", r_refI.render(q));
        assertEquals("select :1 from table1 where table1.id1 = :2", r_refP.render(q));
        assertEquals("select ? from table1 where table1.id1 = ?", r_ref.render(q));

        r_refI.configuration().settings().setRenderNameStyle(RenderNameStyle.UPPER);
        r_refP.configuration().settings().setRenderNameStyle(RenderNameStyle.UPPER);
        r_ref.configuration().settings().setRenderNameStyle(RenderNameStyle.UPPER);

        assertEquals("select 1 from TABLE1 where TABLE1.ID1 = 2", r_refI.render(q));
        assertEquals("select :1 from TABLE1 where TABLE1.ID1 = :2", r_refP.render(q));
        assertEquals("select ? from TABLE1 where TABLE1.ID1 = ?", r_ref.render(q));

        r_refI.configuration().settings().setRenderNameStyle(RenderNameStyle.QUOTED);
        r_refP.configuration().settings().setRenderNameStyle(RenderNameStyle.QUOTED);
        r_ref.configuration().settings().setRenderNameStyle(RenderNameStyle.QUOTED);

        assertEquals("select 1 from `TABLE1` where `TABLE1`.`ID1` = 2", r_refI.render(q));
        assertEquals("select :1 from `TABLE1` where `TABLE1`.`ID1` = :2", r_refP.render(q));
        assertEquals("select ? from `TABLE1` where `TABLE1`.`ID1` = ?", r_ref.render(q));
    }
View Full Code Here

    @Test
    public void testRenderNameStyleWithSpecialCharacters() {
        Query q = create.select(val(1).as("Aa `Bb` Cc")).from(TABLE1.as("Xx ''Yy''\\ Zz"));

        RenderContext r_refI = r_refI();

        r_refI.configuration().settings().setRenderNameStyle(RenderNameStyle.AS_IS);
        assertEquals("select 1 as Aa `Bb` Cc from TABLE1 as Xx ''Yy''\\ Zz", r_refI.render(q));

        r_refI.configuration().settings().setRenderNameStyle(RenderNameStyle.LOWER);
        assertEquals("select 1 as aa `bb` cc from table1 as xx ''yy''\\ zz", r_refI.render(q));

        r_refI.configuration().settings().setRenderNameStyle(RenderNameStyle.UPPER);
        assertEquals("select 1 as AA `BB` CC from TABLE1 as XX ''YY''\\ ZZ", r_refI.render(q));

        r_refI.configuration().settings().setRenderNameStyle(RenderNameStyle.QUOTED);
        assertEquals("select 1 as `Aa ``Bb`` Cc` from `TABLE1` as `Xx ''Yy''\\ Zz`", r_refI.render(q));
    }
View Full Code Here

    @Test
    public void testRenderKeywordStyle() {
        Query q = create.select(val(1)).from(TABLE1).where(FIELD_ID1.equal(2));

        RenderContext r_refI = r_refI();
        RenderContext r_refP = r_refP();
        RenderContext r_ref = r_ref();

        r_refI.configuration().settings().setRenderKeywordStyle(RenderKeywordStyle.UPPER);
        r_refP.configuration().settings().setRenderKeywordStyle(RenderKeywordStyle.UPPER);
        r_ref.configuration().settings().setRenderKeywordStyle(RenderKeywordStyle.UPPER);

        assertEquals("SELECT 1 FROM `TABLE1` WHERE `TABLE1`.`ID1` = 2", r_refI.render(q));
        assertEquals("SELECT :1 FROM `TABLE1` WHERE `TABLE1`.`ID1` = :2", r_refP.render(q));
        assertEquals("SELECT ? FROM `TABLE1` WHERE `TABLE1`.`ID1` = ?", r_ref.render(q));

        r_refI.configuration().settings().setRenderKeywordStyle(RenderKeywordStyle.LOWER);
        r_refP.configuration().settings().setRenderKeywordStyle(RenderKeywordStyle.LOWER);
        r_ref.configuration().settings().setRenderKeywordStyle(RenderKeywordStyle.LOWER);

        assertEquals("select 1 from `TABLE1` where `TABLE1`.`ID1` = 2", r_refI.render(q));
        assertEquals("select :1 from `TABLE1` where `TABLE1`.`ID1` = :2", r_refP.render(q));
        assertEquals("select ? from `TABLE1` where `TABLE1`.`ID1` = ?", r_ref.render(q));
    }
View Full Code Here

        assertEquals(NAMED, r_refP().paramType());
    }

    @Test
    public void testData() {
        RenderContext ctx = create.renderContext();
        ctx.data("key", "value");

        TestDataQueryPart part = new TestDataQueryPart();
        ctx.render(part);
        assertEquals("value", part.value);
    }
View Full Code Here

                  AbstractRoutine.this.type);
        }

        @Override
        public void accept(Context<?> ctx) {
            RenderContext local = create(ctx).renderContext();
            toSQLQualifiedName(local);

            Field<?>[] array = new Field<?>[getInParameters().size()];

            int i = 0;
            for (Parameter<?> p : getInParameters()) {

                // Disambiguate overloaded function signatures
                if (POSTGRES == ctx.dialect() && isOverloaded()) {
                    array[i] = getInValues().get(p).cast(p.getType());
                }
                else {
                    array[i] = getInValues().get(p);
                }

                i++;
            }

            Field<T> result = function(local.render(), getDataType(), array);

            // [#3592] Decrease SQL -> PL/SQL context switches with Oracle Scalar Subquery Caching
            if (TRUE.equals(settings(ctx.configuration()).isRenderScalarSubqueriesForStoredFunctions())) {
                result = DSL.select(result).asField();
            }
View Full Code Here

        return delegate(ctx).clauses(ctx);
    }

    private final QueryPartInternal delegate(Context<?> ctx) {
        final Configuration configuration = ctx.configuration();
        final RenderContext render = ctx instanceof RenderContext ? (RenderContext) ctx : null;

        SQLDialect family = configuration.dialect().family();

        // [#3505] TODO: Emulate this where it is not supported
        if (rightQuantified != null) {
            return new Native();
        }

        // [#2395] These dialects have full native support for comparison
        // predicates with row value expressions and subqueries:
        else if (asList(H2, HSQLDB, MARIADB, MYSQL, POSTGRES).contains(family)) {
            return new Native();
        }

        // [#2395] These dialects have native support for = and <>
        else if (
            asList(H2, HSQLDB, MARIADB, MYSQL, POSTGRES).contains(family) &&
            asList(EQUALS, NOT_EQUALS).contains(comparator)) {

            return new Native();
        }

        // [#2395] These dialects have native support for IN and NOT IN
        else if (
            asList(H2, HSQLDB, MARIADB, MYSQL, POSTGRES).contains(family) &&
            asList(IN, NOT_IN).contains(comparator)) {

            return new Native();
        }

        // [#2395] All other configurations have to be emulated
        else {
            String table = render == null ? "t" : render.nextAlias();

            List<String> names = new ArrayList<String>();
            for (int i = 0; i < left.size(); i++) {
                names.add(table + "_" + i);
            }
View Full Code Here

            }
        }
    }

    private final String getQualifiedName(Configuration configuration) {
        RenderContext local = create(configuration).renderContext();
        Schema mappedSchema = Util.getMappedSchema(configuration, sequence.schema);

        if (mappedSchema != null && configuration.getDialect() != CUBRID) {
            local.sql(mappedSchema);
            local.sql(".");
        }

        local.literal(sequence.name);
        return local.render();
    }
View Full Code Here

    /**
     * Simulate the LIMIT / OFFSET clause in the {@link SQLDialect#DB2},
     * {@link SQLDialect#SQLSERVER} and {@link SQLDialect#SYBASE} dialects
     */
    private final void toSQLReferenceLimitDB2SQLServerSybase(RenderContext context) {
        RenderContext local = new DefaultRenderContext(context);
        toSQLReference0(local);
        String enclosed = local.render();

        String subqueryName = "limit_" + Util.hash(enclosed);
        String rownumName = "rownum_" + Util.hash(enclosed);

        context.keyword("select * from (")
View Full Code Here

    /**
     * Simulate the LIMIT / OFFSET clause in the {@link SQLDialect#ORACLE}
     * dialect
     */
    private final void toSQLReferenceLimitOracle(RenderContext context) {
        RenderContext local = new DefaultRenderContext(context);
        toSQLReference0(local);
        String enclosed = local.render();

        String subqueryName = "limit_" + Util.hash(enclosed);
        String rownumName = "rownum_" + Util.hash(enclosed);

        context.keyword("select * from (")
View Full Code Here

TOP

Related Classes of org.jooq.RenderContext

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.