Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Makes Squeryl-Record both aware of the dirty_? flag, which is reset a…

…fter values are loaded from the DB, and utilize runSafe during data loading.
  • Loading branch information...
commit 27f5c8b435705e9f90769847753d49dd27985ec9 1 parent 9c53f7e
Dave Whittaker davewhittaker authored
25 persistence/squeryl-record/src/main/scala/net/liftweb/squerylrecord/RecordMetaDataFactory.scala
View
@@ -141,15 +141,30 @@ class RecordMetaDataFactory extends FieldMetaDataFactory {
fieldScale getOrElse super.scale
}
- private def fieldFor(o: AnyRef) = getter.get.invoke(o).asInstanceOf[TypedField[_ <: AnyRef]]
+ private def fieldFor(o: AnyRef) = getter.get.invoke(o) match {
+ case tf: TypedField[_] => tf
+ case other => org.squeryl.internals.Utils.throwError("Field's used with Squeryl must inherit from net.liftweb.record.TypedField : " + other )
+ }
- override def set(target: AnyRef, value: AnyRef) = {
- val typedField: TypedField[_] = fieldFor(target)
- typedField.setFromAny(Box !! value)
+ /**
+ * Sets the value which was retrieved from the DB into the appropriate Record field
+ */
+ override def set(target: AnyRef, value: AnyRef) = target match {
+ case record: Record[_] =>
+ record.runSafe {
+ val typedField: TypedField[_] = fieldFor(target)
+ typedField.setFromAny(Box !! value)
+ typedField.resetDirty
+ }
+ case other =>
+ org.squeryl.internals.Utils.throwError("RecordMetaDataFactory can not set fields on non Record objects : " + other)
}
override def setFromResultSet(target: AnyRef, rs: ResultSet, index: Int) = set(target, resultSetHandler(rs, index))
+ /**
+ * Extracts the value from the field referenced by o that will be stored in the DB
+ */
override def get(o: AnyRef) = fieldFor(o) match {
case enumField: EnumTypedField[_] => enumField.valueBox match {
case Full(enum: Enumeration#Value) => enum.id: java.lang.Integer
@@ -161,7 +176,7 @@ class RecordMetaDataFactory extends FieldMetaDataFactory {
}
case other => other.valueBox match {
case Full(c: Calendar) => new Timestamp(c.getTime.getTime)
- case Full(other) => other
+ case Full(other: AnyRef) => other
case _ => null
}
}
6 persistence/squeryl-record/src/test/scala/net/liftweb/squerylrecord/SquerylRecordSpec.scala
View
@@ -352,6 +352,12 @@ object SquerylRecordSpec extends Specification("SquerylRecord Specification") {
val columnDefinition = new PostgreSqlAdapter().writeColumnDeclaration(fieldMetaData, false, MySchema)
columnDefinition.endsWith("numeric(" + Company.employeeSatisfaction.context.getPrecision() +"," + Company.employeeSatisfaction.scale + ")") must_== true
}
+
+ forExample("Properly reset the dirty_? flag after loading entities") >> inTransaction {
+ val company = from(companies)(company =>
+ select(company)).page(0, 1).single
+ company.allFields map { f => f.dirty_? must_== false }
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.