Skip to content

Commit a628ae9

Browse files
author
Philipp Wagner
committed
Add IntervalValueHandler
1 parent 7d3a015 commit a628ae9

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

PgBulkInsert/src/main/java/de/bytefish/pgbulkinsert/pgsql/handlers/ValueHandlerProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import de.bytefish.pgbulkinsert.exceptions.ValueHandlerAlreadyRegisteredException;
66
import de.bytefish.pgbulkinsert.exceptions.ValueHandlerNotRegisteredException;
77
import de.bytefish.pgbulkinsert.pgsql.constants.DataType;
8+
import de.bytefish.pgbulkinsert.pgsql.handlers.utils.IntervalValueHandler;
89

910
import java.util.EnumMap;
1011
import java.util.Map;
@@ -51,6 +52,7 @@ public ValueHandlerProvider() {
5152
add(DataType.Int8Range, new RangeValueHandler<>(new LongValueHandler<>()));
5253
add(DataType.NumRange, new RangeValueHandler<>(new BigDecimalValueHandler<>()));
5354
add(DataType.DateRange, new RangeValueHandler<>(new LocalDateValueHandler()));
55+
add(DataType.Interval, new IntervalValueHandler());
5456
}
5557

5658
public <TTargetType> ValueHandlerProvider add(DataType targetType, IValueHandler<TTargetType> valueHandler) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
2+
3+
package de.bytefish.pgbulkinsert.pgsql.handlers.utils;
4+
5+
import de.bytefish.pgbulkinsert.pgsql.handlers.BaseValueHandler;
6+
import de.bytefish.pgbulkinsert.pgsql.model.geometric.Box;
7+
import de.bytefish.pgbulkinsert.pgsql.model.interval.Interval;
8+
9+
import java.io.DataOutputStream;
10+
11+
public class IntervalValueHandler extends BaseValueHandler<Interval> {
12+
13+
@Override
14+
protected void internalHandle(DataOutputStream buffer, final Interval value) throws Exception {
15+
buffer.writeInt(16);
16+
17+
buffer.writeLong(value.getTime());
18+
buffer.writeInt(value.getDays());
19+
buffer.writeInt(value.getMonths());
20+
}
21+
22+
@Override
23+
public int getLength(Interval value) {
24+
return 16;
25+
}
26+
}

0 commit comments

Comments
 (0)