Starter for using jOOQ to access SQL databases with JDBC, providing auto-configuration and Spring integration
—
Configuration properties and customization options for jOOQ integration in Spring Boot applications.
Configuration properties class that maps to spring.jooq.* properties in your application configuration.
/**
* Configuration properties for jOOQ database library under spring.jooq prefix
*/
@ConfigurationProperties("spring.jooq")
public class JooqProperties {
/** SQL dialect to use. Auto-detected by default. */
private SQLDialect sqlDialect;
/** Location of the jOOQ config file. */
private Resource config;
/**
* Get the configured SQL dialect
* @return the SQL dialect, or null if auto-detection should be used
*/
public SQLDialect getSqlDialect();
/**
* Set the SQL dialect to use
* @param sqlDialect the SQL dialect
*/
public void setSqlDialect(SQLDialect sqlDialect);
/**
* Get the jOOQ configuration file location
* @return Resource pointing to the config file, or null if not specified
*/
public Resource getConfig();
/**
* Set the jOOQ configuration file location
* @param config Resource pointing to the XML configuration file
*/
public void setConfig(Resource config);
/**
* Determine the SQL dialect to use based on configuration and DataSource
* Uses explicit sqlDialect if set, otherwise auto-detects from DataSource
* @param dataSource the primary data source
* @return the SQL dialect to use for the DataSource
*/
public SQLDialect determineSqlDialect(DataSource dataSource);
}Functional interface for customizing jOOQ's DefaultConfiguration while retaining auto-configuration benefits.
/**
* Callback interface for beans that want to customize DefaultConfiguration
* while keeping default auto-configuration
*/
@FunctionalInterface
public interface DefaultConfigurationCustomizer {
/**
* Customize the jOOQ Configuration
* @param configuration the configuration to customize
*/
void customize(DefaultConfiguration configuration);
}Utility class for automatically determining the appropriate SQL dialect from a DataSource.
/**
* Utility to lookup well known SQL dialects from a DataSource
* Used internally for auto-detection when spring.jooq.sql-dialect is not specified
*/
final class SqlDialectLookup {
/**
* Return the most suitable SQL dialect for the given DataSource
* @param dataSource the source DataSource
* @return the most suitable SQL dialect, or SQLDialect.DEFAULT if detection fails
*/
static SQLDialect getDialect(DataSource dataSource);
}Usage Examples:
# Specify SQL dialect explicitly (otherwise auto-detected)
spring.jooq.sql-dialect=MYSQL
# Specify external jOOQ configuration file
spring.jooq.config=classpath:jooq-config.xml# YAML format
spring:
jooq:
sql-dialect: POSTGRESQL
config: classpath:config/jooq-settings.xml@Component
public class MyJooqCustomizer implements DefaultConfigurationCustomizer {
@Override
public void customize(DefaultConfiguration configuration) {
// Add custom converters
configuration.set(new LocalDateTimeConverter());
// Add custom execute listeners
configuration.set(new DefaultExecuteListenerProvider(
new MyCustomExecuteListener()
));
// Customize settings programmatically
Settings settings = new Settings();
settings.withExecuteLogging(true);
settings.withRenderSchema(false);
configuration.set(settings);
}
}When spring.jooq.config is specified, you can provide an external XML configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://www.jooq.org/xsd/jooq-runtime-3.18.0.xsd">
<settings>
<executeLogging>true</executeLogging>
<renderSchema>false</renderSchema>
<renderNamedParamPrefix>$</renderNamedParamPrefix>
<fetchWarnings>true</fetchWarnings>
</settings>
</configuration>The SQL dialect is automatically detected based on your DataSource configuration:
// Auto-detection examples based on JDBC URL patterns:
// jdbc:mysql://... -> SQLDialect.MYSQL
// jdbc:postgresql://... -> SQLDialect.POSTGRES
// jdbc:h2:... -> SQLDialect.H2
// jdbc:oracle:... -> SQLDialect.ORACLE
// etc.
@Service
public class DatabaseService {
@Autowired
private DSLContext dsl;
public void demonstrateDialectSpecificFeatures() {
// The DSLContext automatically uses the correct dialect
// MySQL-specific syntax when using MySQL
// PostgreSQL-specific syntax when using PostgreSQL
// etc.
}
}You can define multiple customizers with ordering:
@Component
@Order(1)
public class ConverterCustomizer implements DefaultConfigurationCustomizer {
@Override
public void customize(DefaultConfiguration configuration) {
// Add data type converters
configuration.set(new LocalDateConverter());
}
}
@Component
@Order(2)
public class ListenerCustomizer implements DefaultConfigurationCustomizer {
@Override
public void customize(DefaultConfiguration configuration) {
// Add execute listeners (after converters)
configuration.set(new DefaultExecuteListenerProvider(
new AuditingExecuteListener()
));
}
}org.jooq.SQLDialect enum valueH2, MYSQL, MARIADB, POSTGRES, ORACLE, SQLSERVER, SQLITE, DERBY, HSQLDB, etc.classpath:jooq-config.xmlfile:/path/to/config.xmlconfig/jooq-settings.xmlNote: When using spring.jooq.config, JAXB must be available on the classpath for XML parsing. If JAXB is not available, a JaxbNotAvailableException will be thrown with helpful error information.
Install with Tessl CLI
npx tessl i tessl/maven-org-springframework-boot--spring-boot-starter-jooq