use of org.springframework.roo.addon.jpa.addon.dod.EmbeddedHolder in project spring-roo by spring-projects.
the class JpaEntityFactoryMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String entityFactoryMetadata, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
// Get related entity
final JavaType entity = (JavaType) governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getAnnotation(ROO_JPA_ENTITY_FACTORY).getAttribute("entity").getValue();
if (entity == null) {
return null;
}
final MemberDetails memberDetails = getMemberDetails(entity);
if (memberDetails == null) {
return null;
}
final MemberHoldingTypeDetails persistenceMemberHoldingTypeDetails = MemberFindingUtils.getMostConcreteMemberHoldingTypeDetailsWithTag(memberDetails, PERSISTENT_TYPE);
if (persistenceMemberHoldingTypeDetails == null) {
return null;
}
// We need to be informed if our dependent metadata changes
getMetadataDependencyRegistry().registerDependency(persistenceMemberHoldingTypeDetails.getDeclaredByMetadataId(), entityFactoryMetadata);
final JavaType identifierType = getPersistenceMemberLocator().getIdentifierType(entity);
if (identifierType == null) {
return null;
}
// Identify all the fields we care about on the entity
final Map<FieldMetadata, JpaEntityFactoryMetadata> locatedFields = getLocatedFields(memberDetails, entityFactoryMetadata);
// Get the list of embedded metadata holders - may be an empty list if
// no embedded identifier exists
final List<EmbeddedHolder> embeddedHolders = getEmbeddedHolders(memberDetails, entityFactoryMetadata);
// Get the embedded identifier metadata holder - may be null if no
// embedded identifier exists
final EmbeddedIdHolder embeddedIdHolder = getEmbeddedIdHolder(memberDetails, entityFactoryMetadata);
Set<ClassOrInterfaceTypeDetails> entityFactoryClasses = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY_FACTORY);
return new JpaEntityFactoryMetadata(entityFactoryMetadata, aspectName, governorPhysicalTypeMetadata, entity, locatedFields, embeddedHolders, entityFactoryClasses, embeddedIdHolder);
}
use of org.springframework.roo.addon.jpa.addon.dod.EmbeddedHolder in project spring-roo by spring-projects.
the class JpaEntityFactoryMetadataProviderImpl method getEmbeddedHolders.
private List<EmbeddedHolder> getEmbeddedHolders(final MemberDetails memberDetails, final String metadataIdentificationString) {
final List<EmbeddedHolder> embeddedHolders = new ArrayList<EmbeddedHolder>();
final List<FieldMetadata> embeddedFields = MemberFindingUtils.getFieldsWithTag(memberDetails, EMBEDDED_FIELD);
if (embeddedFields.isEmpty()) {
return embeddedHolders;
}
for (final FieldMetadata embeddedField : embeddedFields) {
final MemberDetails embeddedMemberDetails = getMemberDetails(embeddedField.getFieldType());
if (embeddedMemberDetails == null) {
continue;
}
final List<FieldMetadata> fields = new ArrayList<FieldMetadata>();
for (final FieldMetadata field : embeddedMemberDetails.getFields()) {
if (!(Modifier.isStatic(field.getModifier()) || Modifier.isFinal(field.getModifier()) || Modifier.isTransient(field.getModifier()))) {
getMetadataDependencyRegistry().registerDependency(field.getDeclaredByMetadataId(), metadataIdentificationString);
fields.add(field);
}
}
embeddedHolders.add(new EmbeddedHolder(embeddedField, fields));
}
return embeddedHolders;
}
Aggregations