Example #1
0
  public <T> T load(PersistenceContext context, Class<T> entityClass) {
    log.debug("Loading entity of class {} using PersistenceContext {}", entityClass, context);
    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());

    T entity = null;

    if (entityMeta.isClusteredCounter()) {
      entity = counterLoader.loadClusteredCounters(context);
    } else {
      Row row = context.loadEntity();
      if (row != null) {
        entity = entityMeta.instanciate();
        mapper.setNonCounterPropertiesToEntity(row, entityMeta, entity);
      }
    }

    return entity;
  }
Example #2
0
  public <T> T createEmptyEntity(PersistenceContext context, Class<T> entityClass) {
    log.debug("Loading entity of class {} using PersistenceContext {}", entityClass, context);
    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());

    T entity = entityMeta.instanciate();
    entityMeta.getIdMeta().setValueToField(entity, primaryKey);

    return entity;
  }
Example #3
0
 public void loadPropertyIntoObject(
     PersistenceContext context, Object realObject, PropertyMeta pm) {
   log.trace("Loading property {} into object {}", pm.getPropertyName(), realObject);
   PropertyType type = pm.type();
   if (type.isCounter()) {
     counterLoader.loadCounter(context, realObject, pm);
   } else {
     Row row = context.loadProperty(pm);
     mapper.setPropertyToEntity(row, pm, realObject);
   }
 }