jOOQ is an internal DSL and source code generator, modelling the SQL language as a type safe Java API to help you write better SQL
—
Comprehensive configuration system for customizing SQL rendering, execution behavior, debugging, and dialect-specific optimizations. Includes support for schema mapping, naming strategies, and performance tuning.
Main configuration class containing all jOOQ settings for customizing library behavior.
public class Settings {
/**
* Get the SQL rendering formatting setting
* @return RenderFormatting enum value
*/
public RenderFormatting getRenderFormatting();
/**
* Set SQL rendering formatting
* @param value Formatting setting
* @return Settings with updated formatting
*/
public Settings withRenderFormatting(RenderFormatting value);
/**
* Get the quoted names rendering setting
* @return RenderQuotedNames enum value
*/
public RenderQuotedNames getRenderQuotedNames();
/**
* Set quoted names rendering behavior
* @param value Quoted names setting
* @return Settings with updated quoted names behavior
*/
public Settings withRenderQuotedNames(RenderQuotedNames value);
/**
* Get the statement type setting
* @return StatementType enum value
*/
public StatementType getStatementType();
/**
* Set statement type (prepared vs static)
* @param value Statement type setting
* @return Settings with updated statement type
*/
public Settings withStatementType(StatementType value);
/**
* Get parameter type setting for SQL rendering
* @return ParamType enum value
*/
public ParamType getParamType();
/**
* Set parameter type for SQL rendering
* @param value Parameter type setting
* @return Settings with updated parameter type
*/
public Settings withParamType(ParamType value);
/**
* Get execution logging setting
* @return true if execution logging is enabled
*/
public Boolean getExecuteLogging();
/**
* Set execution logging behavior
* @param value true to enable execution logging
* @return Settings with updated logging setting
*/
public Settings withExecuteLogging(Boolean value);
/**
* Get query timeout setting in seconds
* @return Query timeout in seconds, 0 for no timeout
*/
public Integer getQueryTimeout();
/**
* Set query timeout in seconds
* @param seconds Timeout in seconds, 0 for no timeout
* @return Settings with updated timeout
*/
public Settings withQueryTimeout(Integer seconds);
/**
* Get fetch size for result sets
* @return Fetch size, 0 for driver default
*/
public Integer getFetchSize();
/**
* Set fetch size for result sets
* @param size Fetch size, 0 for driver default
* @return Settings with updated fetch size
*/
public Settings withFetchSize(Integer size);
/**
* Get batch size for batch operations
* @return Batch size, 0 for no batching
*/
public Integer getBatchSize();
/**
* Set batch size for batch operations
* @param size Batch size, 0 for no batching
* @return Settings with updated batch size
*/
public Settings withBatchSize(Integer size);
/**
* Get schema mapping settings
* @return List of schema mappings
*/
public List<MappedSchema> getSchemaMapping();
/**
* Set schema mapping for cross-schema queries
* @param mapping List of schema mappings
* @return Settings with updated schema mapping
*/
public Settings withSchemaMapping(List<MappedSchema> mapping);
}Core configuration interface that combines all jOOQ configuration elements.
public interface Configuration {
/**
* Get the SQL dialect for this configuration
* @return SQLDialect enum value
*/
SQLDialect dialect();
/**
* Get the settings for this configuration
* @return Settings instance
*/
Settings settings();
/**
* Get the connection provider
* @return ConnectionProvider for database connections
*/
ConnectionProvider connectionProvider();
/**
* Get the transaction provider
* @return TransactionProvider for transaction management
*/
TransactionProvider transactionProvider();
/**
* Get the record mapper provider
* @return RecordMapperProvider for custom record mapping
*/
RecordMapperProvider recordMapperProvider();
/**
* Get the record listener providers
* @return Array of RecordListenerProvider instances
*/
RecordListenerProvider[] recordListenerProviders();
/**
* Get the execute listener providers
* @return Array of ExecuteListenerProvider instances
*/
ExecuteListenerProvider[] executeListenerProviders();
/**
* Get the visit listener providers
* @return Array of VisitListenerProvider instances
*/
VisitListenerProvider[] visitListenerProviders();
/**
* Create a derived configuration with different settings
* @param newSettings New settings to use
* @return Configuration with updated settings
*/
Configuration derive(Settings newSettings);
/**
* Create a derived configuration with different connection provider
* @param newConnectionProvider New connection provider
* @return Configuration with updated connection provider
*/
Configuration derive(ConnectionProvider newConnectionProvider);
/**
* Create a derived configuration with different dialect
* @param newDialect New SQL dialect
* @return Configuration with updated dialect
*/
Configuration derive(SQLDialect newDialect);
}Usage Examples:
// Create custom settings
Settings settings = new Settings()
.withRenderFormatting(RenderFormatting.TRUE)
.withRenderQuotedNames(RenderQuotedNames.ALWAYS)
.withExecuteLogging(true)
.withQueryTimeout(30)
.withFetchSize(1000);
// Create configuration with custom settings
Configuration config = new DefaultConfiguration()
.set(SQLDialect.POSTGRES)
.set(settings)
.set(dataSource);
// Create DSLContext with configuration
DSLContext create = using(config);
// Derive configuration for different use cases
Configuration readOnlyConfig = config
.derive(new Settings().withQueryTimeout(5))
.derive(readOnlyDataSource);
DSLContext readOnly = using(readOnlyConfig);Key enumeration types for configuration options.
public enum RenderFormatting {
/**
* Format SQL with indentation and line breaks
*/
TRUE,
/**
* Render SQL in compact format
*/
FALSE
}
public enum RenderQuotedNames {
/**
* Always quote identifiers
*/
ALWAYS,
/**
* Quote identifiers when explicitly specified or required
*/
EXPLICIT_DEFAULT_QUOTED,
/**
* Don't quote identifiers unless explicitly specified
*/
EXPLICIT_DEFAULT_UNQUOTED,
/**
* Never quote identifiers
*/
NEVER
}
public enum StatementType {
/**
* Use prepared statements (recommended)
*/
PREPARED_STATEMENT,
/**
* Use static statements with inlined parameters
*/
STATIC_STATEMENT
}
public enum ParamType {
/**
* Use indexed parameters (?)
*/
INDEXED,
/**
* Use named parameters (:name)
*/
NAMED,
/**
* Use named parameters or inline values as appropriate
*/
NAMED_OR_INLINED,
/**
* Inline all parameter values directly in SQL
*/
INLINED
}Configuration for mapping database schemas and tables.
public class MappedSchema {
/**
* Get the input schema name (from database)
* @return Input schema name
*/
public String getInput();
/**
* Set the input schema name
* @param input Schema name from database
* @return MappedSchema with updated input
*/
public MappedSchema withInput(String input);
/**
* Get the output schema name (for queries)
* @return Output schema name
*/
public String getOutput();
/**
* Set the output schema name
* @param output Schema name to use in queries
* @return MappedSchema with updated output
*/
public MappedSchema withOutput(String output);
/**
* Get table mappings within this schema
* @return List of table mappings
*/
public List<MappedTable> getTables();
/**
* Set table mappings within this schema
* @param tables List of table mappings
* @return MappedSchema with updated table mappings
*/
public MappedSchema withTables(List<MappedTable> tables);
}
public class MappedTable {
/**
* Get the input table name (from database)
* @return Input table name
*/
public String getInput();
/**
* Set the input table name
* @param input Table name from database
* @return MappedTable with updated input
*/
public MappedTable withInput(String input);
/**
* Get the output table name (for queries)
* @return Output table name
*/
public String getOutput();
/**
* Set the output table name
* @param output Table name to use in queries
* @return MappedTable with updated output
*/
public MappedTable withOutput(String output);
}Usage Examples:
// Schema mapping for multi-tenant applications
MappedSchema tenantMapping = new MappedSchema()
.withInput("public")
.withOutput("tenant_123");
Settings settings = new Settings()
.withSchemaMapping(Arrays.asList(tenantMapping));
// Use configuration with schema mapping
DSLContext create = using(connection, SQLDialect.POSTGRES, settings);
// Query will automatically map "public" schema to "tenant_123"
Result<Record> result = create.selectFrom(USERS).fetch();
// Generated SQL: SELECT * FROM tenant_123.usersInterfaces for extending jOOQ functionality through listeners and custom providers.
public interface ExecuteListener {
/**
* Called before query execution
* @param ctx Execution context
*/
void executeStart(ExecuteContext ctx);
/**
* Called after query execution
* @param ctx Execution context
*/
void executeEnd(ExecuteContext ctx);
/**
* Called when an exception occurs during execution
* @param ctx Execution context with exception information
*/
void exception(ExecuteContext ctx);
}
public interface RecordListener {
/**
* Called before a record is stored
* @param ctx Record context
*/
void storeStart(RecordContext ctx);
/**
* Called after a record is stored
* @param ctx Record context
*/
void storeEnd(RecordContext ctx);
/**
* Called before a record is inserted
* @param ctx Record context
*/
void insertStart(RecordContext ctx);
/**
* Called after a record is inserted
* @param ctx Record context
*/
void insertEnd(RecordContext ctx);
/**
* Called before a record is updated
* @param ctx Record context
*/
void updateStart(RecordContext ctx);
/**
* Called after a record is updated
* @param ctx Record context
*/
void updateEnd(RecordContext ctx);
/**
* Called before a record is deleted
* @param ctx Record context
*/
void deleteStart(RecordContext ctx);
/**
* Called after a record is deleted
* @param ctx Record context
*/
void deleteEnd(RecordContext ctx);
}
public interface TransactionProvider {
/**
* Begin a new transaction
* @param ctx Transaction context
*/
void begin(TransactionContext ctx);
/**
* Commit the current transaction
* @param ctx Transaction context
*/
void commit(TransactionContext ctx);
/**
* Rollback the current transaction
* @param ctx Transaction context
*/
void rollback(TransactionContext ctx) throws DataAccessException;
}Usage Examples:
// Custom execute listener for logging
ExecuteListener loggingListener = new ExecuteListener() {
@Override
public void executeStart(ExecuteContext ctx) {
System.out.println("Executing: " + ctx.sql());
}
@Override
public void executeEnd(ExecuteContext ctx) {
System.out.println("Execution time: " + ctx.executionTime() + "ms");
}
};
// Custom record listener for auditing
RecordListener auditListener = new RecordListener() {
@Override
public void insertEnd(RecordContext ctx) {
System.out.println("Inserted record: " + ctx.record());
}
@Override
public void updateEnd(RecordContext ctx) {
System.out.println("Updated record: " + ctx.record());
}
};
// Configure with listeners
Configuration config = new DefaultConfiguration()
.set(SQLDialect.MYSQL)
.set(dataSource)
.set(ExecuteListenerProvider.providers(loggingListener))
.set(RecordListenerProvider.providers(auditListener));
DSLContext create = using(config);Install with Tessl CLI
npx tessl i tessl/maven-org-jooq--jooq