Skip to content

Commit 19bcaa2

Browse files
committed
Update Instant handling.
1 parent f901f83 commit 19bcaa2

6 files changed

Lines changed: 9 additions & 16 deletions

File tree

.idea/dataSources.xml

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ The `WebServiceProxy` class is used to submit API requests to a server. It provi
355355
public WebServiceProxy(String method, URI uri) { ... }
356356
```
357357

358-
Query arguments are specified via a map passed to the `setArguments()` method. Any value may be used as an argument and will generally be encoded using its string representation. However, `Date` and `Instant` instances are first converted to a long value representing epoch time in milliseconds. Additionally, `Collection` or array instances represent multi-value parameters and behave similarly to `<select multiple>` tags in HTML forms.
358+
Query arguments are specified via a map passed to the `setArguments()` method. Any value may be used as an argument and will generally be encoded using its string representation. However, `Date` instances are first converted to a long value representing epoch time in milliseconds. Additionally, `Collection` or array instances represent multi-value parameters and behave similarly to `<select multiple>` tags in HTML forms.
359359

360360
Body content is specified via the `setBody()` method. By default, it will be serialized as JSON; however, the `setRequestHandler()` method can be used to facilitate alternate encodings:
361361

@@ -771,7 +771,6 @@ Temporal values (such as "birth" and "death" above) are automatically converted
771771

772772
* `java.sql.Date`/`LocalDate`
773773
* `java.sql.Time`/`LocalTime`
774-
* `java.sql.Timestamp`/`Instant`
775774

776775
### Schema Annotations
777776
`QueryBuilder` also offers a simplified approach to query construction using "schema annotations". For example, given these type definitions:

kilo-client/src/main/java/org/httprpc/kilo/WebServiceProxy.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import java.nio.charset.StandardCharsets;
4747
import java.nio.file.Files;
4848
import java.nio.file.Path;
49-
import java.time.Instant;
5049
import java.util.ArrayList;
5150
import java.util.Arrays;
5251
import java.util.Collection;
@@ -913,8 +912,6 @@ private static List<Object> getParameterValues(Object argument) {
913912
private static Object getParameterValue(Object argument) {
914913
if (argument instanceof Date date) {
915914
return date.getTime();
916-
} else if (argument instanceof Instant instant) {
917-
return instant.toEpochMilli();
918915
} else {
919916
return argument;
920917
}

kilo-client/src/main/java/org/httprpc/kilo/sql/QueryBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,9 @@ public ResultSetAdapter executeQuery(PreparedStatement statement) throws SQLExce
13761376
* Temporal values are converted as follows:
13771377
* <p>
13781378
* <ul>
1379-
* <li>{@link Date} - long value representing epoch time in milliseconds</li>
1379+
* <li>{@link Date} or {@link Instant} - long value representing epoch time in milliseconds</li>
13801380
* <li>{@link LocalDate} - {@link java.sql.Date}</li>
13811381
* <li>{@link LocalTime} - {@link java.sql.Time}</li>
1382-
* <li>{@link Instant} - {@link java.sql.Timestamp}</li>
13831382
* </ul>
13841383
* <p>
13851384
* All other arguments are applied as is.
@@ -1514,9 +1513,9 @@ private void apply(PreparedStatement statement, Map<String, ?> arguments) throws
15141513
} else {
15151514
switch (argument) {
15161515
case Date date -> value = date.getTime();
1516+
case Instant instant -> value = instant.toEpochMilli();
15171517
case LocalDate localDate -> value = java.sql.Date.valueOf(localDate);
15181518
case LocalTime localTime -> value = java.sql.Time.valueOf(localTime);
1519-
case Instant instant -> value = java.sql.Timestamp.from(instant);
15201519
case null, default -> {
15211520
var transform = transforms.get(parameter);
15221521

kilo-test/src/test/resources/org/httprpc/kilo/test/catalog.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@
301301
"iterable": false,
302302
"keyType": null,
303303
"map": false,
304-
"name": "Date",
304+
"name": "Instant",
305305
"valueType": null
306306
}
307307
},

kilo-test/src/test/resources/org/httprpc/kilo/test/test.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
"iterable": false,
147147
"keyType": null,
148148
"map": false,
149-
"name": "Date",
149+
"name": "Long",
150150
"valueType": null
151151
}
152152
},
@@ -161,7 +161,7 @@
161161
"iterable": false,
162162
"keyType": null,
163163
"map": false,
164-
"name": "Date",
164+
"name": "Long",
165165
"valueType": null
166166
},
167167
"intrinsic": true,
@@ -1099,7 +1099,7 @@
10991099
"iterable": false,
11001100
"keyType": null,
11011101
"map": false,
1102-
"name": "Date",
1102+
"name": "Long",
11031103
"valueType": null
11041104
}
11051105
},
@@ -2133,7 +2133,7 @@
21332133
"iterable": false,
21342134
"keyType": null,
21352135
"map": false,
2136-
"name": "Date",
2136+
"name": "Long",
21372137
"valueType": null
21382138
}
21392139
},
@@ -2149,7 +2149,7 @@
21492149
"iterable": false,
21502150
"keyType": null,
21512151
"map": false,
2152-
"name": "Date",
2152+
"name": "Long",
21532153
"valueType": null
21542154
},
21552155
"intrinsic": true,

0 commit comments

Comments
 (0)