Ejemplo n.º 1
0
  protected PropertyMeta parseSimpleProperty(PropertyParsingContext context) {
    log.debug(
        "Parsing property {} as simple property of entity class {}",
        context.getCurrentPropertyName(),
        context.getCurrentEntityClass().getCanonicalName());

    Class<?> entityClass = context.getCurrentEntityClass();
    Field field = context.getCurrentField();
    boolean timeUUID = isTimeUUID(context, field);

    Method[] accessors = entityIntrospector.findAccessors(entityClass, field);
    PropertyType type = SIMPLE;

    PropertyMeta propertyMeta =
        factory()
            .objectMapper(context.getCurrentObjectMapper())
            .type(type)
            .propertyName(context.getCurrentPropertyName())
            .entityClassName(context.getCurrentEntityClass().getCanonicalName())
            .accessors(accessors)
            .consistencyLevels(context.getCurrentConsistencyLevels())
            .field(field)
            .timeuuid(timeUUID)
            .build(Void.class, field.getType());

    log.trace(
        "Built simple property meta for property {} of entity class {} : {}",
        propertyMeta.getPropertyName(),
        context.getCurrentEntityClass().getCanonicalName(),
        propertyMeta);
    return propertyMeta;
  }
Ejemplo n.º 2
0
  protected PropertyMeta parseCounterProperty(PropertyParsingContext context) {
    log.debug(
        "Parsing property {} as counter property of entity class {}",
        context.getCurrentPropertyName(),
        context.getCurrentEntityClass().getCanonicalName());

    Class<?> entityClass = context.getCurrentEntityClass();
    Field field = context.getCurrentField();

    Method[] accessors = entityIntrospector.findAccessors(entityClass, field);

    PropertyType type = PropertyType.COUNTER;

    CounterProperties counterProperties =
        new CounterProperties(context.getCurrentEntityClass().getCanonicalName());

    PropertyMeta propertyMeta =
        factory()
            .objectMapper(context.getCurrentObjectMapper())
            .type(type)
            .propertyName(context.getCurrentPropertyName())
            .entityClassName(context.getCurrentEntityClass().getCanonicalName())
            .accessors(accessors)
            .field(field)
            .counterProperties(counterProperties)
            .consistencyLevels(context.getCurrentConsistencyLevels())
            .build(Void.class, field.getType());

    context.hasSimpleCounterType();
    context.getCounterMetas().add(propertyMeta);
    if (context.isCustomConsistencyLevels()) {
      parseSimpleCounterConsistencyLevel(context, propertyMeta);
    }

    log.trace(
        "Built simple property meta for property {} of entity class {} : {}",
        propertyMeta.getPropertyName(),
        context.getCurrentEntityClass().getCanonicalName(),
        propertyMeta);
    return propertyMeta;
  }
Ejemplo n.º 3
0
 private boolean isTimeUUID(PropertyParsingContext context, Field field) {
   boolean timeUUID = false;
   if (filter.hasAnnotation(field, TimeUUID.class)) {
     Validator.validateBeanMappingTrue(
         field.getType().equals(UUID.class),
         "The field '%s' from class '%s' annotated with @TimeUUID should be of java.util.UUID type",
         field.getName(),
         context.getCurrentEntityClass().getCanonicalName());
     timeUUID = true;
   }
   return timeUUID;
 }
Ejemplo n.º 4
0
  protected <K, V> PropertyMeta parseMapProperty(PropertyParsingContext context) {
    log.debug(
        "Parsing property {} as map property of entity class {}",
        context.getCurrentPropertyName(),
        context.getCurrentEntityClass().getCanonicalName());

    Class<?> entityClass = context.getCurrentEntityClass();
    Field field = context.getCurrentField();
    boolean timeUUID = isTimeUUID(context, field);

    validator.validateMapGenerics(field, entityClass);

    Pair<Class<K>, Class<V>> types = determineMapGenericTypes(field);
    Class<K> keyClass = types.left;
    Class<V> valueClass = types.right;

    Method[] accessors = entityIntrospector.findAccessors(entityClass, field);
    PropertyType type = MAP;

    PropertyMeta mapMeta =
        factory()
            .objectMapper(context.getCurrentObjectMapper())
            .type(type)
            .propertyName(context.getCurrentPropertyName())
            .entityClassName(context.getCurrentEntityClass().getCanonicalName())
            .consistencyLevels(context.getCurrentConsistencyLevels())
            .accessors(accessors)
            .field(field)
            .timeuuid(timeUUID)
            .build(keyClass, valueClass);

    log.trace(
        "Built map property meta for property {} of entity class {} : {}",
        mapMeta.getPropertyName(),
        context.getCurrentEntityClass().getCanonicalName(),
        mapMeta);

    return mapMeta;
  }
