Spring CrudRepository - spring

I am trying to implement all basic CRUD operations using Spring and CrudRepository. I have already implemented GET, POST, DELETE, PUT but I want also to implement PATCH. Does Crud Repository supports HTTP PATCH? Because so far I haven't find any method of CrudRepository that implements that.

When you check the HTTP PATCH,
PATCH means: Modifies the given record
If you want to implement it, you just need call the Update API of your CrudRepository in your Service/Controller class with the PATCH method.
But in mordern REST API implementation, we seldom use this. Most USE PUT instead.
For the several REST part, you can refer to:
confusion between post and get method

Related

Spring Data Rest modify Repository method URI

This may be a bit of a rudimentary question, but I have a repository where I can do a find by username as follows:
....../items/search/byUsername/?username=myusername
However, this is generally inconsistent with how AngularJS Resources treat queries. Is there a way to instead make the request URI for the same thing to be
....../items/?username=myusername
Or does that functionality not exist with spring data rest? custom methods can be made in the angular resource but it is tedious to do that for every possible search category
If Angular (read: a client library) defines what URI's have to look like, then it's fundamentally violating a core REST principle — which is that clients follow links and URI templates.
That said, if you're using Querydsl and let your repository extend QuerydslPredicateExecutor, collection resources can be filtered by using property expressions. See the reference documentation for details.
Another option would be to manually expose resources under the URIs expected and manually forward the calls. But again, I'd argue you're better off teaching Angular to behave like a proper REST client in the first place 🙃.

ehcache restful service methods override/extend

my question may be vague to ask. I am trying to use ehcache restful service methods such as get or put. I am not sure how this works under hood, is there any way I can override these methods? I mean, get always looks up in cache, but I want to look up in database if not found in cache. I can implement this behavior by writing my own rest service methods, but is there anyway to use ehcache built-in rest functionality by overriding their methods or extend their methods to look up in database if not found in cache. Appreciate your help, thanks.

spring data neo4j - using server extension through repository

I read about the server extensions available in neo4j in server mode. I was wondering if it is possible to somehow annotate repository method to use this extension insted of allowing to create query based on method name or #Query annotation?
If not, is there easy way to invoke REST interface methods using Neo4jTemplate?
That's not possible right now, it would be cool though, feel free to raise a JIRA issue that describes your suggestion in more detail. Perhaps Spring-Data-REST Clients allow such a thing.

Adding behaviour to single repositories which uses base repository methods

I want to add custom behavior to single repository as described in 1.4.1 Adding behaviour to single repositories. In this custom behavior I want to use method already present in my base repository (like save() or findOne() method). Ho can I achieve this in Spring data?
I tried extending my UserRepositoryImpl with SimpleJpaRepository to have basic SimpleJpaRepository methods available. But this way I got instantiation problems.
Also using aproach described in 1.4.2 Adding custom behaviour to all repositories doesn't seem like good solution, because it's way too much code for adding one simple method. In this case Spring Data seems more like burden.
Or is it antipatern to add to my repository such simple method which depends on other methods from base repository? Should I rather move this method to service/business layer?
The same question came up a few days ago in this post. As I wrote there as well, I strongly believe this is an antipattern, so my answer to your last question would be a definite yes.

PUT method in jersey

I am new to Restful webservice. When I was going through the tutorials, I saw that PUT method can be used to create the resource. the creation means adding into the database or somewhere by implementing our own effort? or will Jersey take care of creating the resource its own?
Sorry for asking silly questions.. I did not get the way what PUT is doing..
Thanks
Bhanu
Jersey won't do anything except you tell it to. A PUT request semantically should create or update a ressource, so if you plan to create some entity, thats the HTTP method to use. Use #PUT to annotate your method and implement your functionality (as your tutorials tell you).

Resources