Class DurationArgumentFactory
- java.lang.Object
-
- org.jdbi.v3.core.argument.AbstractArgumentFactory<java.time.Duration>
-
- org.jdbi.v3.postgres.DurationArgumentFactory
-
- All Implemented Interfaces:
ArgumentFactory,ArgumentFactory.Preparable
public class DurationArgumentFactory extends AbstractArgumentFactory<java.time.Duration>
Postgres version of argument factory forDuration.For simplicity, this implementation makes the duration positive before proceeding. However, this can cause an
ArithmeticExceptionto be thrown. E.g., this can occur if your duration is -2^63 seconds.Not all
Durations can be represented as intervals in Postgres. One incompatibility results fromDurations that are too large. This is due to (1)Durations using alonginternally, andPGIntervals usingints; and (2) the conversion of days to months or years being ambiguous. Another results fromDurations being too precise; they have nanosecond precision, whereas Postgres has only microsecond. AnIllegalArgumentExceptionwill be thrown in these cases. The handling of the second is subject to revision in the future; for example, it would be reasonable to have a configurable truncation option.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jdbi.v3.core.argument.ArgumentFactory
ArgumentFactory.Preparable
-
-
Constructor Summary
Constructors Constructor Description DurationArgumentFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Argumentbuild(java.time.Duration duration, ConfigRegistry config)Produce an argument object for the given value.-
Methods inherited from class org.jdbi.v3.core.argument.AbstractArgumentFactory
build, prepare, prePreparedTypes
-
-
-
-
Method Detail
-
build
public Argument build(java.time.Duration duration, ConfigRegistry config)
Description copied from class:AbstractArgumentFactoryProduce an argument object for the given value. When the implementation class has accepted a given type, it must then produce an argument instance or throw an exception.- Specified by:
buildin classAbstractArgumentFactory<java.time.Duration>- Parameters:
duration- the value to convert to an argumentconfig- the config registry- Returns:
- An
Argumentfor the givenvalue. Must not be null!
-
-