MappedBinary may not handle BLOBs correctly
Just looking at the source, we have:
def buildSetActualValue(accessor: Method, inst: AnyRef, columnName: String): (T, AnyRef) => Unit =
(inst, v) => doField(inst, accessor, {case f: MappedBinary[T] =>
val toSet = v match {
case null => null
case ba: Array[Byte] => ba
case other => other.toString.getBytes("UTF-8")
}
f.data() = toSet
f.orgData() = toSet
})
But the toSet doesn't have a case for getting a java.sql.Blob instance. I think that converting a BLOB to a String and then back to bytes is much less efficient than just doing:
val toSet = v match {
case null => null
case ba: Array[Byte] => ba
case blob : Blob => blob.getBytes(1, blob.length)
case other => other.toString.getBytes("UTF-8")
}
def buildSetActualValue(accessor: Method, inst: AnyRef, columnName: String): (T, AnyRef) => Unit =
(inst, v) => doField(inst, accessor, {case f: MappedBinary[T] =>
val toSet = v match {
case null => null
case ba: Array[Byte] => ba
case other => other.toString.getBytes("UTF-8")
}
f.data() = toSet
f.orgData() = toSet
})
But the toSet doesn't have a case for getting a java.sql.Blob instance. I think that converting a BLOB to a String and then back to bytes is much less efficient than just doing:
val toSet = v match {
case null => null
case ba: Array[Byte] => ba
case blob : Blob => blob.getBytes(1, blob.length)
case other => other.toString.getBytes("UTF-8")
}
Leave a comment
on 2010-02-06 20:47 *
By github.importer
Imported from GitHub: http://github.com/dpp/liftweb/issues/4/find