info.archinnov.achilles.proxy.ThriftEntityInterceptorBuilder Maven / Gradle / Ivy
package info.archinnov.achilles.proxy;
import info.archinnov.achilles.context.ThriftPersistenceContext;
import info.archinnov.achilles.entity.metadata.EntityMeta;
import info.archinnov.achilles.entity.metadata.PropertyMeta;
import info.archinnov.achilles.validation.Validator;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* ThriftEntityInterceptorBuilder
*
* @author DuyHai DOAN
*
*/
public class ThriftEntityInterceptorBuilder
{
private static final Logger log = LoggerFactory.getLogger(ThriftEntityInterceptorBuilder.class);
private T target;
private Set alreadyLoaded = new HashSet();
private ThriftPersistenceContext context;
public static ThriftEntityInterceptorBuilder builder(ThriftPersistenceContext context,
T entity)
{
return new ThriftEntityInterceptorBuilder(context, entity);
}
public ThriftEntityInterceptorBuilder(ThriftPersistenceContext context, T entity) {
Validator.validateNotNull(context, "PersistenceContext for interceptor should not be null");
Validator.validateNotNull(entity, "Target entity for interceptor should not be null");
this.context = context;
this.target = entity;
}
public ThriftEntityInterceptor build()
{
log.debug("Build interceptor for entity of class {}", context
.getEntityMeta()
.getClassName());
ThriftEntityInterceptor interceptor = new ThriftEntityInterceptor();
EntityMeta entityMeta = context.getEntityMeta();
Validator.validateNotNull(target, "Target object for interceptor of '"
+ context.getEntityClass().getCanonicalName() + "' should not be null");
Validator.validateNotNull(entityMeta.getGetterMetas(),
"Getters metadata for interceptor of '"
+ context.getEntityClass().getCanonicalName() + "' should not be null");
Validator.validateNotNull(entityMeta.getSetterMetas(),
"Setters metadata for interceptor of '"
+ context.getEntityClass().getCanonicalName() + "'should not be null");
if (entityMeta.isClusteredEntity())
{
Validator.validateNotNull(context.getWideRowDao(), "Column Family Dao for '"
+ context.getEntityClass().getCanonicalName() + "' should not be null");
}
else
{
Validator.validateNotNull(context.getEntityDao(), "Entity dao for '"
+ context.getEntityClass().getCanonicalName() + "' should not be null");
}
PropertyMeta, ?> idMeta = entityMeta.getIdMeta();
Validator.validateNotNull(idMeta, "Id metadata for '"
+ context.getEntityClass().getCanonicalName() + "' should not be null");
interceptor.setTarget(target);
interceptor.setContext(context);
interceptor.setGetterMetas(entityMeta.getGetterMetas());
interceptor.setSetterMetas(entityMeta.getSetterMetas());
interceptor.setIdGetter(idMeta.getGetter());
interceptor.setIdSetter(idMeta.getSetter());
if (context.isLoadEagerFields())
{
alreadyLoaded.addAll(entityMeta.getEagerGetters());
}
interceptor.setAlreadyLoaded(alreadyLoaded);
interceptor.setDirtyMap(new HashMap>());
interceptor.setPrimaryKey(context.getPrimaryKey());
return interceptor;
}
public ThriftEntityInterceptorBuilder alreadyLoaded(Set alreadyLoaded)
{
this.alreadyLoaded = alreadyLoaded;
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy