elide
elide copied to clipboard
Commonize JSR 303 Validation Code
Need to write the JSR 303 validation code in a nice package that can be used where needed.
Is there any Validation example?
Unfortunately this functionality hasn't been baked in yet. We likely need to discuss a design to make this work for all datastores. However, to implement this today you can use any JSR 303 validator you wish. A reasonable hookpoint would be inside of the datastore for now.
You can override a datastore and probably run the validator in the save()
or commit()
(for the actual functionality, just call the respective super
method).
Some examples on calling a validator are here: https://developer.ucsd.edu/develop/data-layer/jpa/java-validation-api.html
To return a useful error through the API, you would most likely want to throw an appropriate WebApplicationException.
All that said, you can still use the hibernate-validator if you're already planning on using that. This works by virtue of hibernate controlling its execution.
Please let me know if you have any more questions on this.
Any update on this?
Sorry for the delay. We haven't actually implemented this yet. It shouldn't be very difficult, but there is a question as to whether or not we want Elide to always handle all JSR303 validations. It may not matter in practice, but other things like Hibernate do also perform JSR303 validations. Again, in the grand-scheme this may not matter too much, but I haven't thought through it.
Generally, we perform JSR303 validations internally today through a custom datastore. When objects are saved (or before commit), they are validated (we use standard JSR303 validator for execution). If an error occurs, we throw the appropriate exception to return an error to the user.