-
Notifications
You must be signed in to change notification settings - Fork 62
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
Question about usage performance #161
Comments
Unfortunately, YAVI does not support such cases. Example Validator<Pair<Document, Param>> validator = ValidatorBuilder.<Pair<Document, Param>>of()
.constraintOnObject(Pair::first, "id", c -> c.notNull().message("{0} not exists"))
.constraintOnTarget(pair -> pair.first() == null || Objects.equals(pair.first().getOwnerId(), pair.second().getOwnerId()),
"ownerId", "no_permission", "no permission")
.build();
validator.validate(new Pair<>(documentDao.findById(param.getId()), param)); |
@making Thanks for your help. but the full validator buider is builder._string(Param::getFielda, "fielda", a -> a.notNull().notBlank());
builder._string(Param::getFieldb, "fieldb", a -> a.notNull().notBlank());
builder._long(Param::getId, "id", Constraint::notNull);
builder.constraintOnTarget(param -> {
Document doc = documentDao.findById(param.getId());
if (isNull(doc)) {
return false;
}
return true;
}, "id", "not_exists", "id not exists");
builder.constraintOnTarget(param -> {
Document doc = documentDao.findById(param.getId());
if (!param.getOwnerId().equals(doc.getOwnerId())) {
return false;
}
return true;
}, "ownerId", "no_permission", "no permission"); If there is some workaround please? |
Validator<Pair<Document, Param>> validator = new ValidatorBuilder<Pair<Document, Param>>("" /* message key separator */)
.nest(Pair::second, "", b -> b
.constraint(Param::getId, "id", c -> c.notNull())
.constraint(Param::getFieldA, "fieldA", c -> c.notNull().notBlank())
.constraint(Param::getFieldB, "fieldB", c -> c.notNull().notBlank()))
.constraintOnObject(Pair::first, "id", c -> c.notNull().message("{0} not exists"))
.constraintOnTarget(pair -> pair.first() == null || Objects.equals(pair.first().getOwnerId(), pair.second().getOwnerId()),
"ownerId", "no_permission", "no permission")
.build(); |
ok I see, Thanks for your help again @making |
Hi @making this is commons use cases in our projects, do you any idea or any plan to support this case Thanks |
It's hard to achieve it under the current design. I would use caching like Spring Framework provides |
Hi, Currently I am considering to fork yavi, and have a dirty hack. Extends and hack the |
Can you add test cases? I'm not sure what your commits want to achieve |
Hi @making test added |
Sorry, but I can't accept your proposal. It may require big changes to the code base |
Hi @making This make sense, and thanks for your time. It is just dirty changes, and for my own usage. |
@making Thanks for this library. I have been using |
@atkawa7 can you open a new issue? This is closed. |
Thanks @making I have created a new ticket copying this one |
this validator will execute
documentDao.findById
twice, is it possible to make thedocumentDao.findById
execute only once?Thanks
The text was updated successfully, but these errors were encountered: