use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class ServiceMetadata method getDeleteBatchMethod.
/**
* Method that generates "delete" batch method
*
* @return MethodMetadataBuilder with public void delete(Iterable
* <Long> ids); structure
*/
private MethodMetadata getDeleteBatchMethod() {
// Define method name
JavaSymbolName methodName = new JavaSymbolName("delete");
// 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;
}
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, null);
// Build a MethodMetadata instance
MethodMetadata methodMetadata = methodBuilder.build();
return methodMetadata;
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class ServiceMetadata method getSaveBatchMethod.
/**
* Method that generates "save" batch method.
*
* @return MethodMetadataBuilder with public List<Entity> save(Iterable
* <Entity> entities); structure
*/
private MethodMetadata getSaveBatchMethod() {
// Define method name
JavaSymbolName methodName = new JavaSymbolName("save");
// Define method parameter types
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(entity)));
// Define method parameter names
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(new JavaSymbolName("entities"));
JavaType listEntityJavaType = JavaType.listOf(entity);
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, listEntityJavaType, parameterTypes, parameterNames, null);
// Build a MethodMetadata instance
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder 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.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class ServiceMetadata method getCountByReferencedFieldMethod.
/**
* Method that generates countByReferencedField method on current interface
*
* @param countMethod
* @return
*/
private MethodMetadata getCountByReferencedFieldMethod(MethodMetadata countMethod) {
// Define method parameter types and parameter names
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
List<AnnotatedJavaType> methodParamTypes = countMethod.getParameterTypes();
List<JavaSymbolName> methodParamNames = countMethod.getParameterNames();
for (int i = 0; i < countMethod.getParameterTypes().size(); i++) {
parameterTypes.add(methodParamTypes.get(i));
parameterNames.add(methodParamNames.get(i));
}
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, countMethod.getMethodName(), countMethod.getReturnType(), parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
// instance
}
use of org.springframework.roo.classpath.details.MethodMetadataBuilder in project spring-roo by spring-projects.
the class ServiceMetadata method getFindOneForUpdateMethod.
/**
* Generates the "findOneForUpdate" method to be able to control
* concurrency in Entity updates.
*
* @return MethodMetadata with public Entity findOneForUpdate(T id);
* structure
*/
private MethodMetadata getFindOneForUpdateMethod() {
// Define method name
JavaSymbolName methodName = new JavaSymbolName("findOneForUpdate");
// Define method parameter types
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(this.identifierType));
// Define method parameter names
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(this.entityMetadata.getCurrentIndentifierField().getFieldName());
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
}
Aggregations