Custom spring-data repository backend - java

I already have a working object storage service, developed in-house - let's call it a database. Now I would like to use spring-data for CRUD operations on it, so that in the future I can easily switch to some conventional database.
The question in: how can I implement yet another spring-data repository backend? Any guides, tutorials?

The central piece to look at is the API in the Spring Data Commons module. It effectively provides the foundation for all of the existing store implementations. The support consist of the following aspects:
Object-to-store mapping (meta-model and conversion implementation)
Repository implementation and DI container configuration support
The best way to get started is by having a look at the MongoDB module for example and mimic the implementation. We're currently working on a developer guide whose work-in-progress version you can find in the Spring Data Commons wiki.

Related

Swagger / Openapi with openapi-generator where do we add the business logic code?

I have to create a rest api from scratch. I have already some experience with Jersey by doing mostly everything manualy.
I wanted to do it right now as this project is new. So I am currently trying the pet store sample that is available every time I am trying an openapi 3.0 online editor.
Using openapi-generator, I have generated the spring boot server for the pet store.
There are a lot of tutorial that will stop there. I don't understand where or how do I have to add my business logic code (database access, ....).
And after that I have a question, how is the specification update is done ?
With Spring Framework, you use Repository and Entity classes to handle data layer. And then add Service classes for business logic.
https://www.baeldung.com/spring-component-repository-service
Database (example in MySql): https://spring.io/guides/gs/accessing-data-mysql/

Reverse engineer database in spring data rest

I want to expose CRUD operations to MySql via REST apis. I have just started exploring Spring. I have found Spring rest data to be a good fit for this.
But there is only one problem, automating the generation of java model, repository classes, etc,. What are the tools available that can do this? I want this to be done without any interface, preferably via maven.

What are the advantages of using Spring Data REST over Spring Data JPA?

I know that spring data rest will export your repositories as REST services..but i want to know advantages of that over use of spring data jpa.
This is a fruit-salad-to-buffet comparison as the technologies solve completely different problems:
Spring Data JPA eases working with JPA on top of Spring. It exposes a repository programming model which allows you to build Java APIs to access data in relational databases.
Spring Data REST builds on top of the repository abstraction (not being tied to JPA at all) and exposes Spring MVC based REST resources following common patterns via a HTTP.
I suggest to skim through the getting started guides for Spring Data JPA and Spring Data REST to play with both of them and get a feel for the problems they solve.
Spring-Data-JPA is just one "flavour" of how you will persist your data. Among others, there are also MongoDB, Neo4J, etc. So as Oliver explained, Spring-Data is about how and where you keep your data.
On the other hand, Spring-Data REST is implementation, how to expose that data through REST using best practices.
Hope this clarifies a bit.

Differences between Spring Data and JDBC/ORM modules

I'm starting a new Java Web project using Spring and obviously I need data access in my application.
In previous applications I used JDBC or ORM modules of Spring framework to implement my data access layer, but some times ago I read about Spring Data project. I'm curious about it and I'd like to know the diffenrences between the two projects and understand if there are advantages passing from one approach to the other.
Spring data provides several functionalities:
Common functionality related to database applications - Defining a "repository" element (similar to DAO) with various functionalities, audit trail, etc.
JdbcTemplate like support for various NoSQL databases - MongoDB, Redis, Neo4J, and there are several community projects for other databases
High level functionality for JDBC (mostly Oracle) and JPA to reduce boilerplate code
Spring data also aims to save boilerplate code, as the repositories are defined as interfaces and the implementation is given by spring based on the method names.
Spring Data use JPA. it is also great for reducing the amount of boilerplate code that you need to write.
By writing the interfaces
E.g. table.findAll()
Its uses aspects to create the boilerplate code to select * from table
or table.findByName
it will implement the code to select by Name
have a look at this excellent tutorial http://www.petrikainulainen.net/spring-data-jpa-tutorial/

How to use existing java data bindings in grails?

I need to add a new datasource to my grails project wich uses the musicbrainz postgresql database. http://musicbrainz.org/doc/MusicBrainz_Database
I found a project on github where the data bindings are ready to use for a spring project:
https://github.com/lastfm/musicbrainz-data
Am i able to use these data bindings in a grails 2.2.3 project? If yes, how can i do this? (because there is no hibernate xml as needed by grails (regarding to the grails documentation: Hibernate Mapped Domain Classes))
I don't think it will be. Just setup the additional datasource and model out the tables or objects you need.
How do you access two databases in Grails
Once you do that, you can use all of the GORM methods and dynamic finders to get your data. Plus validation criteria, transactions, etc. Unless there is some very specialized criteria that make it necessary to bypass GORM, I would suggest leveraging it.

Categories

Resources