Method method = aMethod.getMethod();
Class<?>[] parameters = method.getParameterTypes();
if(method.getParameterTypes().length != 2) {
throw new IllegalAnnotationUsageException("The FindByQuery annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
"doesn't have exactly two parameters.");
}
if(!Collection.class.isAssignableFrom(method.getReturnType())) {
throw new IllegalAnnotationUsageException("The FindByQuery annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
"doesn't return an instance of Collection.");
}
int queryIndex = indexOffFirstAssignableClass(String.class, parameters);
if(queryIndex == -1) {
throw new IllegalAnnotationUsageException("The FindByQuery annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
"doesn't have a String parameter. This parameter is needed to receive the query string.");
}
int parameterIndex = (queryIndex == 0) ? 1 : 0;
if(containsAssignableClass(List.class, parameters) || containsAssignableClass(Object[].class, parameters)) {
if(lookupWithPositionalQueryMethod != null) {
throw new IllegalAnnotationUsageException("A second method annotated with the '"+ LookupByQuery.class.getName() +"' annotation is found for a Positional query. " +
"Only one method, with a List or Object array parameter, per class is allowed to be annotated with this annotation.");
}
lookupWithPositionalQueryMethod = new LookupWithPositionalQueryMethod(method, queryIndex, parameterIndex);
} else if(containsAssignableClass(Map.class, parameters)){
if(lookupWithNamedQueryMethod != null) {
throw new IllegalAnnotationUsageException("A second method annotated with the '"+ LookupByQuery.class.getName() +"' annotation is found for a Positional query. " +
"Only one method, with a Map parameter, per class is allowed to be annotated with this annotation.");
}
lookupWithNamedQueryMethod = new LookupWithNamedQueryMethod(method, queryIndex, parameterIndex);
} else {
throw new IllegalAnnotationUsageException("The FindByQuery annotated method '"+ method +"' of the DAO class '"+ daoClass.getName() +"' " +
"doesn't have a List, Object array or Map parameter. This parameter is needed to receive the query parameters.");
}
}