Ejemplo n.º 1
0
  private void validateTable(
      EntityMeta entityMeta, TableMetadata tableMetadata, PropertyMeta idMeta) {
    if (idMeta.isEmbeddedId()) {
      validatePrimaryKeyComponents(tableMetadata, idMeta, true);
      validatePrimaryKeyComponents(tableMetadata, idMeta, false);
    } else {
      validateColumn(
          tableMetadata,
          idMeta.getPropertyName().toLowerCase(),
          idMeta.getValueClassForTableCreation(),
          idMeta.isIndexed());
    }

    for (PropertyMeta pm : entityMeta.getAllMetasExceptIdAndCounters()) {
      switch (pm.type()) {
        case SIMPLE:
          validateColumn(
              tableMetadata,
              pm.getPropertyName().toLowerCase(),
              pm.getValueClassForTableCreation(),
              pm.isIndexed());
          break;
        case LIST:
        case SET:
        case MAP:
          validateCollectionAndMapColumn(tableMetadata, pm);
          break;
        default:
          break;
      }
    }
  }
Ejemplo n.º 2
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.º 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);
   }
 }
Ejemplo n.º 4
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.º 5
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.º 6
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.º 7
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.º 8
0
  private void validateCollectionAndMapColumn(TableMetadata tableMetadata, PropertyMeta pm) {

    log.debug("Validate existing collection/map column {} from table {}");

    String columnName = pm.getPropertyName().toLowerCase();
    String tableName = tableMetadata.getName();
    ColumnMetadata columnMetadata = tableMetadata.getColumn(columnName);

    Validator.validateTableTrue(
        columnMetadata != null, "Cannot find column '%s' in the table '%s'", columnName, tableName);
    Name realType = columnMetadata.getType().getName();
    Name expectedValueType = toCQLType(pm.getValueClassForTableCreation());

    switch (pm.type()) {
      case LIST:
        Validator.validateTableTrue(
            realType == Name.LIST,
            "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed",
            columnName,
            tableName,
            realType,
            Name.LIST);
        Name realListValueType = columnMetadata.getType().getTypeArguments().get(0).getName();
        Validator.validateTableTrue(
            realListValueType == expectedValueType,
            "Column '%s' of table '%s' of type 'List<%s>' should be of type 'List<%s>' indeed",
            columnName,
            tableName,
            realListValueType,
            expectedValueType);

        break;
      case SET:
        Validator.validateTableTrue(
            realType == Name.SET,
            "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed",
            columnName,
            tableName,
            realType,
            Name.SET);
        Name realSetValueType = columnMetadata.getType().getTypeArguments().get(0).getName();

        Validator.validateTableTrue(
            realSetValueType == expectedValueType,
            "Column '%s' of table '%s' of type 'Set<%s>' should be of type 'Set<%s>' indeed",
            columnName,
            tableName,
            realSetValueType,
            expectedValueType);
        break;
      case MAP:
        Validator.validateTableTrue(
            realType == Name.MAP,
            "Column '%s' of table '%s' of type '%s' should be of type '%s' indeed",
            columnName,
            tableName,
            realType,
            Name.MAP);

        Name expectedMapKeyType = toCQLType(pm.getKeyClass());
        Name realMapKeyType = columnMetadata.getType().getTypeArguments().get(0).getName();
        Name realMapValueType = columnMetadata.getType().getTypeArguments().get(1).getName();
        Validator.validateTableTrue(
            realMapKeyType == expectedMapKeyType,
            "Column %s' of table '%s' of type 'Map<%s,?>' should be of type 'Map<%s,?>' indeed",
            columnName,
            tableName,
            realMapKeyType,
            expectedMapKeyType);

        Validator.validateTableTrue(
            realMapValueType == expectedValueType,
            "Column '%s' of table '%s' of type 'Map<?,%s>' should be of type 'Map<?,%s>' indeed",
            columnName,
            tableName,
            realMapValueType,
            expectedValueType);
        break;
      default:
        break;
    }
  }