i am using spring/hibernate application. i configured c3p0 connection pool. my application has 5 datasources which connects to 5 different databases. 5 databases are for 5 different modules.
when i am using one module it has connected to some datasource. is it possible to get that particular datasource which is being used by the current module?
Thanks!
You must be explicitly selecting a data source for a module. Check in the code.
Related
I have two environments like onprem and aws, for
onprem we have connected with Oracle database and required configuration
is done and but for aws we are using aurora postgres and whenever
i have tried to add postgres dependency then deploying into
aws environment it's giving error so is it possible if we have
multiple dependencies in same pom file and used for different environments.
Quarks version : 1.13.3.final
Sample configuration:
Oracle:
-------
quarkus.datasource.db-kind=oracle
quarkus.datasource.username=user-default
quarkus.datasource.password=password-default
quarkus.datasource.reactive.url=jdbc:oracle:thin://localhost:5432/default
Postgresql:
-----------
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=user-default
quarkus.datasource.password=password-default
quarkus.datasource.reactive.url=postgresql://localhost:5432/default
Code or issue:
The issue i'm getting is as follows:
2021-11-11 07:18:45,173 WARN [org.hib.eng.jdb.env.int.JdbcEnvironmentInitiator] (main) HHH000342: Could not obtain connection to query metadata: java.sql.SQLException: Driver does not support the provided URL: jdbc:postgresql://
at io.agroal.pool.ConnectionFactory.connectionSetup(ConnectionFactory.java:220)
at io.agroal.pool.ConnectionFactory.createConnection(ConnectionFactory.java:204)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:490)
at io.agroal.pool.ConnectionPool$CreateConnectionTask.call(ConnectionPool.java:472)
Dependencies:
quarkus-jdbc-oracle
quarkus-jdbc-postgresql
According to the official documentation, you can use Multiple Datasources.
However if you have more than 1, then you must provide a Name, otherwise how will Quarkus know which Drivers to use.
The format : quarkus.datasource.<datasourceCustomName>. If it is not your default DataSource which will not require a name.
Important to Notice: For now, multiple datasources are only supported for JDBC and the Agroal extension. So it is not currently possible to create multiple reactive datasources.
https://quarkus.io/guides/datasource#multiple-datasources
Multiple Datasources
Configuring Multiple Datasources
For now, multiple datasources are only supported for JDBC and the
Agroal extension. So it is not currently possible to create multiple
reactive datasources.
The Hibernate ORM extension supports defining several persistence
units using configuration properties. For each persistence unit, you
can point to the datasource of your choice.
Defining multiple datasources works exactly the same way as defining a
single datasource, with one important change: you define a name.
In the following example, you have 3 different datasources:
The default one,
A datasource named users,
A datasource named inventory,
each with its own configuration.
quarkus.datasource.db-kind=h2
quarkus.datasource.username=username-default
quarkus.datasource.jdbc.url=jdbc:h2:mem:default
quarkus.datasource.jdbc.max-size=13
quarkus.datasource.users.db-kind=h2
quarkus.datasource.users.username=username1
quarkus.datasource.users.jdbc.url=jdbc:h2:mem:users
quarkus.datasource.users.jdbc.max-size=11
quarkus.datasource.inventory.db-kind=h2
quarkus.datasource.inventory.username=username2
quarkus.datasource.inventory.jdbc.url=jdbc:h2:mem:inventory
quarkus.datasource.inventory.jdbc.max-size=12
quarkus.datasource.db-kind is fixed at build time. The property can not change at runtime.
You have to build the app for Oracle and seperate for Postgresql
https://quarkus.io/guides/all-config#quarkus-datasource_quarkus.datasource.db-kind
So I have two Springboot applications that are independant. Both are using distinct mariadb databases with distince schemas names.
To make it simple:
For some reason, my app1 has to be able to access db2 data. Ive been able to add a second datasource in my app1, however, due to differences between flyway and liquibase, it fails to start.
How can i do so that my flyway configuration is ignored for datasource 2 (db2). App1 should just access data (read/write whatever) but the whole database structure is handled by App2.
I'm writing a web application in Java and use Hibernate to map the database with my java objects. In Hibernate I connect to the database using C3PO pool. Now I need to schedule some tasks. Herefore I will use Quartz. Now the scheduled tasks will be stored in the database. It is possible to share the connection pool of C3PO with Quartz? So that the database settings are in one and the same file and that only one library is responsible to open a databaseconnection.
This is sort of a subjective thing, but suffice it to say, if you want to share the connection you have a number of options.
If you are using spring, define the c3p0 connection pool as a bean and inject it into both the Hibernate session factory and the Quartz scheduler beans.
If you are trying to stay "pure" and not using Spring, you can define your a JNDI based data-source at the container level.
There are some nuances with both approaches.
Unfortunately without indicating how "portable" you are trying to be and what you are currently using beyond just 'java', 'quartz-scheduler' and 'c3p0' as tags an answer will be vague at best.
EDIT
Thanks to the OP for adding additional information.
So with regard to that information, if you are using a Dynamic Web Project, you may be able to add a container specific deployment descriptor to WebContent directory.
For tomcat, META-INF/context.xml
For Jetty, WEB-INF/jetty-web.xml
With those, you can define a JNDI data source. Refer to the specific container for information on how to do that. Once done, Hibernate and Quartz can be configured to use a JNDI reference for the data source you have configured.
I've a Java Web application that currently consists of:
multiple live existing servlets - using MyBatis
a single pool connection to a Postgresql database via tomcat's server context.xml configuration.
This ensures that the all the servlets share a common application pool.
I'm adding database analysis loggging to the system, using pgBadger. The analysis the database log output.
If I was setting this system up new I would likely have created users per servlet and I could use the username to identify the servlet SQL statements called.
As I am using Mybatis to create my Java Objects from the Database, the SQL from each servlet is identical.
Can I possible use the datasource connection's application name parameter for each servlet, but still have a common pool?
In other words: is it possible to use a common database connection pool, but have different application name passed onto the database?
Or indeed can I use the same pool and use a different username?
Does both these constraints mean that the connection pools need to be multiplied by the number of servlets?
I am about to make a connection to my database and I am using EJB and JPA. I have recently started doing these technologies so I have some problems understand it all at this point:)
I know that the persistence.xml is needed in order to use JPA. It is the file where I configure how to connect to the database, that I know. However it seems like there are multiple ways of doing it.
What would be the difference (or when should I even use the one alternative over the other?) of defining properties such as username, database, password etc. in the persistence.xml file and in Glassfish? Advantages/disadvantages if any.
Underneath on the image I posted I have JDBC Resources and JDBC Connection Pools. I am a litte confused about the terminology of the two. Why don't we add properties such as username, database, password and so on in the JDBC Resources? Could someone explain the difference between them and what they mean?
JDBC Resources
A JDBC resource (data source) provides applications with a means of
connecting to a database. Typically, the administrator creates a JDBC
resource for each database accessed by the applications deployed in a
domain. (However, more than one JDBC resource can be created for a
database.)
http://download.oracle.com/docs/cd/E19316-01/820-4335/ablih/index.html
I think it strange that we add such properties on the pool but not in the resource, but I probably misunderstand the concepts.
In the "JDBC connection pools" you can create container managed JDBC data sources (with connection pooling capabilities). The data source needs to know about at least the JDBC driver, the JDBC URL, username and password.
In the "JDBC resources" you can bind those container managed JDBC data sources to one or more JNDI names so that they are by JNDI available to the deployed web application.
In the persistence.xml you can specify whether to use a local data source or to use a container managed data source. If you want to use a container managed data source, then you should specify its JNDI name. Using a container managed data source has the advantage that you can share a single data source among multiple web applications. In case of JPA, it has also the advantage that you can make use of JTA (container managed transactions) so that you don't need to call transaction.begin(), commit(), rollback() etc in every method.