From 7f9bf7b58972d1694bc936425033c3fde5d7b10f Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Sat, 19 Jun 2010 17:35:05 +0000 Subject: [PATCH] Determined that we need to pass the field type into the fromPersistent() to support use cases like ByteEnum. (Even though I'm leaving ByteEnum support hard-coded for the time being.) --- .../com/samskivert/depot/Transformer.java | 20 ++++++++++++++++--- .../com/samskivert/depot/Transformers.java | 5 +---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/java/com/samskivert/depot/Transformer.java b/src/java/com/samskivert/depot/Transformer.java index eb0fa2a..710cd1d 100644 --- a/src/java/com/samskivert/depot/Transformer.java +++ b/src/java/com/samskivert/depot/Transformer.java @@ -30,9 +30,23 @@ package com.samskivert.depot; */ public interface Transformer { - /** Transforms a runtime value into a value that can be persisted. */ + /** + * Transforms a runtime value into a value that can be persisted. + * + * @param value the value just read from a persistent record. + * + * @return the transformed value, which will be written to the database. + */ T toPersistent (F value); - /** Transforms a persisted value into a value that can be store in a runtime field. */ - F fromPersistent (T value); + /** + * Transforms a persisted value into a value that can be store in a runtime field. + * + * @param fieldType the type of the persistent record field to which the transformed value will + * be written. + * @param value the value just read from the database. + * + * @return the transformed value, which will be stored in a field of the persistent record. + */ + F fromPersistent (Class fieldType, T value); } diff --git a/src/java/com/samskivert/depot/Transformers.java b/src/java/com/samskivert/depot/Transformers.java index 0238bbb..1c0fdfd 100644 --- a/src/java/com/samskivert/depot/Transformers.java +++ b/src/java/com/samskivert/depot/Transformers.java @@ -33,9 +33,6 @@ import com.samskivert.depot.annotation.Column; * public String[] cities; * } * - * Because of limitations of Java's annotation system, configuration of transformers is not - * possible (without complex machinations) and separate classes must be created for any particular - * transformation. */ public class Transformers { @@ -46,7 +43,7 @@ public class Transformers public String toPersistent (String[] value) { return Joiner.on(",").join(value); } - public String[] fromPersistent (String value) { + public String[] fromPersistent (Class ftype, String value) { return value.split(","); } }