Skip to content

Commit

Permalink
Jakarta Persistence 3.2: java.time.Instant and java.time.Year - minor…
Browse files Browse the repository at this point in the history
… fixes (#2081)

* Jakarta Persistence 3.2: java.time.Instant and java.time.Year - minor fixes

Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
  • Loading branch information
rfelcman committed Feb 29, 2024
1 parent 0acf479 commit 5ffbbc9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2684,7 +2684,7 @@ public int appendParameterInternal(Call call, Writer writer, Object parameter) {
java.sql.Timestamp ts = java.sql.Timestamp.valueOf(java.time.LocalDateTime.of(java.time.LocalDate.ofEpochDay(0), ot.toLocalTime()));
appendTimestamp(ts, writer);
} else if (dbValue instanceof java.time.Year){
appendNumber((Number)dbValue, writer);
appendNumber(((java.time.Year) dbValue).getValue(), writer);
} else if (dbValue instanceof java.sql.Date) {
appendDate((java.sql.Date)dbValue, writer);
} else if (dbValue == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,7 @@ protected java.time.Year convertObjectToYear(Object sourceObject) throws Convers
try {
year = java.time.Year.of(Integer.valueOf((String) sourceObject));
} catch (Exception e) {
year = java.time.Year.parse(((String) sourceObject).replace(' ', 'T'), Helper.getDefaultDateTimeFormatter());
java.time.LocalTime localTime = java.time.LocalTime.parse(((String) sourceObject).replace(' ', 'T'), Helper.getDefaultDateTimeFormatter());
throw ConversionException.couldNotBeConverted(sourceObject, ClassConstants.TIME_YEAR);
}
} else if (sourceObject instanceof java.util.Date) {
// handles sql.Time, sql.Date, sql.Timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ public void timeConvertLongToYear() {
}

@Test
public void timeConvertYearToException() {
public void timeConvertYearToExceptionWrongInputString() {
String date = "Bogus";

try {
Expand All @@ -639,4 +639,16 @@ public void timeConvertYearToException() {
// Expected
}
}

@Test
public void timeConvertYearToExceptionWrongInputType() {
Boolean inputValue = true;

try {
Year year = cm.convertObject(inputValue, ClassConstants.TIME_YEAR);
Assert.fail("Expected Exception was not thrown.");
} catch (ConversionException ce) {
// Expected
}
}
}

0 comments on commit 5ffbbc9

Please sign in to comment.