Hello

2013/9/22 Rob Nikander <[email protected]>

> Hi,
>
> Is there a nice way to get around this? I can't set an int column the way
> you can in Java.
>
>    val userId: Int = ...
>
>    val u = dsl.update(t)
>         .set(t.MODIFIED_BY, userId)  // compile error here
>         .set(t.IS_ACTIVE, isActive)
>
> An implicit conversion from Int to java.lang.Integer won't satisfy it.
> Need to substitute userId with java.lang.Integer.valueOf(userId). Kind of
> annoying.
>
> I don't really understand the error message:
>
> type mismatch;  found   :
> org.jooq.TableField[foo.db.gen.tables.records.DocRecord,Integer]  required:
> org.jooq.Field[Any] Note: Integer <: Any
> (and org.jooq.TableField[foo.db.gen.tables.records.DocRecord,Integer] <:
> org.jooq.Field[Integer]), but Java-defined trait Field is invariant in type
> T. You may wish to investigate a wildcard type such as `_ <: Any`. (SLS
> 3.2.10)
> Why does it think it needs Field[Any]; the set method is generic.
>

This is indeed weird. From my intuitive (and far from thorough)
understanding, the Scala compiler should infer [T] from the first method
argument, just like the Java compile does. But I wouldn't be surprised if
this behaviour differs significantly, as soon as implicit conversions
apply. Are you using org.jooq.scala.Conversions? What would happen to this
statement, if you removed it? In particular these conversions:

  implicit def asSNumberField[T <: Number](f : Field[T]): SNumberField[T] =
f match {
    case AnyFieldWrapper(f) => f
    case NumberFieldWrapper(f) => f
    case _ => new NumberFieldWrapper(f)
  }

  implicit def asSAnyField[T](f : Field[T]): SAnyField[T] = f match {
    case AnyFieldWrapper(f) => f
    case _ => new AnyFieldWrapper(f)
  }


Also the isActive is a boolean, going to an int column. Also won't work
> without manual intervention.
>

In this case, you might want to consider forcing your isActive column to a
boolean type at code-generation time:
http://www.jooq.org/doc/3.1/manual/code-generation/custom-data-types/

I wonder if adding support for explicit Scala type converters make sense.
I'm thinking about stuff like the following pseudo-code:

public class IntConverter implements Converter<Integer, scala.Int> {

    @Override
    public Int from(Integer t) {
        return (Int) (Object) t;
    }

    @Override
    public Integer to(Int u) {
        return (Integer) (Object) u;
    }

    @Override
    public Class<Integer> fromType() {
        return Integer.class;
    }

    @Override
    public Class<Int> toType() {
        return Int.class;
    }
}

What do Scala users on this group think?

Cheers
Lukas

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to