Enumerations as strings?

216 views
Skip to first unread message

Jeppe Nejsum Madsen

unread,
Apr 3, 2013, 9:57:52 AM4/3/13
to squ...@googlegroups.com
Hi

I've seen a few old threads on storing Enumerations of strings, but no real clean solutions.

Is there a clean way to do this using 0.9.6?

/Jeppe

Tomer Gabel

unread,
Apr 3, 2013, 11:04:58 AM4/3/13
to squ...@googlegroups.com
Not without a custom type, I believe. Max?



/Jeppe

--
You received this message because you are subscribed to the Google Groups "Squeryl" group.
To unsubscribe from this group and stop receiving emails from it, send an email to squeryl+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Maxime Lévesque

unread,
Apr 3, 2013, 2:00:10 PM4/3/13
to Squeryl

At least, see Adam Hooper's email from a few days ago, 
there are also a few other tweaks required...

Jeppe Nejsum Madsen

unread,
Apr 3, 2013, 3:43:33 PM4/3/13
to squ...@googlegroups.com
On Wed, Apr 3, 2013 at 8:00 PM, Maxime Lévesque <maxime....@gmail.com> wrote:

At least, see Adam Hooper's email from a few days ago, 
there are also a few other tweaks required...


Ok, looked at that and have created the custom types that overrides enumValueToTE (step 2 from Adam's mail), but it seems like it still doesn't work:

Message: java.lang.RuntimeException: could not map row :
ResultSetRow:[#1->9:Long,#2->Test 1:String,#3->2013-03-21 17:26:58.685:Timestamp,#4->499:Integer,#5->1a1d61bb-6a05-4473-a0ce-b526666b716c:String,#6->f7a807b6-ff5d-404c-9c61-bedf5581e2d0:UUID,#7->FP:String,#8->5:Integer]
 with mapper :
'ResultSetMapper:107b954b($(2->PolicyViewItem.name:java.lang.String),$(3->PolicyViewItem.updated_at:org.joda.time.LocalDateTime),$(4->PolicyViewItem.org_unit_id:java.lang.Long),$(5->PolicyViewItem.url_name:java.lang.String),$(6->PolicyViewItem.policy_id:java.util.UUID),$(7->PolicyViewItem.policy_type:scala.Enumeration$Val),$(8->PolicyViewItem.tenant_id:java.lang.Long))--*
	org.squeryl.internals.ResultSetMapper.map(ResultSetMapper.scala:237)
	org.squeryl.View.give(View.scala:89)
....
Caught and thrown by: Message: org.postgresql.util.PSQLException: Bad value for type int : FP org.postgresql.jdbc2.AbstractJdbc2ResultSet.toInt(AbstractJdbc2ResultSet.java:2759) org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2003) org.squeryl.internals.FieldMapper$$anon$30.map(FieldMapper.scala:266) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) org.squeryl.internals.FieldMapper$$anonfun$resultSetHandlerFor$1.apply(FieldMapper.scala:319) org.squeryl.internals.FieldMapper$$anonfun$resultSetHandlerFor$1.apply(FieldMapper.scala:318) org.squeryl.internals.FieldMetaData.setFromResultSet(FieldMetaData.scala:297) org.squeryl.internals.ColumnToFieldMapper.map(ResultSetMapper.scala:112) org.squeryl.internals.ResultSetMapper$$anonfun$map$2.apply(ResultSetMapper.scala:233) org.squeryl.internals.ResultSetMapper$$anonfun$map$2.apply(ResultSetMapper.scala:232)

Looking into FieldMapper it seems like there's some explicit references to the embedded enumValueTEF.

But maybe that's the "few other tweaks" you mentioned :-)

Any further hints?

/Jeppe

Adam Hooper

unread,
Apr 10, 2013, 3:32:22 PM4/10/13
to squ...@googlegroups.com
On Wednesday, April 3, 2013 3:43:33 PM UTC-4, Jeppe Nejsum Madsen wrote:
On Wed, Apr 3, 2013 at 8:00 PM, Maxime Lévesque <maxime....@gmail.com> wrote:

At least, see Adam Hooper's email from a few days ago, 
there are also a few other tweaks required...


Ok, looked at that and have created the custom types that overrides enumValueToTE (step 2 from Adam's mail), but it seems like it still doesn't work:

Looking into FieldMapper it seems like there's some explicit references to the embedded enumValueTEF.

But maybe that's the "few other tweaks" you mentioned :-)

Any further hints?

I spent several hours working at it; I have a sketch of a solution drawn up, but it requires non-trivial changes to Squeryl itself.

So for my current project, I'm postponing ENUM support and sticking with Squeryl's default INT. (I have the luxury of being able to modify the database schema to suit my needs.) It shouldn't be difficult to adjust the database later, when Squeryl supports ENUM.

Enjoy life,
Adam

Maxime Lévesque

unread,
Apr 10, 2013, 3:53:06 PM4/10/13
to Squeryl
Jeppe and Adam, are your experiments could you post your experiments
on String enum on github ?
I'd like to look at them.

Maxime Lévesque

unread,
Apr 10, 2013, 3:55:19 PM4/10/13
to Squeryl
Typing stuttering problem here, correction :

Could you post your experiments on String enum on github ?

Jeppe Nejsum Madsen

unread,
Apr 11, 2013, 4:29:24 AM4/11/13
to squ...@googlegroups.com
Sure. I'll try to make a standalone project this week.

/Jeppe

Jeppe Nejsum Madsen

unread,
Apr 11, 2013, 11:11:59 AM4/11/13
to squ...@googlegroups.com
And here it is :-) 

https://github.com/jeppenejsum/enumtest

Let me know if you have any questions

/Jeppe

Reply all
Reply to author
Forward
0 new messages