Created
November 12, 2010 03:13
-
-
Save rotaris/673675 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package code { | |
| package lib { | |
| import net.liftweb._ | |
| import http._ | |
| import util._ | |
| import common._ | |
| import _root_.net.liftweb.mapper._ | |
| import _root_.net.liftweb.mapper.MappedField._ | |
| import _root_.java.sql.{ResultSet, Types} | |
| import _root_.java.lang.reflect.Method | |
| import _root_.scala.Math.{abs} | |
| import _root_.scala.xml.Text | |
| import _root_.net.liftweb.http.js._ | |
| import _root_.net.liftweb.json._ | |
| import _root_.scala.xml._ | |
| import _root_.java.util.Date | |
| import code.lib._ | |
| abstract class MappedLatLong[T <: Mapper[T]] (val fieldOwner: T) extends MappedField[LatLongPoint, T] { | |
| // Default constructor code | |
| // TODO: Complete | |
| // The data and orgData variables are used so that | |
| // we know when the field has been modified by the user | |
| private var data = defaultValue | |
| private var orgData = defaultValue | |
| private def st (in: LatLongPoint) { | |
| data = in | |
| orgData = in | |
| } | |
| def defaultValue = new LatLongPoint(0.0) | |
| def dbFieldClass = classOf[LatLongPoint] | |
| override def readPermission_? = true | |
| override def writePermission_? = true | |
| // The i_is_! and i_was_! methods are used internally to | |
| // keep track of when the field value is changed. In our | |
| // instance they delegate directly to the data and | |
| // orgData variables | |
| protected def i_is_! = data | |
| protected def i_was_! = orgData | |
| override def doneWithSave() { | |
| orgData = data | |
| } | |
| protected def i_obscure_!(in: LatLongPoint) = defaultValue | |
| protected def real_i_set_!(value: LatLongPoint): LatLongPoint = { | |
| if (value != data) { | |
| data = value | |
| dirty_?(true) | |
| } | |
| data | |
| } | |
| def asJsonValue: Box[JsonAST.JValue] = Full(JsonAST.JDouble(is.value)) // | |
| def asJsExp: JsExp = JE.Num(is.value) // | |
| def setFromAny(in: Any): LatLongPoint = in match { | |
| case ll: LatLongPoint => setAll(ll) | |
| case n :: _ => setFromString(n.toString) | |
| case Some(n) => setFromString(n.toString) | |
| case Full(n) => setFromString(n.toString) | |
| case None | Empty | Failure(_, _, _) | null => setFromString("0") | |
| case n => setFromString(n.toString) | |
| } | |
| // TODO: Fix/complete ? | |
| def setFromString(in: String): LatLongPoint = { | |
| new LatLongPoint(in.toDouble) | |
| } | |
| protected def setAll(in: LatLongPoint) = this.set(in) | |
| def targetSQLType = Types.DOUBLE | |
| def jdbcFriendly(field: String) = { | |
| println("\n jdbcFriendly()\n") | |
| new _root_.java.lang.Double(i_is_!.value) | |
| } | |
| def real_convertToJDBCFriendly(value: LatLongPoint): Object = { | |
| println("\n real_convertToJDBCFriendly()\n") | |
| new _root_.java.lang.Double(value.value) | |
| } | |
| // The following methods are used internally by Lift to | |
| // process values retrieved from the database. | |
| def buildSetBooleanValue(accessor : Method, columnName : String) : (T, Boolean, Boolean) => Unit = null | |
| def buildSetDateValue(accessor : Method, columnName : String) : (T, Date) => Unit = null | |
| def buildSetStringValue(accessor: Method, columnName: String): (T, String) => | |
| Unit = (inst, v) => | |
| doField(inst, accessor, { | |
| case f: MappedField[LatLongPoint, T] => | |
| println("\n buildSetStringValue() \n") | |
| null | |
| }) | |
| def buildSetLongValue(accessor: Method, columnName : String) : (T, Long, Boolean) => | |
| Unit = (inst, v, isNull) => | |
| doField(inst, accessor, { | |
| case f: MappedLatLong[T] => | |
| println("\n buildSetLongValue() \n") | |
| f.set(v) | |
| }) | |
| def buildSetActualValue(accessor: Method, data: AnyRef, columnName: String) : (T, AnyRef) => | |
| Unit = (inst, v) => | |
| doField(inst, accessor, { | |
| case f: MappedField[LatLongPoint, T] => | |
| println("\n buildSetActualValue() \n") | |
| null | |
| }) | |
| def fieldCreatorString(dbType: DriverType, colName: String): String = { | |
| colName + " " + dbType.integerColumnType + notNullAppender() | |
| } | |
| } | |
| } // End packages | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment