Package org.jooq

Examples of org.jooq.Field


    @Test
    public void testComparisonPredicateTypeCoercion() throws Exception {
        // This test checks whether automatic type coercion works well for
        // comparison predicates

        Field integer = Table1.FIELD_ID1;
        Field string = Table1.FIELD_NAME1;
        Field object = fieldByName("ANY");

        // Check if a correct type was coerced correctly
        // ---------------------------------------------
        {
            Condition int_int = integer.eq(1);
            assertEquals("`TABLE1`.`ID1` = 1", r_refI().render(int_int));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(int_int).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition string_string = string.eq("1");
            assertEquals("`TABLE1`.`NAME1` = '1'", r_refI().render(string_string));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(string_string).peekIndex());
            context.assertIsSatisfied();
        }

        // Check if a convertible type was coerced correctly
        // -------------------------------------------------
        {
            Condition int_string = integer.eq("1");
            assertEquals("`TABLE1`.`ID1` = 1", r_refI().render(int_string));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(int_string).peekIndex());
            context.assertIsSatisfied();

            Condition string_int = string.eq(1);
            assertEquals("`TABLE1`.`NAME1` = '1'", r_refI().render(string_int));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(string_int).peekIndex());
            context.assertIsSatisfied();
        }

        // Check if ...
        // ------------
        {
            Condition object_int = object.eq(1);
            assertEquals("`ANY` = 1", r_refI().render(object_int));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(object_int).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition object_string = object.eq("1");
            assertEquals("`ANY` = '1'", r_refI().render(object_string));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(object_string).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition object_date = object.eq(Timestamp.valueOf("2012-12-21 15:30:00.0"));
            assertEquals("`ANY` = {ts '2012-12-21 15:30:00.0'}", r_refI().render(object_date));
            context.checking(new Expectations() {{
                oneOf(statement).setTimestamp(1, Timestamp.valueOf("2012-12-21 15:30:00.0"));
            }});
View Full Code Here


    @Test
    public void testInPredicateTypeCoercion() throws Exception {
        // [#2227] This test checks whether automatic type coercion works well for
        // IN predicates

        Field integer = Table1.FIELD_ID1;
        Field string = Table1.FIELD_NAME1;
        Field object = fieldByName("ANY");

        // Check if a correct type was coerced correctly
        // ---------------------------------------------
        {
            Condition int_int = integer.in(1);
            assertEquals("`TABLE1`.`ID1` in (1)", r_refI().render(int_int));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(int_int).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition string_string = string.in("1");
            assertEquals("`TABLE1`.`NAME1` in ('1')", r_refI().render(string_string));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(string_string).peekIndex());
            context.assertIsSatisfied();
        }

        // Check if a convertible type was coerced correctly
        // -------------------------------------------------
        {
            Condition int_string = integer.in("1");
            assertEquals("`TABLE1`.`ID1` in (1)", r_refI().render(int_string));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(int_string).peekIndex());
            context.assertIsSatisfied();

            Condition string_int = string.in(1);
            assertEquals("`TABLE1`.`NAME1` in ('1')", r_refI().render(string_int));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});

            assertEquals(2, b_ref().visit(string_int).peekIndex());
            context.assertIsSatisfied();
        }

        // Check if ...
        // ------------
        {
            Condition object_int = object.in(1);
            assertEquals("`ANY` in (1)", r_refI().render(object_int));
            context.checking(new Expectations() {{
                oneOf(statement).setInt(1, 1);
            }});

            assertEquals(2, b_ref().visit(object_int).peekIndex());
            context.assertIsSatisfied();
        }

        {
            Condition object_string = object.in("1");
            assertEquals("`ANY` in ('1')", r_refI().render(object_string));
            context.checking(new Expectations() {{
                oneOf(statement).setString(1, "1");
            }});
View Full Code Here

    public final void fromArray(Object[] array, Field<?>... f) {
        Fields accept = new Fields(f);
        int size = fields.size();

        for (int i = 0; i < size && i < array.length; i++) {
            Field field = fields.field(i);

            if (accept.field(field) != null) {
                Utils.setValue(this, field, array[i]);
            }
        }
View Full Code Here

        TableField<?, ?>[] references = key.getFieldsArray();
        TableField<?, ?>[] referenced = key.getKey().getFieldsArray();

        for (int i = 0; i < references.length; i++) {
            Field f1 = references[i];
            Field f2 = referenced[i];

            // [#2870] TODO: If lhs or rhs are aliased tables, extract the appropriate fields from them
            result.and(f1.equal(f2));
        }
View Full Code Here

   @Override public ColumnExpressions<?> mathOpValue(TypedValue.MathOpValue val, Void in) throws TypedValueVisitorException
   {
      ColumnExpressions<?> left = val.left.visit(this, in);
      ColumnExpressions<?> right = val.right.visit(this, in);
      Field leftField = (Field)left.getOnlyColumn();
      Field rightField = (Field)right.getOnlyColumn();
      Field resultField;
      switch(val.op)
      {
      case minus: resultField = leftField.minus(rightField); break;
      case plus: resultField = leftField.plus(rightField); break;
      case mul: resultField = leftField.mul(rightField); break;
View Full Code Here

//            right.columns[0] = new SQLFragment("FALSE");
//         }
//      }
      if (!left.isSingleColumn() || !right.isSingleColumn())
         throw new TypedValueVisitorException("Do not know how to compare multiple columns together");
      Field leftField = (Field)left.getOnlyColumn();
      Field rightField = (Field)right.getOnlyColumn();
      Condition result = null;
      switch (val.compOp)
      {
         case eq:
            result = leftField.eq(rightField);
View Full Code Here

TOP

Related Classes of org.jooq.Field

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.