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:
@@ -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(",");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user