Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squeryl-Record integration should be Record "dirty_?" field aware #1259

Merged
merged 1 commit into from May 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -141,15 +141,30 @@ class RecordMetaDataFactory extends FieldMetaDataFactory {
fieldScale getOrElse super.scale 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) * Sets the value which was retrieved from the DB into the appropriate Record field
typedField.setFromAny(Box !! value) */
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)) 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 { override def get(o: AnyRef) = fieldFor(o) match {
case enumField: EnumTypedField[_] => enumField.valueBox match { case enumField: EnumTypedField[_] => enumField.valueBox match {
case Full(enum: Enumeration#Value) => enum.id: java.lang.Integer case Full(enum: Enumeration#Value) => enum.id: java.lang.Integer
Expand All @@ -161,7 +176,7 @@ class RecordMetaDataFactory extends FieldMetaDataFactory {
} }
case other => other.valueBox match { case other => other.valueBox match {
case Full(c: Calendar) => new Timestamp(c.getTime.getTime) case Full(c: Calendar) => new Timestamp(c.getTime.getTime)
case Full(other) => other case Full(other: AnyRef) => other
case _ => null case _ => null
} }
} }
Expand Down
Expand Up @@ -352,6 +352,12 @@ object SquerylRecordSpec extends Specification("SquerylRecord Specification") {
val columnDefinition = new PostgreSqlAdapter().writeColumnDeclaration(fieldMetaData, false, MySchema) val columnDefinition = new PostgreSqlAdapter().writeColumnDeclaration(fieldMetaData, false, MySchema)
columnDefinition.endsWith("numeric(" + Company.employeeSatisfaction.context.getPrecision() +"," + Company.employeeSatisfaction.scale + ")") must_== true 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 }
}


} }


Expand Down