HiKariCP for Bigquery - spring-boot

I am new to gcloud and trying to leverage bigquery for accessing the data. I am trying to implement a connection pooling mechanism for bigquery and found that Hikari (one of the default datasource provided by spring boot) as a viable option. Could you please guide me in setting up the Bigquery credentials in the Hikari datasource as I am not able to figure out the way to give the driver, url and credentials.
I imported the bigquery api and hikari api in my pom dependencies
FYI: I am trying to make use of springboot

I have managed to establish connection from spring boot to bigquery using simba JDBC drivers and successfully queried it.
Firstly, you need to include GCP starter dependency in your boot.
<artifactId>spring-cloud-gcp-dependencies</artifactId>
Dowload and add dependency jars of simba drivers in spring boot from the below link. Also refer installation guide in the link.
https://cloud.google.com/bigquery/docs/reference/odbc-jdbc-drivers
Secondly, create a service account that has access to bigquery and generate a key JSON file which is used to authenticate our spring boot application for connecting bigquery. Refer the below link.
https://cloud.google.com/bigquery/docs/reference/libraries#setting_up_authentication.
Lastly configure this key JSON file to be accessed by our spring book application using the simba driver JDBC installation guide.
Create a simba driver datasource and use this data source to create JDBC template bean. ( JDBC url formation is given in the installation guide of simba driver) . Thats it!! Run the application and see the results.
If you face any difficulties feel free to ask the specifics.

Related

How to configure database connection runtime in Spring Boot?

I made a new Spring Boot project using the Spring Initializr. I'm building an On-premise backend so what I'm trying to achieve is that when the user opens the jar executable and the server starts, he should be able to configure the database connection by going to localhost:8080/ in his web browser. Basically the index.html will have a form with 4 fields for IP Address, Database Name, UserName and Password. When the form is submitted spring will try to connect to the database with the provided information.
I have all my entities, repositories and controllers but currently the only way i can connect to a database is with the application.properties file, but since the user wont have access to the source, there should be a way for him to configure his database.
Thanks for your time!
I would suggest to use the Spring cloud Config server to store database related properties which is capable of picking up configuration at run time. Although it is typically configured with a Git repository, you can store them locally as pointed out in this thread.

How to create Springboot App with postgres using spring native graalvm?

I was trying to create a CRUD app using spring boot and postgres ,alongwith spring native.But I couldn't find any proper documentation related to it apart from spring native documentation.
The part of how to integrate it with postgres,is what I am looking for.Thankyou
You can use Spring Data like you would in a standard Spring Boot application. Depending on the type of application, you can use Spring Data JDBC, Spring Data JPA (if you need the Hibernate features), or Spring Data R2DBC (for reactive apps). If you bootstrap your application from start.spring.io, you can directly select the PostgreSQL dependency from there.
To get started with Spring Data, you can refer to this guide on the Spring website: relational data access with Spring Data JDBC. It uses H2, but you can replace it with PostgreSQL. More details are available on the project documentation.
On my GitHub, you can find an example of Spring Boot application with a REST API, security, and data persistence with PostgreSQL. And packaged as a native executable through Spring Native. If you're new to Spring Native, I wrote an article about how to get started with it.

How can we setup Spring Cloud Data Flow datasource to use Kerberos Auth8n

I'd like to install SCDF 2.6.x with an Oracle DB and Kerberos auth8n.
I am following the spring cloud data flow adocs in the source, and the online guides at https://docs.spring.io/spring-cloud-dataflow/docs/current-SNAPSHOT/reference/htmlsingle/#_oracle.
There's clarity on how to use an Oracle datasource, but only with username and password for authentication.
My aim is to be able to use Kerberos auth8n with an Oracle driver, and specify this in the server-config.yml for kubernetes deployment.

Spring-boot JPA connect to postgres where database and schema are provided at runtime

I am building a multi-tenant application, where the tenant database configuration are stored in Redis. Based on the request, I will query the Redis to get the database and schema configured for that tenant, this application is built on spring boot.
I took a look at spring boot's JPA sample, and did some more google to find a suitable solution for this, unfortunately, I couldn't find one.
Is this really possible to use JPA sample provided here ?
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-jpa
Please suggest me any other best possible way to tackle this problem
Thanks
Spring Data JPA uses JPA annotations to define domain model. These JPA entities define schema for your database. Obviously you can't change these entities, nor DB schema on runtime.
So no, updating schema on runtime is not possible with Spring Boot + Spring Data JPA combo.
Database connection (e.g. DB URL, username password) could be more flexible. You would need to create DataSource beans programmatically and somehow programatically define which data source to use for each query per tenant. But this wasn't requirement of Spring nor JPA ecosystem, therefore you may face lot of issues.
I was working on such system before, but we were using plain SQL queries via JDBC and were creating DB connection programatically to achieve schema changes on runtime.

Connecting Spring to Existing JDBC Connection

I've followed this tutorial through Spring's docs. It's nice, but I can not find anything online (and current) that shows how to connect to an existing DataSource through JDBC using Spring. Where can I configure this connection? This tutorial only shows how to create one (but where exactly is it even doing that?).
From your how-to link, you can see:
Spring Boot spots H2, an in-memory relational database engine,
and automatically creates a connection. Because we are using
spring-jdbc, Spring Boot automatically creates a JdbcTemplate.
The #Autowired JdbcTemplate field automatically loads it and
makes it available.
You can bypass the default DataSource by adding #EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) to your Application class. This link provides more detail on setting up a DataSource in Spring Boot.
...and the other sections are pretty useful too!
You are using Spring boot which contains embedded databases, in this case H2 database (check line "Spring Boot spots H2, an in-memory relational database engine, and automatically creates a connection.")
To provide custom connection and configure DataSource see this section https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html

Resources