Class Database.Builder
- Enclosing class:
Database
Database.
This class is intended for use by a single thread.
- Since:
- 1.0.0
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescription@NonNull Database.BuilderambiguousTimestampBindingStrategy(@Nullable AmbiguousTimestampBindingStrategy ambiguousTimestampBindingStrategy) Configures how Pyranid bindsInstantandOffsetDateTimeparameters when JDBC parameter metadata cannot identify whether the target isTIMESTAMPorTIMESTAMP WITH TIME ZONE.@NonNull Databasebuild()@NonNull Database.BuilderdatabaseType(@Nullable DatabaseType databaseType) Overrides automatic database type detection.@NonNull Database.BuilderConfigures a database-wide JDBC fetch size default.@NonNull Database.BuilderinstanceProvider(@Nullable InstanceProvider instanceProvider) @NonNull Database.BuilderConfigures a database-wide JDBC maximum row count default.@NonNull Database.BuildermetricsCollector(@Nullable MetricsCollector metricsCollector) Configures the metrics collector for theDatabasebeing built.@NonNull Database.BuilderparameterRedactor(@Nullable ParameterRedactor parameterRedactor) Configures the redactor used for non-secure parameters in diagnostics.@NonNull Database.BuilderparsedSqlCacheCapacity(@Nullable Integer parsedSqlCacheCapacity) Configures the size of the parsed SQL cache.@NonNull Database.BuilderpreparedStatementBinder(@Nullable PreparedStatementBinder preparedStatementBinder) @NonNull Database.BuilderqueryTimeout(@Nullable Duration queryTimeout) Configures a database-wide JDBC query timeout default.@NonNull Database.BuilderresultSetMapper(@Nullable ResultSetMapper resultSetMapper) @NonNull Database.BuilderstatementLogger(@Nullable StatementLogger statementLogger) Configures the statement logger for theDatabasebeing built.@NonNull Database.BuilderConfigures the database time zone Pyranid should use when converting zone-less temporal values.
-
Method Details
-
databaseType
Overrides automatic database type detection.If
null, the database type is detected lazily when database-type-specific behavior is first needed. Supplying a non-null value avoids automatic detection and its metadata lookup entirely.- Parameters:
databaseType- the database type to use (null to enable auto-detection)- Returns:
- this
Builder, for chaining - Since:
- 4.0.0
-
timeZone
Configures the database time zone Pyranid should use when converting zone-less temporal values.This value is used when mapping
TIMESTAMPvalues to instant-based Java types, and when bindingInstantorOffsetDateTimeparameters to knownTIMESTAMPtargets. It also applies to ambiguous timestamp bindings ifambiguousTimestampBindingStrategy(AmbiguousTimestampBindingStrategy)is configured withAmbiguousTimestampBindingStrategy.TIMESTAMP_WITHOUT_TIME_ZONE.If
null, Pyranid usesZoneId.systemDefault().- Parameters:
timeZone- database time zone to use, ornullfor the JVM default zone- Returns:
- this
Builder, for chaining - Since:
- 3.0.0
-
ambiguousTimestampBindingStrategy
public @NonNull Database.Builder ambiguousTimestampBindingStrategy(@Nullable AmbiguousTimestampBindingStrategy ambiguousTimestampBindingStrategy) Configures how Pyranid bindsInstantandOffsetDateTimeparameters when JDBC parameter metadata cannot identify whether the target isTIMESTAMPorTIMESTAMP WITH TIME ZONE.The default,
AmbiguousTimestampBindingStrategy.TIMESTAMP_WITH_TIME_ZONE, is appropriate for timestamp-with-time-zone targets. UseAmbiguousTimestampBindingStrategy.TIMESTAMP_WITHOUT_TIME_ZONEfor drivers or proxies that cannot provide identifying parameter metadata when your target columns are zone-lessTIMESTAMPvalues that should be interpreted intimeZone(ZoneId).- Parameters:
ambiguousTimestampBindingStrategy- strategy to use, ornullfor the default- Returns:
- this
Builder, for chaining - Since:
- 4.2.0
-
instanceProvider
-
preparedStatementBinder
public @NonNull Database.Builder preparedStatementBinder(@Nullable PreparedStatementBinder preparedStatementBinder) -
resultSetMapper
-
statementLogger
Configures the statement logger for theDatabasebeing built.StatementLoggerfailures are fail-fast: a logger exception can make a successful statement operation throw, and inside a Pyranid transaction it participates in normal rollback handling. If the database statement itself failed, logger failures are suppressed onto the primary statement failure.- Parameters:
statementLogger- statement logger to use, ornullfor a no-op logger- Returns:
- this
Builder, for chaining
-
parameterRedactor
Configures the redactor used for non-secure parameters in diagnostics.SecureParametervalues always render viaSecureParameter.getMask()and are never passed to this redactor. Batch executions render a bounded batch summary instead of invoking the redactor for each batch value. Specifynullor omit this setter to render non-secure, non-batch values verbatim.- Parameters:
parameterRedactor- parameter redactor to use, ornullfor the default- Returns:
- this
Builder, for chaining - Since:
- 4.4.0
-
metricsCollector
Configures the metrics collector for theDatabasebeing built.Like all
Databaseconfiguration, this value is fixed atbuild()time. Specifynullor omit this setter to disable metrics collection.- Parameters:
metricsCollector- metrics collector to use, ornullto disable- Returns:
- this
Builder, for chaining - Since:
- 4.2.0
-
queryTimeout
Configures a database-wide JDBC query timeout default.This maps to
Statement.setQueryTimeout(int).nullleaves the timeout unset.Duration.ZEROdisables the JDBC timeout. Positive sub-second durations are rounded up to one second because JDBC accepts whole seconds. Per-queryQuery.queryTimeout(Duration)settings override this value, andQuery.customize(PreparedStatementCustomizer)runs last.- Parameters:
queryTimeout- timeout to apply by default, ornullto leave unset- Returns:
- this
Builder, for chaining - Since:
- 4.2.0
-
fetchSize
Configures a database-wide JDBC fetch size default.This maps to
Statement.setFetchSize(int).nullleaves the fetch size unset. A value of0uses the driver's default fetch-size behavior. Per-queryQuery.fetchSize(Integer)settings override this value, andQuery.customize(PreparedStatementCustomizer)runs last.- Parameters:
fetchSize- fetch size to apply by default, ornullto leave unset- Returns:
- this
Builder, for chaining - Since:
- 4.2.0
-
maxRows
Configures a database-wide JDBC maximum row count default.This maps to
Statement.setMaxRows(int).nullleaves the maximum row count unset. A value of0disables the JDBC row limit. Per-queryQuery.maxRows(Integer)settings override this value, andQuery.customize(PreparedStatementCustomizer)runs last.- Parameters:
maxRows- maximum rows to apply by default, ornullto leave unset- Returns:
- this
Builder, for chaining - Since:
- 4.2.0
-
parsedSqlCacheCapacity
Configures the size of the parsed SQL cache.A value of
0disables caching. A value ofnulluses the default size.- Parameters:
parsedSqlCacheCapacity- cache size (0 disables caching, null uses default)- Returns:
- this
Builder, for chaining
-
build
-