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.)
This commit is contained in:
Michael Bayne
2010-06-19 17:35:05 +00:00
parent 1d9a19e502
commit 7f9bf7b589
2 changed files with 18 additions and 7 deletions
+17 -3
View File
@@ -30,9 +30,23 @@ package com.samskivert.depot;
*/
public interface Transformer<F,T>
{
/** 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);
}
@@ -33,9 +33,6 @@ import com.samskivert.depot.annotation.Column;
* public String[] cities;
* }
* </pre>
* 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(",");
}
}