@@ -3,15 +3,20 @@ package org.squeryl.test
33import org .squeryl ._
44import org .squeryl .framework .{SchemaTester , RunTestsInsideTransaction }
55import java .util .UUID
6-
76import org .squeryl .test .PrimitiveTypeModeForTests ._
7+ import framework .SingleTestRun
88
99object UuidTests {
1010 class UuidAsProperty extends KeyedEntity [Long ] {
1111 val id : Long = 0
1212 val uuid = UUID .randomUUID
1313 }
14-
14+
15+ class UuidWithOption (val optionalUuid : Option [UUID ]) extends KeyedEntity [Long ] {
16+ def this () = this (Some (UUID .randomUUID()))
17+ val id : Long = 0
18+ }
19+
1520 class UuidAsId extends KeyedEntity [UUID ] {
1621 var id = UUID .randomUUID
1722 lazy val foreigns = TestSchema .uuidOneToMany.left(this )
@@ -25,6 +30,7 @@ object UuidTests {
2530 val uuidAsProperty = table[UuidAsProperty ]
2631 val uuidAsId = table[UuidAsId ]
2732 val uuidAsForeignKey = table[UuidAsForeignKey ]
33+ val uuidWithOption = table[UuidWithOption ]
2834
2935 val uuidOneToMany = oneToManyRelation(uuidAsId, uuidAsForeignKey).via(_.id === _.foreignUuid)
3036
@@ -52,6 +58,27 @@ abstract class UuidTests extends SchemaTester with RunTestsInsideTransaction{
5258 testObject.uuid should equal(uuidAsProperty.where(_.uuid in List (testObject.uuid)).single.uuid)
5359 }
5460
61+ test(" UuidOptional" , SingleTestRun ) {
62+ import TestSchema ._
63+
64+ val testObject = new UuidWithOption (None )
65+ testObject.save
66+
67+ val fromDb = uuidWithOption.lookup(testObject.id).get
68+ println(fromDb.optionalUuid)
69+ fromDb.optionalUuid should equal(None )
70+
71+ val uuid = UUID .randomUUID()
72+
73+ update(uuidWithOption)(p =>
74+ where(p.id === testObject.id)
75+ set(p.optionalUuid := Some (uuid))
76+ )
77+
78+ uuidWithOption.lookup(testObject.id).get.optionalUuid should equal(Some (uuid))
79+
80+ }
81+
5582 test(" UuidAsId" ) {
5683 import TestSchema ._
5784
0 commit comments