Permalink
Browse files

Don't set dirty_? when loading MappedDecimal. Closes #1116

  • Loading branch information...
1 parent 1c0980b commit 49de1fca1af83a4037dc169343cfdd1b9ba30e5d @jeppenejsum jeppenejsum committed Sep 16, 2011
@@ -61,7 +61,7 @@ abstract class MappedDecimal[T <: Mapper[T]] (val fieldOwner : T, val context :
*/
def this(fieldOwner : T, value : BigDecimal, context : MathContext) = {
this(fieldOwner, context, value.scale)
- setAll(value)
+ wholeSet(coerce(value))
}
/**
@@ -74,7 +74,7 @@ abstract class MappedDecimal[T <: Mapper[T]] (val fieldOwner : T, val context :
*/
def this(fieldOwner : T, value : BigDecimal) = {
this(fieldOwner, MathContext.UNLIMITED, value.scale)
- setAll(value)
+ wholeSet(coerce(value))
}
private val zero = BigDecimal("0")
@@ -86,7 +86,7 @@ abstract class MappedDecimal[T <: Mapper[T]] (val fieldOwner : T, val context :
private var data : BigDecimal = defaultValue
private var orgData : BigDecimal = defaultValue
- private def st (in : BigDecimal) = {
+ private def wholeSet (in : BigDecimal) = {
data = in
orgData = in
}
@@ -147,16 +147,16 @@ abstract class MappedDecimal[T <: Mapper[T]] (val fieldOwner : T, val context :
def buildSetBooleanValue(accessor : Method, columnName : String) : (T, Boolean, Boolean) => Unit = null
def buildSetDateValue(accessor : Method, columnName : String) : (T, Date) => Unit =
- (inst, v) => doField(inst, accessor, {case f: MappedDecimal[T] => f.set(if (v == null) defaultValue else coerce(BigDecimal(v.getTime)))})
+ (inst, v) => doField(inst, accessor, {case f: MappedDecimal[T] => f.wholeSet(if (v == null) defaultValue else coerce(BigDecimal(v.getTime)))})
def buildSetStringValue(accessor: Method, columnName: String): (T, String) =>
- Unit = (inst, v) => doField(inst, accessor, {case f: MappedDecimal[T] => f.set(if (v == null) defaultValue else coerce(BigDecimal(v)))})
+ Unit = (inst, v) => doField(inst, accessor, {case f: MappedDecimal[T] => f.wholeSet(if (v == null) defaultValue else coerce(BigDecimal(v)))})
def buildSetLongValue(accessor: Method, columnName : String) : (T, Long, Boolean) =>
- Unit = (inst, v, isNull) => doField(inst, accessor, {case f: MappedDecimal[T] => f.set(if (isNull) defaultValue else coerce(BigDecimal(v)))})
+ Unit = (inst, v, isNull) => doField(inst, accessor, {case f: MappedDecimal[T] => f.wholeSet(if (isNull) defaultValue else coerce(BigDecimal(v)))})
def buildSetActualValue(accessor: Method, data: AnyRef, columnName: String) : (T, AnyRef) =>
- Unit = (inst, v) => doField(inst, accessor, {case f: MappedDecimal[T] => f.set(if (v == null) defaultValue else coerce(BigDecimal(v.toString)))})
+ Unit = (inst, v) => doField(inst, accessor, {case f: MappedDecimal[T] => f.wholeSet(if (v == null) defaultValue else coerce(BigDecimal(v.toString)))})
/**
* Returns the SQL creation string for this field. See the note at the
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2010-2011 WorldWide Conferencing, LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.liftweb
+package mapper
+
+import org.specs.Specification
+
+import common._
+
+
+/**
+ * Systems under specification for MappedDate.
+ */
+object MappedDecimalSpec extends Specification("MappedDecimal Specification") {
+ val provider = DbProviders.H2MemoryProvider
+
+ private def ignoreLogger(f: => AnyRef): Unit = ()
+ def setupDB {
+ provider.setupDB
+ Schemifier.destroyTables_!!(ignoreLogger _, Dog, User)
+ Schemifier.schemify(true, ignoreLogger _, Dog, User)
+ }
+
+ "MappedDecimal" should {
+ "not be marked dirty on read" in {
+ setupDB
+ val charlie = Dog.create
+ charlie.price(42.42).save
+
+ println("Reading")
+ val read = Dog.find(charlie.id).open_!
+ read.dirty_? must_== false
+ }
+
+ "be marked dirty on update" in {
+ setupDB
+ val charlie = Dog.create
+ charlie.price(42.42).save
+
+ val read = Dog.find(charlie.id).open_!
+// read.dirty_? must_== false
+ read.price(100.42)
+ read.dirty_? must_== true
+ }
+ }
+}
+
@@ -271,6 +271,8 @@ class Dog extends LongKeyedMapper[Dog] with IdPK {
object weight extends MappedInt(this)
object owner extends MappedLongForeignKey(this, User)
+
+ object price extends MappedDecimal(this, new java.math.MathContext(7), 2)
}

0 comments on commit 49de1fc

Please sign in to comment.