private void completeCounterPropertyMeta(EntityParsingContext context, PropertyMeta idMeta) { for (PropertyMeta counterMeta : context.getCounterMetas()) { log.debug( "Add id Meta {} to counter meta {} of entity class {}", idMeta.getPropertyName(), counterMeta.getPropertyName(), context.getCurrentEntityClass().getCanonicalName()); counterMeta.getCounterProperties().setIdMeta(idMeta); } }
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); }
private void validateEntityAndGetObjectMapper(EntityParsingContext context) { Class<?> entityClass = context.getCurrentEntityClass(); log.debug("Validate entity {}", entityClass.getCanonicalName()); Validator.validateInstantiable(entityClass); ObjectMapper objectMapper = context.getObjectMapperFactory().getMapper(entityClass); Validator.validateNotNull( objectMapper, "No Jackson ObjectMapper found for entity '%s'", entityClass.getCanonicalName()); log.debug( "Set default object mapper {} for entity {}", objectMapper.getClass().getCanonicalName(), entityClass.getCanonicalName()); context.setCurrentObjectMapper(objectMapper); }
@Test public void should_parse_bean_with_simple_counter_field() throws Exception { initEntityParsingContext(BeanWithSimpleCounter.class); EntityMeta meta = parser.parseEntity(entityContext); assertThat(meta).isNotNull(); assertThat(entityContext.getHasSimpleCounter()).isTrue(); PropertyMeta idMeta = meta.getIdMeta(); assertThat(idMeta).isNotNull(); PropertyMeta counterMeta = meta.getPropertyMetas().get("counter"); assertThat(counterMeta).isNotNull(); CounterProperties counterProperties = counterMeta.getCounterProperties(); assertThat(counterProperties).isNotNull(); assertThat(counterProperties.getFqcn()) .isEqualTo(BeanWithSimpleCounter.class.getCanonicalName()); assertThat(counterProperties.getIdMeta()).isSameAs(idMeta); }
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; }