Spring data and multiple schema config - spring-boot

I'm trying to configure spring boot 1.3.5 + spring data with one datasource and multiples schemas. I've read a lot of post but none helped me.
I want that each costumer has it own schema and i want to create it at a runtime as soon as the new client costumer.
Can someone put an example to help me do it?

Related

Latest by group query using Spring Boot JPA

I am using Spring Boot 2.5.0 for one of my test projects and need to get some data from one of the transaction tables. I need only latest record per group from this table. This problem has a solution given multiple times on SO, one of which is https://stackoverflow.com/a/1313293/841221.
However, I want to implement the same using Spring Boot Data JPA and not using a native query as using a native query would make me lose database independence.
Can someone please help me?

How to set up a connection between spring boot project and PostgresSQL DB

I created a spring boot project and I link it with my DB under PgAdmin.
I've modified the application.properties correctly and created a class named "user" and its repository "userRepository" but I don't know if this will automaticly create the user table in the DB (I used annotations) or I have to create it in PgAdmin ?
Do I need to specify any controller or webController if I want to have Crud operations ? And where does the CrudRepository exists do I need to generate it and how ?
Excuse me this my first experience with spring, I will really appreciate if you guys can help me.
Thanks in advance.
For your first question:
I don't know if this will automaticly create the user table in the DB
You have several ways how to create your tables, for example with property in application.properties file
spring.jpa.hibernate.ddl-auto = [none|validate|update|create-drop]
where none means this configuration not affect existing database
update means updating changes in database
create-drop means creating all tables from scratch according your project entities classes.
You can check this documentations for additional information
https://docs.spring.io/spring-boot/docs/1.1.0.M1/reference/html/howto-database-initialization.html
59.2 Initialize a database using Hibernate
also you can check how to initialize database with existing sql scripts files in documentation above
59.3 Initialize a database using Spring JDBC
For question: Do I need to specify any controller or webController if I want to have Crud operations ? And where does the CrudRepository exists do I need to generate it and how ?
Yes you should create controllers to handle requests and repositories to work with JPA.I also suggest check tutorial first, for example this one (first in google)
https://bezkoder.com/spring-boot-jpa-crud-rest-api/

How to set multiple data sources in Spring Data R2DBC

I am using spring data r2dbc in my new project and need to connect multiple data sources like A data source and B data source.
Is there a way to connect multiple data sources using r2dbc?
Could I get an example or a document if there is a way?
My stacks are below:
Spring Boot 2.3.0.M4
Spring WebFlux
Spring Data R2DBC
If you want to use multiple datasources in a single application, check my multi r2dbc connection factories example.
If you need a multi-tenant like feature check this multi-tenancy-r2dbc example.
I solved this issue using AbstractRoutingConnectionFactory you can check Add support for AbstractRoutingConnectionFactory

Teiid Spring Boot #SelectQuery

I have configured 2 different data souces in my Teiid Spring Boot Application and have been following this example:
https://github.com/teiid/teiid-spring-boot/blob/master/docs/UserGuide.adoc
This example demonstrates a union query from Customer table from two different data sources, however, when i run my application the customerrepository retrieves records only from one database and not from the other.
I have uploaded my source code on github:
https://github.com/purnimadas27/TeiidExample1/tree/master/TeiidSpringBootPrj5
Can someone suggest why is my union query not retrieving results as expected, it appears that the customerrepository is bound to only one of the datasource and is retrieving results only from one datasource and it also appears that #SelectQuery is not being considered at all.
Any help is greatly appreciated, thank you!
See this full example here with updated document
Updated: I could not figure out root issue is, this was not occurring with latest code, so wrote a new example with 1.3.1 release of the Teiid Spring Boot. This should work.

Change the Hibernate database schema at run time in spring boot application

I have A requirement where the current schema to be used is stored in db table;(schema_a or schema_b).
The application is loaded with default schema
spring.jpa.properties.hibernate.default_schema=schema_a
Now when the data in table is updated to B I want to consider all jpa query to use schema_b without any down time at server.
Your question is not clear enough to provide some code to your question, but you can catch inspiration from the following articles:
https://spring.io/blog/2007/01/23/dynamic-datasource-routing/
Spring Boot - Change connection dynamically

Resources