use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class ServiceMetadata method getFindAllIterableMethod.
/**
* Method that generates method "findAll" with iterable parameter.
*
* @return MethodMetadataBuilder with public List <Entity> findAll(Iterable
* <Long> ids) structure
*/
private MethodMetadata getFindAllIterableMethod() {
// Define method name
JavaSymbolName methodName = new JavaSymbolName("findAll");
// Define method parameter types
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(identifierType)));
// Define method parameter names
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(new JavaSymbolName("ids"));
MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
JavaType listEntityJavaType = JavaType.listOf(entity);
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, listEntityJavaType, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
// instance
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType 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.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class ServiceMetadataProviderImpl method registerDependencyModulesOfFinder.
private void registerDependencyModulesOfFinder(final PhysicalTypeMetadata governorPhysicalTypeMetadata, MethodMetadata finder) {
// Add dependencies between modules
List<JavaType> types = new ArrayList<JavaType>();
types.add(finder.getReturnType());
types.addAll(finder.getReturnType().getParameters());
for (AnnotatedJavaType parameter : finder.getParameterTypes()) {
types.add(parameter.getJavaType());
types.addAll(parameter.getJavaType().getParameters());
}
for (JavaType parameter : types) {
getTypeLocationService().addModuleDependency(governorPhysicalTypeMetadata.getType().getModule(), parameter);
}
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class RepositoryJpaCustomMetadata method getFindAllMethodByReferencedField.
/**
* Method that generates the findAll method for provided referenced field on current interface.
*
* @param referencedField
* @param identifierType
*
* @return
*/
private MethodMetadata getFindAllMethodByReferencedField(FieldMetadata referencedField, RelationInfo relationInfo) {
// Define method name
String findPattern = "findBy%s";
if (relationInfo.cardinality == Cardinality.MANY_TO_MANY) {
findPattern = "findBy%sContains";
}
// Method name
JavaSymbolName methodName = new JavaSymbolName(String.format(findPattern, referencedField.getFieldName().getSymbolNameCapitalisedFirstLetter()));
// Define method parameter types and parameter names
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
final JavaType paramType = referencedField.getFieldType().getBaseType();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(paramType));
parameterTypes.add(GLOBAL_SEARCH_PARAMETER);
parameterTypes.add(PAGEABLE_PARAMETER);
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(referencedField.getFieldName().getSymbolName())));
parameterNames.add(GOBAL_SEARCH_PARAMETER_NAME);
parameterNames.add(PAGEABLE_PARAMETER_NAME);
// Return type
JavaType returnType = new JavaType(SpringJavaType.PAGE.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(defaultReturnType));
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, returnType, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class RepositoryJpaCustomMetadata method getCustomFinder.
/**
* Method that generates finder methods whose return types are projections.
*
* @param finderReturnType
* @param finderName
* @param parameterType
*
* @return
*/
private MethodMetadata getCustomFinder(JavaType finderReturnType, JavaSymbolName finderName, JavaType parameterType) {
// Define method parameter types and parameter names
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(parameterType));
parameterTypes.add(GLOBAL_SEARCH_PARAMETER);
parameterTypes.add(PAGEABLE_PARAMETER);
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(new JavaSymbolName("formBean"));
parameterNames.add(GOBAL_SEARCH_PARAMETER_NAME);
parameterNames.add(PAGEABLE_PARAMETER_NAME);
// Return type
JavaType returnType = new JavaType(SpringJavaType.PAGE.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(finderReturnType));
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, finderName, returnType, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
}
Aggregations