Ejemplo n.º 1
0
  private void saveConsistencyLevel(
      EntityParsingContext context,
      String columnFamilyName,
      Pair<ConsistencyLevel, ConsistencyLevel> consistencyLevels) {
    log.debug(
        "Set default read/write consistency levels {} / {} for column family {}",
        consistencyLevels.left.name(),
        consistencyLevels.right.name(),
        columnFamilyName);

    context
        .getConfigurableCLPolicy()
        .setConsistencyLevelForRead(consistencyLevels.left, columnFamilyName);
    context
        .getConfigurableCLPolicy()
        .setConsistencyLevelForWrite(consistencyLevels.right, columnFamilyName);
  }
Ejemplo n.º 2
0
  public EntityMeta parseEntity(EntityParsingContext context) {
    log.debug("Parsing entity class {}", context.getCurrentEntityClass().getCanonicalName());

    Class<?> entityClass = context.getCurrentEntityClass();
    validateEntityAndGetObjectMapper(context);

    String columnFamilyName =
        introspector.inferColumnFamilyName(entityClass, entityClass.getName());
    Pair<ConsistencyLevel, ConsistencyLevel> consistencyLevels =
        introspector.findConsistencyLevels(entityClass, context.getConfigurableCLPolicy());

    context.setCurrentConsistencyLevels(consistencyLevels);
    context.setCurrentColumnFamilyName(columnFamilyName);

    PropertyMeta idMeta = null;
    List<Field> inheritedFields = introspector.getInheritedPrivateFields(entityClass);
    for (Field field : inheritedFields) {
      PropertyParsingContext propertyContext = context.newPropertyContext(field);
      if (filter.hasAnnotation(field, Id.class)) {
        propertyContext.setPrimaryKey(true);
        idMeta = parser.parse(propertyContext);
      }
      if (filter.hasAnnotation(field, EmbeddedId.class)) {
        context.setClusteredEntity(true);
        propertyContext.isEmbeddedId(true);
        idMeta = parser.parse(propertyContext);
      } else if (filter.hasAnnotation(field, Column.class)) {
        parser.parse(propertyContext);
      } else {
        log.trace(
            "Un-mapped field {} of entity {} will not be managed by Achilles",
            field.getName(),
            context.getCurrentEntityClass().getCanonicalName());
      }
    }

    // First validate id meta
    validator.validateHasIdMeta(entityClass, idMeta);

    // Deferred counter property meta completion
    completeCounterPropertyMeta(context, idMeta);

    // Finish validation of property metas
    // validator.validatePropertyMetas(context, idMeta);
    validator.validateClusteredEntities(context);

    EntityMeta entityMeta =
        entityMetaBuilder(idMeta)
            .entityClass(entityClass)
            .className(entityClass.getCanonicalName())
            .columnFamilyName(columnFamilyName)
            .propertyMetas(context.getPropertyMetas())
            .consistencyLevels(context.getCurrentConsistencyLevels())
            .build();

    saveConsistencyLevel(context, columnFamilyName, consistencyLevels);

    log.trace(
        "Entity meta built for entity class {} : {}",
        context.getCurrentEntityClass().getCanonicalName(),
        entityMeta);
    return entityMeta;
  }