开发者

Scala / Lift Mapper - unsigned MappedInt

Is it possible to define an unsigned mapped Integer in Lift? I could not find anything about it.

class Project extends LongKeyedMapper[Project] with IdPK {
    def getSingleton = Project
    ...
    object budget extends MappedInt(this) // should be uns开发者_如何学编程igned!
    ...
}


Since there are not unsigned ints in scala or java, all you can do is write a runtime check. Something like this should do it: (haven't tested it)

object budget extends MappedInt(this) {
  override def validations = {
    ((value:Int) =>
      if (value < 0)
        FieldError(fieldOwner, Text("Budget must not be negative"))::Nil
      else
        Nil)
    :: super.validations
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