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; }
private void parseSimpleCounterConsistencyLevel( PropertyParsingContext context, PropertyMeta propertyMeta) { log.trace("Parse custom consistency levels for counter property {}", propertyMeta); Pair<ConsistencyLevel, ConsistencyLevel> consistencyLevels = findConsistencyLevels(context.getCurrentField(), context.getDefaultConsistencyLevels()); validator.validateConsistencyLevelForCounter(context, consistencyLevels); log.trace("Found custom consistency levels : {}", consistencyLevels); propertyMeta.setConsistencyLevels(consistencyLevels); }
private void inferPropertyName(PropertyParsingContext context) { log.trace("Inferring property name for property {}", context.getCurrentPropertyName()); String propertyName; Field field = context.getCurrentField(); Column column = field.getAnnotation(Column.class); if (column != null) { propertyName = StringUtils.isNotBlank(column.name()) ? column.name() : field.getName(); } else { propertyName = field.getName(); } context.setCurrentPropertyName(propertyName); }
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; }
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; }
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; }
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; }
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; }
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; }