package com.completex.objective.components.persistency.mapper;
/**
* Establishes map between Persistent Objects and Domain Objects that can be POJOs.
* Inability to map the value should normally be tolerated.
*
* @author Gennady Krizhevsky
*/
public interface Mapper {
public static final NullMapper NULL_MAPPER = new NullMapper();
/**
* Converts Persistent Object to POJO bean. If the mapping not found it should normally return
* unconverted Persistent Object.
*
* @param po Persistent Object
* @param forModification if true, indicates to cache Persistent Object in Thread Session
* @return POJO bean
*/
Object convertPoToBean(Object po, boolean forModification);
/**
* Converts POJO bean to Persistent Object.
*
* @param bean POJO bean
* @param forModification if true, indicates to cache Persistent Object in Thread Session
* @return Persistent Object
* @throws OdalMappingRuntimeException if the mapping is not found
*/
Object convertBeanToPo(Object bean, boolean forModification);
/**
* Returns true is the mapping found. At least one of the arguments should not be null.
*
* @param beanClass bean class
* @param poClass persistent object class
* @return true is the mapping found
*/
boolean mappingExists(Class beanClass, Class poClass);
/**
* Null implementation of Mapper
*/
static class NullMapper implements Mapper {
protected NullMapper() {
}
public Object convertPoToBean(Object po, boolean forModification) {
return po;
}
public Object convertBeanToPo(Object bean, boolean forModification) {
return bean;
}
public boolean mappingExists(Class beanClass, Class poClass) {
return false;
}
}
}
|