Fixed handling of java.sql.Date field type

This commit is contained in:
Francesco 2023-10-27 12:15:17 +02:00
parent c205e4948c
commit ad95f2434c
3 changed files with 14 additions and 9 deletions

View File

@ -496,6 +496,7 @@ public class DefaultDbAdminController {
attr.addFlashAttribute("validationErrors", new ValidationErrorsContainer(e));
attr.addFlashAttribute("params", params);
} catch (DbAdminException e) {
e.getCause().printStackTrace();
attr.addFlashAttribute("errorTitle", "Error");
attr.addFlashAttribute("error", e.getMessage());
attr.addFlashAttribute("params", params);

View File

@ -386,7 +386,10 @@ public class DbObjectSchema {
Object parsedFieldValue =
getFieldByName(param).getType().parseValue(params.get(param));
System.out.println(param);
System.out.println(parsedFieldValue);
if (parsedFieldValue != null)
System.out.println(parsedFieldValue.getClass());
if (parsedFieldValue != null && getFieldByName(param).isSettable()) {
setter.invoke(instance, parsedFieldValue);
}

View File

@ -18,13 +18,13 @@
package tech.ailef.dbadmin.external.dbmapping.fields;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.sql.Date;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.Locale;
import tech.ailef.dbadmin.external.dto.CompareOperator;
import tech.ailef.dbadmin.external.exceptions.DbAdminException;
public class DateFieldType extends DbFieldType {
@Override
@ -35,11 +35,12 @@ public class DateFieldType extends DbFieldType {
@Override
public Object parseValue(Object value) {
if (value == null || value.toString().isBlank()) return null;
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH);
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
try {
return format.parse(value.toString());
} catch (ParseException e) {
throw new RuntimeException(e);
LocalDate localDate = LocalDate.parse(value.toString());
return Date.valueOf(localDate);
} catch (DateTimeParseException e) {
throw new DbAdminException("Invalid date " + value, e);
}
}