Ejemplo n.º 5
0
  public <V> PropertyMeta parseSetProperty(PropertyParsingContext context) {
    log.debug(
        "Parsing property {} as set property of entity class {}",
        context.getCurrentPropertyName(),
        context.getCurrentEntityClass().getCanonicalName());

    Class<?> entityClass = context.getCurrentEntityClass();
    Field field = context.getCurrentField();
    boolean timeUUID = isTimeUUID(context, field);

    Class<V> valueClass;
    Type genericType = field.getGenericType();

    valueClass = inferValueClassForListOrSet(genericType, entityClass);
    Method[] accessors = entityIntrospector.findAccessors(entityClass, field);
    PropertyType type = SET;

    PropertyMeta setMeta =
        factory()
            .objectMapper(context.getCurrentObjectMapper())
            .type(type)
            .propertyName(context.getCurrentPropertyName())
            .entityClassName(context.getCurrentEntityClass().getCanonicalName())
            .consistencyLevels(context.getCurrentConsistencyLevels())
            .accessors(accessors)
            .field(field)
            .timeuuid(timeUUID)
            .build(Void.class, valueClass);

    log.trace(
        "Built set property meta for property {} of  entity class {} : {}",
        setMeta.getPropertyName(),
        context.getCurrentEntityClass().getCanonicalName(),
        setMeta);

    return setMeta;
  }
Ejemplo n.º 6
0
  protected PropertyMeta parseEmbeddedId(PropertyParsingContext context) {
    log.debug(
        "Parsing property {} as embedded id of entity class {}",
        context.getCurrentPropertyName(),
        context.getCurrentEntityClass().getCanonicalName());

    Class<?> entityClass = context.getCurrentEntityClass();
    Field field = context.getCurrentField();
    EmbeddedId embeddedId = field.getAnnotation(EmbeddedId.class);
    String propertyName =
        StringUtils.isNotBlank(embeddedId.name())
            ? embeddedId.name()
            : context.getCurrentPropertyName();

    Method[] accessors = entityIntrospector.findAccessors(entityClass, field);
    PropertyType type = EMBEDDED_ID;

    EmbeddedIdProperties embeddedIdProperties = extractEmbeddedIdProperties(field.getType());
    PropertyMeta propertyMeta =
        factory()
            .objectMapper(context.getCurrentObjectMapper())
            .type(type)
            .propertyName(propertyName)
            .embeddedIdProperties(embeddedIdProperties)
            .entityClassName(context.getCurrentEntityClass().getCanonicalName())
            .accessors(accessors)
            .field(field)
            .consistencyLevels(context.getCurrentConsistencyLevels())
            .build(Void.class, field.getType());

    log.trace(
        "Built embedded id property meta for property {} of entity class {} : {}",
        propertyMeta.getPropertyName(),
        context.getCurrentEntityClass().getCanonicalName(),
        propertyMeta);
    return propertyMeta;
  }
Ejemplo n.º 7
0
  protected PropertyMeta parseId(PropertyParsingContext context) {
    log.debug(
        "Parsing property {} as id of entity class {}",
        context.getCurrentPropertyName(),
        context.getCurrentEntityClass().getCanonicalName());

    PropertyMeta idMeta = parseSimpleProperty(context);
    idMeta.setType(ID);
    Id id = context.getCurrentField().getAnnotation(Id.class);
    String propertyName =
        StringUtils.isNotBlank(id.name()) ? id.name() : context.getCurrentPropertyName();
    idMeta.setPropertyName(propertyName);

    return idMeta;
  }
  @Test
  public void should_set_primaryKey_to_true_when_embedded_id() throws Exception {
    // Given
    EntityParsingContext entityContext = mock(EntityParsingContext.class, RETURNS_DEEP_STUBS);
    when(entityContext.getCurrentEntityClass()).thenReturn((Class) CompleteBean.class);
    Field field = CompleteBean.class.getDeclaredField("age");

    PropertyParsingContext context = new PropertyParsingContext(entityContext, field);

    // When
    context.setEmbeddedId(true);

    // Then
    assertThat(context.isEmbeddedId()).isTrue();
    assertThat(context.isPrimaryKey()).isTrue();
    assertThat(context.<CompleteBean>getCurrentEntityClass()).isEqualTo(CompleteBean.class);
    assertThat(context.getCurrentPropertyName()).isEqualTo("age_in_years");
  }
Ejemplo n.º 9
0
  public PropertyMeta parse(PropertyParsingContext context) {
    log.debug(
        "Parsing property {} of entity class {}",
        context.getCurrentPropertyName(),
        context.getCurrentEntityClass().getCanonicalName());

    Field field = context.getCurrentField();
    inferPropertyName(context);
    context.setCustomConsistencyLevels(hasConsistencyAnnotation(context.getCurrentField()));

    validator.validateNoDuplicate(context);
    validator.validateIndexIfSet(context);

    Class<?> fieldType = field.getType();
    PropertyMeta propertyMeta;

    if (List.class.isAssignableFrom(fieldType)) {
      propertyMeta = parseListProperty(context);
    } else if (Set.class.isAssignableFrom(fieldType)) {
      propertyMeta = parseSetProperty(context);
    } else if (Map.class.isAssignableFrom(fieldType)) {
      propertyMeta = parseMapProperty(context);
    } else if (Counter.class.isAssignableFrom(fieldType)) {
      propertyMeta = parseCounterProperty(context);
    } else if (context.isEmbeddedId()) {
      propertyMeta = parseEmbeddedId(context);
    } else if (context.isPrimaryKey()) {
      propertyMeta = parseId(context);
    } else {
      propertyMeta = parseSimpleProperty(context);
      String indexName = getIndexName(field);
      if (indexName != null) {
        propertyMeta.setIndexProperties(new IndexProperties(indexName));
      }
    }
    context.getPropertyMetas().put(context.getCurrentPropertyName(), propertyMeta);
    return propertyMeta;
  }