开发者

Scala / Lift Mapper - unsigned MappedInt

开发者 https://www.devze.com 2023-03-23 19:40 出处:网络
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 {

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

精彩评论

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

关注公众号