Skip to content
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

Merged
merged 10 commits into from
Mar 17, 2017

Conversation

buehner
Copy link
Member

@buehner buehner commented Mar 14, 2017

This introduces a findAllWhereFieldEquals method to DAO and service layer, which is very useful and can be used with PersistentObjects and primitve types, too.

@annarieger
Copy link
Member

LGTM!
Could you provide the tests for the new methods?

@buehner
Copy link
Member Author

buehner commented Mar 15, 2017

I pushed some commits that add tests for all new methods. On top of that, i added tests for the recently introduced method findAllWithCollectionContaining

Copy link
Member

@marcjansen marcjansen left a 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()
);
Copy link
Member

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,
Copy link
Member

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) {
Copy link
Member

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.

@buehner
Copy link
Member Author

buehner commented Mar 16, 2017

I think i "finalized" this in 8c3e31b by also handling null values. Please review (and merge!?) @marcjansen

@marcjansen
Copy link
Member

Looking into this now.

@marcjansen
Copy link
Member

Very nice, Nils. Merging now. Thanks a lot!

@marcjansen marcjansen merged commit f38f361 into terrestris:master Mar 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants