-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce a findAllWhereFieldEquals method #246
Conversation
LGTM! |
I pushed some commits that add tests for all new methods. On top of that, i added tests for the recently introduced method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally approve this, because this method will become quite useful. Yet I have added a couple of comments which you might want to think about and possibly take.
Thanks and please merge after commenting on my comments.
"There is no field '%s' in the type '%s'", | ||
fieldName, | ||
entityClass.getName() | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Message could be enhanced to read e.g.
String errorMsg = String.format(
"There is no field '%s' in the type '%s' that accepts instances of '%s'",
fieldName,
entityClass.getName(),
// beware of null, though
fieldEntity.getClass().getName()
);
* @return The list of objects | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public List<E> findAllWhereFieldEquals(String fieldName, Object fieldEntity, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if fieldEntity
is null
?
I would assume that isField
becomes false
and one runs into the IllegalArgumentException
(at least if you take my suggestion of also checking the type).
But this is a valid question, right? Please find me all instances of E
where the field named fieldName
is (or is not) null
. What do you think?
I think we could branch off to a dfifferent method in the service, but this comes from the top of my head.
* @param forceAccess | ||
* @return | ||
*/ | ||
public static boolean isField(Class<?> clazz, String fieldName, boolean forceAccess) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to also check for the accepoted type, here or in another method?
Slightly related, we keep passing forceAccess
around, but on all SHOGun2 model classe we must have it true
, since our models only have private
fields. We should probably remove this everywhere, ansd simply pass through true
. This could be done in another PR of course, and only if you agree.
I think i "finalized" this in 8c3e31b by also handling |
Looking into this now. |
Very nice, Nils. Merging now. Thanks a lot! |
This introduces a
findAllWhereFieldEquals
method to DAO and service layer, which is very useful and can be used withPersistentObject
s and primitve types, too.