Skip to content

Commit e9388f1

Browse files
committed
Issue #91 Start implementation by adding a ValueConverter
1 parent bcdb58c commit e9388f1

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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;
4+
5+
import de.bytefish.pgbulkinsert.pgsql.converter.IValueConverter;
6+
import de.bytefish.pgbulkinsert.pgsql.converter.LocalDateTimeConverter;
7+
8+
import java.io.DataOutputStream;
9+
import java.sql.Timestamp;
10+
import java.time.LocalDateTime;
11+
12+
public class TimestampValueHandler extends BaseValueHandler<Timestamp> {
13+
14+
private IValueConverter<LocalDateTime, Long> dateTimeConverter;
15+
16+
public TimestampValueHandler() {
17+
this(new LocalDateTimeConverter());
18+
}
19+
20+
public TimestampValueHandler(IValueConverter<LocalDateTime, Long> dateTimeConverter) {
21+
this.dateTimeConverter = dateTimeConverter;
22+
}
23+
24+
@Override
25+
protected void internalHandle(DataOutputStream buffer, final Timestamp value) throws Exception {
26+
buffer.writeInt(8);
27+
buffer.writeLong(dateTimeConverter.convert(value.toLocalDateTime()));
28+
}
29+
30+
@Override
31+
public int getLength(Timestamp value) {
32+
return 8;
33+
}
34+
}

0 commit comments

Comments
 (0)