quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

Can´t enable JNDI datasources in quarkus #25112

Open hikemachado opened 2 years ago

hikemachado commented 2 years ago

Describe the bug

Hi all, After lots of research I found that quarkus does not support JNDI. (https://stackoverflow.com/questions/58401700/quarkus-how-to-specify-jndi-datasources) @Sanne asked me to open an issue here. Thanks for the advice.

I'm working on a project where we are moving old tecnologies to Quarkus.

The report developers are used to create reports using Pentaho Reports then they save those reports (.prpt) files and those files can be used on diferents environments by our report service app.

So the reports database connections are defined using JNDI (this configuration resides in each prpt file) this way doesnt matter the real connection configuration on our report service environments as the JNDI name is the same for all of them.

We are migrating to quarkus so we are stucked on trying to configure database connection using JNDI to avoid the necessity of changing all the connection configuration in the prpt files for all existent prpt, and also we will have to deal with configuring all the connections for each environment every time one report is created, or every new application installation or when the connection change on some of the environments

Thanks a lot for any help

Expected behavior

we expected that enabling JNDI datasource connection the JNDI would be defined with the same name used when configuring connection in application.properties something like:

quarkus.naming.enable-jndi=true
quarkus.datasource.mydb.db-kind=mysql
quarkus.datasource.mydb.jdbc.driver=com.mysql.cj.jdbc.Driver
quarkus.datasource.mydb.jdbc.url=jdbc:mysql://localhost:3306/mydb
quarkus.datasource.mydbl.username=user
quarkus.datasource.mydb.password=pass

and then when using JNDI name = mydb the reports would be able to connect to database and execute all queries

Actual behavior

JNDI datasource is not be defined

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

java version "11.0.3" 2019-04-16 LTS Java(TM) SE Runtime Environment 18.9 (build 11.0.3+12-LTS) Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.3+12-LTS, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.8.0-Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.6.3

Additional information

No response

Sanne commented 2 years ago

Idea: what if you had a bean which injects the configured Datasource, and then you register it yourself in JNDI, or inject it into Penthao Reports in any other way?

Apologies if that's making no sense, I don't actually know how Penthao is being started / integrated in your Quarkus application. If you had a simple example perhaps that could help.

hikemachado commented 2 years ago

hi Sanne, I´m not sure if the bean workaround would work. I created a repo https://github.com/hikemachado/jndi-quarkus it is a quarkus application. It contains 2 prpt files (/reports folder) one is using JNDI and the other is using explicit db conection in its sql_ds.xml file so you can see the difference The prpt files are zip files so you can open them and check those configurations in it Once the DB JNDI is defined in PRPT files the report developers doesnt have to worry about the db env-related config as just the jndi name must be the same. This is easier to migrate older reports that were already created using JNDI to our new quarkus application also to develop and maintain new reports in case of a db connection change.

thanks for all your help

hikemachado commented 2 years ago

Hi @Sanne ,

Any update on this?

Sanne commented 2 years ago

Hi @hikemachado , sorry I couldn't look into it yet. I'll see if a different team member has more time.

10101010101010001 commented 1 year ago

Checkout this link: https://github.com/keycloak/keycloak/discussions/11464

Keep your knees in the breeze.