org.makumba
Interface DataTransformer
public interface DataTransformer
Specifies interface for data transformation. Some of your application's class should implement this DataTransformer
in order to be used by Makumba during DB operations.
In your db configuration file (e.g. localhost_mysql_myapp.properties
) it should be specified with a line
insert#<i>makumba.Type</i>=<i>yourClassThatImplementsDataTransformer</i>
to run your transformer (yourClassThatImplementsDataTransformer
) on all the records of that makumba type
(makumba.Type
) before being inserted into the database.
Example
insert#<i>general.Person</i>=<i>PersonHook</i>
with a simple DataTransformer
class PersonHook
:
import org.makumba.*;
import java.util.*;
public class PersonHook implements DataTransformer {
public boolean transform(Dictionary d, Database db) {
//we might want to make sure a name is all lowercase with capital initial:
String n= (String)d.get("name");
if(n!=null && n.trim().length()>2) {
d.put("name", n.substring(0,1).toUpperCase()+n.substring(1).toLowerCase());
return true
} else {
return false;
}
}
}
Would ensure that application writes only "properly capitalized" names to the DB, wherever in the application objects
of type general.Person
would be created.
transform
boolean transform(Dictionary<String,Object> d,
Transaction db)
- Performs the data transformation.
- Parameters:
d
- data to transformdb
- database
- Returns:
- true if specified database operation should be done (eg data transformed successfully or data is valid),
false otherwise.