elide icon indicating copy to clipboard operation
elide copied to clipboard

Commonize JSR 303 Validation Code

Open DennisMcWherter opened this issue 9 years ago • 4 comments

Need to write the JSR 303 validation code in a nice package that can be used where needed.

DennisMcWherter avatar Feb 09 '16 16:02 DennisMcWherter

Is there any Validation example?

xiongxin avatar Feb 08 '18 07:02 xiongxin

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.

DennisMcWherter avatar Feb 08 '18 16:02 DennisMcWherter

Any update on this?

jstemen avatar Apr 19 '18 17:04 jstemen

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.

DennisMcWherter avatar Apr 24 '18 15:04 DennisMcWherter