How to use #result with extended enumerations in SQLTemplate?

From: Michael Shea (mik..itido.com)
Date: Thu Jun 18 2009 - 16:13:02 EDT

  • Next message: Andrus Adamchik: "Re: DbLoader incompatible SQLite and lowercase-named tables?"

    Hi guys,

    I'm trying to use a SQLTemplate to retrieve some objects from my database.
    The objects in question use an ExtendedEnumeration object to map from
    integers to an enum.

    eg:

    public enum TaskType implements ExtendedEnumeration
    {
        TYPE_1( 1),
        TYPE_2(2),
        ...
        ...
       public Object getDatabaseValue()
       {
           return databaseValue; // This returns the integer passed in in
    the constructor.
       }
    }

    My SQLTemplate string looks like this:

    select distinct
    #result('taskType' 'my.package.TaskType' '' 'taskType'),
    #result('T.id' 'int' '' 'id')
    ....

    I've tried using both "my.package.TaskType" and "Integer" in the #result
    directive for retrieving the task type column.
    Using the enum class as the java type, I get this exception:

    java.lang.IllegalArgumentException: No enum const class
    my.package.TaskType.1
        at java.lang.Enum.valueOf(Enum.java:196)
        at
    org.apache.cayenne.access.types.ExtendedEnumType.lookup(ExtendedEnumType.java:167)
        at
    org.apache.cayenne.access.types.ExtendedEnumType.materializeObject(ExtendedEnumType.java:90)

    Using an Integer as the java type, I get a ClassCastException when I try
    to actually call Task.getTaskType() on the object I get back (it appears
    to be storing an Integer in the property on the object, so it blows up
    when it tries to return a TaskType enum).

    Does SQLTemplate support extended enumerations in the #result directive?
    If so, how do I use this properly?

    Thanks!

    Shea.



    This archive was generated by hypermail 2.0.0 : Thu Jun 18 2009 - 16:13:52 EDT