Version v1.4 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.

Database Config

Overview

DatabaseConfig can be specified to customize the behavior of the Database instance.

Here is an example of creating a JdbcDatabase instance.

val dataSource: DataSource = ..
val dialect: JdbcDialect = ..
val config: JdbcDatabaseConfig = object: DefaultJdbcDatabaseConfig(dataSource, dialect) {
    // you can override properties here
}
val db = JdbcDatabase(config)

Here is an example of creating a R2dbcDatabase instance.

val connectionFactory: ConnectionFactory = ..
val dialect: R2dbcDialect = ..
val config: R2dbcDatabaseConfig = object: DefaultR2dbcDatabaseConfig(connectionFactory, dialect) {
  // you can override properties here
}
val db = R2dbcDatabase(config)

Properties

The behavior of the Database instance can be customized by overriding the JdbcDatabaseConfig and R2dbcDatabaseConfig properties described below or by using the service loader mechanism.

clockProvider

The clockProvider provides the Clock object which is used to set timestamps on entity class properties.

Target entity class properties are those annotated with @KomapperCreatedAt or @KomapperUpdatedAt.

By default, this property returns a provider that generates the current time using the system default zone ID.

executionOptions

Default runtime options for JDBC and R2DBC. The following settings are available:

batchSize
Batch size for batch updates with INSERT, UPDATE, and DELETE. Default is null. If the batch size is not specified even in the query options, 10 is used.
fetchSize
Fetch size when a SELECT statement is issued. Default is null to indicate that the driver value should be used.
maxRows
The maximum number of rows when a SELECT statement is issued. Default is null to indicate that the driver value should be used.
queryTimeoutSeconds
Query timeout in seconds. Default is null to indicate that the driver value should be used.
suppressLogging
Whether to suppress SQL log output. Default is false.

All of these can be overridden by the query options.

logger

The logger is an adapter for various logger implementations.

By default, this property is resolved by the service loader. If the service loader cannot resolve the logger, this property returns a logger that uses standard output.

The following modules provide logger implementations:

  • komapper-slf4j

See also Logging.

loggerFacade

The loggerFacade accepts log output instructions, formats log messages, and sends them to the logger. All log output from Komapper goes through this facade.

To change the log message or log level, switch the facade implementation.

See also Logging.

statementInspector

The statementInspector inspects org.komapper.core.Statement just before SQL execution.

By default, this property is resolved by the service loader. If the service loader cannot resolve the logger, this property returns an inspector that does nothing.

The following modules provide inspector implementations:

  • komapper-sqlcommenter

templateStatementBuilder

The templateStatementBuilder is a builder that constructs org.komapper.core.Statement from SQL templates.

By default, this property is resolved by the service loader. If the service loader cannot resolve the builder, this property throws an exception.

The following modules provide builder implementations:

  • komapper-template

See also TEMPLATE.

Last modified March 11, 2022: Update the title and linkTitle (cf9ed4f)