Ejemplo n.º 1
0
  public <T> T buildProxy(T entity, EntityOperations context, Set<Method> alreadyLoaded) {

    if (entity == null) {
      return null;
    }

    log.debug("Build Cglib proxy for entity {} ", entity);

    Class<?> proxyClass = factory.createProxyClass(entity.getClass(), context.getConfigContext());

    @SuppressWarnings("unchecked")
    T instance = (T) instantiator.instantiate(proxyClass);

    EntityMeta meta = context.getEntityMeta();
    for (PropertyMeta pm : meta.getAllMetasExceptCounters()) {
      Object value = pm.forValues().getValueFromField(entity);
      pm.forValues().setValueToField(instance, value);
    }

    for (PropertyMeta pm : meta.getAllCounterMetas()) {
      pm.forValues().setValueToField(entity, null);
    }

    ((Factory) instance)
        .setCallbacks(new Callback[] {buildInterceptor(context, entity, alreadyLoaded)});
    return instance;
  }
Ejemplo n.º 2
0
  public void refresh(Object proxifiedEntity, EntityOperations context)
      throws AchillesStaleObjectStateException {
    Object primaryKey = context.getPrimaryKey();
    log.debug(
        "Refreshing entity of class {} and primary key {}",
        context.getEntityClass().getCanonicalName(),
        primaryKey);

    ProxyInterceptor<Object> interceptor = proxifier.getInterceptor(proxifiedEntity);
    Object entity = context.getEntity();

    interceptor.getDirtyMap().clear();

    Object freshEntity = loader.load(context, context.getEntityClass());

    if (freshEntity == null) {
      throw new AchillesStaleObjectStateException(
          "The entity '"
              + entity
              + "' with primary_key '"
              + primaryKey
              + "' no longer exists in Cassandra");
    }
    interceptor.setTarget(freshEntity);
    interceptor.getAlreadyLoaded().clear();
    interceptor.getAlreadyLoaded().addAll(context.getAllGettersExceptCounters());
  }
Ejemplo n.º 3
0
 public void remove(EntityOperations context) {
   log.trace("Removing entity using PersistenceContext {}", context);
   EntityMeta entityMeta = context.getEntityMeta();
   if (entityMeta.structure().isClusteredCounter()) {
     context.bindForClusteredCounterRemoval();
   } else {
     context.bindForRemoval(entityMeta.config().getTableName());
     counterPersister.removeRelatedCounters(context);
   }
 }
Ejemplo n.º 4
0
  public void persist(EntityOperations context) {
    EntityMeta entityMeta = context.getEntityMeta();
    Object entity = context.getEntity();

    log.debug("Persisting transient entity {}", entity);

    if (entityMeta.structure().isClusteredCounter()) {
      counterPersister.persistClusteredCounters(context);
    } else {
      context.pushInsertStatement();
      counterPersister.persistCounters(context, entityMeta.getAllCounterMetas());
    }
  }
Ejemplo n.º 5
0
 public <T> T buildProxyWithAllFieldsLoadedExceptCounters(T entity, EntityOperations context) {
   return buildProxy(entity, context, context.getAllGettersExceptCounters());
 }