private CounterLoader counterLoader = CounterLoader.Singleton.INSTANCE.get();
private AsyncUtils asyncUtils = AsyncUtils.Singleton.INSTANCE.get();
public <T> AchillesFuture<T> load(EntityOperations context, Class<T> entityClass) {
log.debug("Loading entity of class {} using PersistenceContext {}", entityClass, context);
final EntityMeta entityMeta = context.getEntityMeta();
Object primaryKey = context.getPrimaryKey();
Validator.validateNotNull(entityClass, "Entity class should not be null");
Validator.validateNotNull(primaryKey, "Entity '%s' key should not be null", entityClass.getCanonicalName());
Validator.validateNotNull(entityMeta, "Entity meta for '%s' should not be null", entityClass.getCanonicalName());
AchillesFuture<T> achillesFuture;
if (entityMeta.structure().isClusteredCounter()) {
achillesFuture = counterLoader.loadClusteredCounters(context);
} else {
final ListenableFuture<Row> futureRow = context.loadEntity();
Function<Row, T> rowToEntity = new Function<Row, T>() {
@Override
public T apply(Row row) {
T entity = null;
if (row != null) {
entity = entityMeta.forOperations().instanciate();
mapper.setNonCounterPropertiesToEntity(row, entityMeta, entity);
}
return entity;
}
};