/** @return the find (by ID) method (may return null) */ public MethodMetadata getFindMethod() { if ("".equals(crudAnnotationValues.getFindMethod())) { return null; } // Method definition to find or build final String idFieldName = identifierField.getFieldName().getSymbolName(); final JavaSymbolName methodName = new JavaSymbolName(crudAnnotationValues.getFindMethod() + destination.getSimpleTypeName()); final JavaType parameterType = identifierField.getFieldType(); final List<JavaSymbolName> parameterNames = Arrays.asList(new JavaSymbolName(idFieldName)); final JavaType returnType = destination; // Locate user-defined method final MethodMetadata userMethod = getGovernorMethod(methodName, parameterType); if (userMethod != null) { Assert.isTrue( userMethod.getReturnType().equals(returnType), "Method '" + methodName + "' on '" + returnType + "' must return '" + returnType.getNameIncludingTypeParameters() + "'"); return userMethod; } // Create method final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); if (isGaeEnabled) { addTransactionalAnnotation(annotations); } final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); if (JavaType.STRING.equals(identifierField.getFieldType())) { bodyBuilder.appendFormalLine( "if (" + idFieldName + " == null || " + idFieldName + ".length() == 0) return null;"); } else if (!identifierField.getFieldType().isPrimitive()) { bodyBuilder.appendFormalLine("if (" + idFieldName + " == null) return null;"); } bodyBuilder.appendFormalLine( "return " + ENTITY_MANAGER_METHOD_NAME + "().find(" + returnType.getSimpleTypeName() + ".class, " + idFieldName + ");"); final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder( getId(), Modifier.PUBLIC | Modifier.STATIC, methodName, returnType, AnnotatedJavaType.convertFromJavaTypes(parameterType), parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); return methodBuilder.build(); }