Skip to content

Commit

Permalink
Squeryl-Record now used the precision and scale defined within (Optio…
Browse files Browse the repository at this point in the history
…nal)DecimalField.
  • Loading branch information
davewhittaker committed Oct 5, 2011
1 parent a499905 commit 7d6325f
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 132 deletions.
Expand Up @@ -91,11 +91,6 @@ class RecordMetaDataFactory extends FieldMetaDataFactory {
case _ => error("Unsupported field type. Consider implementing " +
"SquerylRecordField for defining the persistent class." +
"Field: " + metaField)
}

val overrideColLength = metaField match {
case (stringTypedField: StringTypedField) => Some(stringTypedField.maxLength)
case _ => None
}

new FieldMetaData(
Expand All @@ -112,7 +107,39 @@ class RecordMetaDataFactory extends FieldMetaDataFactory {
isOptimisticCounter,
metaField) {

override def length = overrideColLength getOrElse super.length
override def length = {
import java.math.MathContext
val fieldLength =
metaField match {
case (stringTypedField: StringTypedField) => Some(stringTypedField.maxLength)
case decimalField: DecimalField[_] => {
val precision = decimalField.context.getPrecision();
if(precision != 0)
Some(precision)
else
None
}
case decimalField: OptionalDecimalField[_] => {
val precision = decimalField.context.getPrecision();
if(precision != 0)
Some(precision)
else
None
}
case _ => None
}
fieldLength getOrElse super.length
}

override def scale = {
val fieldScale =
metaField match {
case decimalField: DecimalField[_] => Some(decimalField.scale)
case decimalField: OptionalDecimalField[_] => Some(decimalField.scale)
case _ => None
}
fieldScale getOrElse super.scale
}

private def fieldFor(o: AnyRef) = getter.get.invoke(o).asInstanceOf[TypedField[AnyRef]]

Expand Down
Expand Up @@ -76,6 +76,7 @@ class Company private () extends Record[Company] with KeyedRecord[Long] with Opt
val country = new CountryField(this)
val postCode = new PostalCodeField(this, country)
val created = new DateTimeField(this)
val employeeSatisfaction = new OptionalDecimalField(this, new MathContext(10), 5)

lazy val employees = MySchema.companyToEmployees.left(this)

Expand Down

0 comments on commit 7d6325f

Please sign in to comment.