Skip to content

Commit

Permalink
local time support
Browse files Browse the repository at this point in the history
  • Loading branch information
Squiry committed Jul 31, 2023
1 parent 7d40104 commit 5a8b79a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -71,6 +72,11 @@ public class CassandraNativeTypes {
(rsName, i) -> CodeBlock.of("$L.getInstant($L)", rsName, i),
(stmt, var, i) -> CodeBlock.of("$L.setInstant($L, $L)", stmt, i, var)
);
var localTime = CassandraNativeType.of(
TypeName.get(LocalTime.class),
(rsName, i) -> CodeBlock.of("$L.getLocalTime($L)", rsName, i),
(stmt, var, i) -> CodeBlock.of("$L.setLocalTime($L, $L)", stmt, i, var)
);

nativeTypes = List.of(
booleanPrimitive,
Expand All @@ -86,7 +92,8 @@ public class CassandraNativeTypes {
byteBuffer,
localDateTime,
localDate,
instant
instant,
localTime
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ default CassandraRowMapper<ZonedDateTime> zonedDateTimeCassandraRowMapper() {
default CassandraRowMapper<Instant> instantCassandraRowMapper() {
return row -> row.isNull(0)
? null
: row.get(0, Instant.class);
: row.getInstant(0);
}

default CassandraReactiveResultSetMapper<Void, Mono<Void>> voidMonoCassandraReactiveResultSetMapper() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import java.nio.ByteBuffer
import java.time.Instant
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime

object CassandraNativeTypes {
private val nativeTypes = listOf(
Expand Down Expand Up @@ -111,6 +112,16 @@ object CassandraNativeTypes {
{ rsName, i -> CodeBlock.of("%N.getInstant(%L)", rsName, i) },
{ stmt, variableName, idx -> CodeBlock.of("%N.setInstant(%L, %L)", stmt, idx, variableName) },
),
CassandraNativeType.of(
LocalTime::class.asTypeName(),
{ rsName, i -> CodeBlock.of("%N.getLocalTime(%L)", rsName, i) },
{ stmt, variableName, idx -> CodeBlock.of("%N.setLocalTime(%L, %L)", stmt, idx, variableName) },
),
CassandraNativeType.of(
LocalTime::class.asTypeName().copy(true),
{ rsName, i -> CodeBlock.of("%N.getLocalTime(%L)", rsName, i) },
{ stmt, variableName, idx -> CodeBlock.of("%N.setLocalTime(%L, %L)", stmt, idx, variableName) },
),
)

fun findNativeType(typeName: TypeName): CassandraNativeType? {
Expand Down

0 comments on commit 5a8b79a

Please sign in to comment.