如何将Scala枚举用于JOOQ转换器

时间:2018-08-23 15:34:37

标签: scala enums jooq

我在文档中找到了如何通过EnumConverter将类型从值强制转换为Java枚举。 我试图为scalas枚举创建自己的转换器。枚举:

package com.enums

object BlockSize extends Enumeration {
  type BlockSize = Value

  val Small, Medium, Large, Wide = Value
}

转换器:

package com.converters

import com.jooqdb.enums.BlockSize
import com.jooqdb.enums.enums.BlockSize.BlockSize
import org.jooq.Converter

class BlockSizeConverter extends Converter[String, BlockSize] {
  override def from(databaseObject: String): BlockSize = if(databaseObject == null) null
    else BlockSize.withName(databaseObject)

  override def to(userObject: BlockSize): String = if(userObject == null) null
    else userObject.toString

  override def fromType(): Class[String] = classOf[String]

  override def toType: Class[BlockSize] = classOf[BlockSize.Value]
}

配置:

<forcedType>
  <userType>scala.Enumeration.Value</userType>
  <converter>com.converters.BlockSizeConverter</converter>
  <expression>some_table.block_size</expression>
</forcedType>

是否可以将JOOQ中的值绑定到scala枚举?

UPD:编译成功,但是publishLoca l由于生成scaladoc而失败。 sources in (Compile, doc) := Seq.empty的解决方法。无论如何,不​​能在Scala中使用此代码

0 个答案:

没有答案