use of org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata in project spring-roo by spring-projects.
the class RepositoryJpaIntegrationTestMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final RepositoryJpaIntegrationTestAnnotationValues annotationValues = new RepositoryJpaIntegrationTestAnnotationValues(governorPhysicalTypeMetadata);
// Find SpringJpaDataDetachableConfiguration class
Set<JavaType> jpaConfigurationClasses = getTypeLocationService().findTypesWithAnnotation(RooJavaType.ROO_JPA_REPOSITORY_CONFIGURATION);
Validate.isTrue(!jpaConfigurationClasses.isEmpty(), "Couldn't find the 'SpringDataJpaDetachableRepositoryConfiguration' on the project for '%s'", this.getClass().getName());
JavaType jpaDetachableRepositoryClass = jpaConfigurationClasses.iterator().next();
// Get repository metadata
JavaType repositoryInterface = annotationValues.getTargetClass();
ClassOrInterfaceTypeDetails repositoryDetails = getTypeLocationService().getTypeDetails(repositoryInterface);
Validate.notNull(repositoryDetails.getAnnotation(RooJavaType.ROO_REPOSITORY_JPA), "Couldn't find @RooJpaRepository in '%s'", repositoryInterface.getSimpleTypeName());
String repositoryMetadataId = RepositoryJpaMetadata.createIdentifier(repositoryDetails);
RepositoryJpaMetadata repositoryMetadata = getMetadataService().get(repositoryMetadataId);
if (repositoryMetadata == null) {
return null;
}
// Get entity identifier info
JavaType entity = repositoryMetadata.getEntity();
JavaType identifierType = getPersistenceMemberLocator().getIdentifierType(entity);
JavaSymbolName identifierAccessorMethodName = getPersistenceMemberLocator().getIdentifierAccessor(entity).getMethodName();
// Get entity metadata
ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
String jpaEntityMetadataId = JpaEntityMetadata.createIdentifier(entityDetails);
JpaEntityMetadata jpaEntityMetadata = getMetadataService().get(jpaEntityMetadataId);
if (jpaEntityMetadata == null) {
return null;
}
// Get entity read only
boolean isReadOnly = jpaEntityMetadata.isReadOnly();
// Get entity plural
String entityPlural = getPluralService().getPlural(entity);
// Get repository default return type
JavaType defaultReturnType = repositoryMetadata.getDefaultReturnType();
return new RepositoryJpaIntegrationTestMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, jpaDetachableRepositoryClass, identifierType, identifierAccessorMethodName, entityPlural, entity, defaultReturnType, isReadOnly);
}
use of org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata in project spring-roo by spring-projects.
the class ServiceMetadata method getRemoveFromRelationMethod.
private MethodMetadata getRemoveFromRelationMethod(RelationInfo relationInfo) {
final MethodMetadata entityRemoveMethod = relationInfo.removeMethod;
// Define method name
JavaSymbolName methodName = entityRemoveMethod.getMethodName();
// Define method parameter types
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
// add parent entity parameter
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(entity));
parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entity.getSimpleTypeName())));
// Get related entity metadata
JpaEntityMetadata childEntityMetadata = relatedEntitiesMetadata.get(relationInfo.childType);
Validate.notNull(childEntityMetadata, "Can't get entity metadata for %s entity generating %s", relationInfo.childType, aspectName);
if (relationInfo.cardinality != Cardinality.ONE_TO_ONE) {
// add child entity parameter
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(childEntityMetadata.getCurrentIndentifierField().getFieldType())));
parameterNames.add(entityRemoveMethod.getParameterNames().get(0));
}
MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, entity, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
// instance
}
use of org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata in project spring-roo by spring-projects.
the class ServiceMetadata method getAddToRelationMethod.
/**
* Generates "AddToRelation" Method for this service
* @param relationInfo
* @return
*/
private MethodMetadata getAddToRelationMethod(RelationInfo relationInfo) {
final MethodMetadata entityAddMethod = relationInfo.addMethod;
// Define method name
JavaSymbolName methodName = entityAddMethod.getMethodName();
// Define method parameter types
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
// add parent entity parameter
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(entity));
parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entity.getSimpleTypeName())));
// add child entity parameter
parameterNames.add(entityAddMethod.getParameterNames().get(0));
if (relationInfo.cardinality == Cardinality.ONE_TO_ONE) {
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(relationInfo.childType));
} else if (relationInfo.type == JpaRelationType.COMPOSITION) {
// Use objects
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(relationInfo.childType)));
} else {
// AGGREGATION: Use Child Pk: Get related entity metadata
JpaEntityMetadata childEntityMetadata = relatedEntitiesMetadata.get(relationInfo.childType);
Validate.notNull(childEntityMetadata, "Can't get entity metadata for %s entity generating %s", relationInfo.childType, aspectName);
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(childEntityMetadata.getCurrentIndentifierField().getFieldType())));
}
MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, entity, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
// instance
}
use of org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata in project spring-roo by spring-projects.
the class ServiceMetadata method getSetRelationMethod.
/**
* Generates "setRelation" Method for this service
* @param relationInfo
* @return
*/
private MethodMetadata getSetRelationMethod(RelationInfo relationInfo) {
// Define method name
final JavaSymbolName methodName = new JavaSymbolName("set" + relationInfo.fieldMetadata.getFieldName().getSymbolNameCapitalisedFirstLetter());
// Define method parameter types
final List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
// add parent entity parameter
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(entity));
parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entity.getSimpleTypeName())));
// add child entity parameter
parameterNames.add(relationInfo.fieldMetadata.getFieldName());
if (relationInfo.cardinality == Cardinality.ONE_TO_ONE) {
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(relationInfo.childType));
} else if (relationInfo.type == JpaRelationType.COMPOSITION) {
// Use objects
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(relationInfo.childType)));
} else {
// AGGREGATION: Use Child Pk: Get related entity metadata
JpaEntityMetadata childEntityMetadata = relatedEntitiesMetadata.get(relationInfo.childType);
Validate.notNull(childEntityMetadata, "Can't get entity metadata for %s entity generating %s", relationInfo.childType, aspectName);
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(childEntityMetadata.getCurrentIndentifierField().getFieldType())));
}
MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, entity, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
// instance
}
use of org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata in project spring-roo by spring-projects.
the class RepositoryJpaCustomMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final RepositoryJpaCustomAnnotationValues annotationValues = new RepositoryJpaCustomAnnotationValues(governorPhysicalTypeMetadata);
// Getting repository custom
JavaType entity = annotationValues.getEntity();
Validate.notNull(entity, "ERROR: Repository custom interface should be contain an entity on @RooJpaRepositoryCustom annotation");
final ClassOrInterfaceTypeDetails repositoryClass = getRepositoryJpaLocator().getRepository(entity);
final String repositoryMedatadataId = RepositoryJpaMetadata.createIdentifier(repositoryClass);
registerDependency(repositoryMedatadataId, metadataIdentificationString);
RepositoryJpaMetadata repositoryMetadata = getMetadataService().get(repositoryMedatadataId);
// This metadata is not available yet.
if (repositoryMetadata == null) {
return null;
}
// Add dependency between modules
ClassOrInterfaceTypeDetails cid = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails();
String module = cid.getName().getModule();
getTypeLocationService().addModuleDependency(module, entity);
getTypeLocationService().addModuleDependency(module, repositoryMetadata.getDefaultReturnType());
// Get field which entity is field part
List<Pair<FieldMetadata, RelationInfo>> relationsAsChild = getJpaOperations().getFieldChildPartOfRelation(entity);
for (Pair<FieldMetadata, RelationInfo> fieldInfo : relationsAsChild) {
// Add dependency between modules
getTypeLocationService().addModuleDependency(module, fieldInfo.getLeft().getFieldType());
}
// Register dependency between JavaBeanMetadata and this one
final ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
final String javaBeanMetadataKey = JavaBeanMetadata.createIdentifier(entityDetails);
registerDependency(javaBeanMetadataKey, metadataIdentificationString);
String entityMetadataKey = JpaEntityMetadata.createIdentifier(entityDetails);
JpaEntityMetadata entityMetadata = getMetadataService().get(entityMetadataKey);
// Entity metadata is not available
if (entityMetadata == null) {
return null;
}
return new RepositoryJpaCustomMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, entityMetadata.getCurrentIndentifierField().getFieldType(), entity, repositoryMetadata, relationsAsChild);
}
Aggregations