SQL
JVM since1.0.0 Native since1.0.0
Perform SQL queries using Spring JDBC.
What’s inside
-
SQL component, URI syntax:
sql:query
-
SQL Stored Procedure component, URI syntax:
sql-stored:template
Please refer to the above links for usage and configuration details.
Maven coordinates
Or add the coordinates to your existing project:
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-sql</artifactId>
</dependency>
Check the User guide for more information about writing Camel Quarkus applications.
Usage
If you are using SQL Aggregator in native mode, you have to register several classes for serialization using GraalVM
feature. Serialization support since GraalVM 21.0 allows developers to configure classes for serialization via
the serialization configuration file -H:SerializationConfigurationResources=/path-to/serialization-config.json
option.
For more information see pull request with feature.
Several classes has to be registered for serialization every time to make SQL Aggregator work in native.
Here is a template of serialization-config.json
with all mandatory classes:
[
{
"name" : "java.lang.Integer"
},
{
"name" : "java.lang.Number"
},
{
"name" : "java.lang.String"
},
{
"name" : "java.util.HashMap"
},
{
"name" : "java.util.LinkedHashMap"
},
{
"name" : "org.apache.camel.support.DefaultExchangeHolder"
}
]
Additional Camel Quarkus configuration
Configuring a DataSource
This extension leverages Quarkus Agroal for DataSource
support. Setting up a DataSource
can be achieved via configuration properties.
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=your-username
quarkus.datasource.password=your-password
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/your-database
quarkus.datasource.jdbc.max-size=16
The Camel SQL component will automatically resolve the DataSource
bean from the registry. When configuring multiple datasources, you can specify which one is to be used on an SQL endpoint via
the URI options datasource
or dataSourceRef
. Refer to the SQL component documentation for more details.
SQL scripts
When configuring sql
or sql-stored
endpoints to reference script files from the classpath, set the following configuration property to ensure that they are available in native mode.
Note that URI schemes such as file
or http
do not need to be listed.
quarkus.native.resources.includes = queries.sql, sql/*.sql