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 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); }
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; }