Support for UUID type (#13)

This commit is contained in:
Francesco 2023-10-11 14:40:21 +02:00
parent 3452eae52b
commit 30384b7381
2 changed files with 30 additions and 2 deletions

View File

@ -252,7 +252,9 @@ public class DefaultDbAdminController {
public String show(Model model, @PathVariable String className, @PathVariable String id) { public String show(Model model, @PathVariable String className, @PathVariable String id) {
DbObjectSchema schema = dbAdmin.findSchemaByClassName(className); DbObjectSchema schema = dbAdmin.findSchemaByClassName(className);
DbObject object = repository.findById(schema, id).orElseThrow(() -> { Object pkValue = schema.getPrimaryKey().getType().parseValue(id);
DbObject object = repository.findById(schema, pkValue).orElseThrow(() -> {
return new DbAdminNotFoundException( return new DbAdminNotFoundException(
schema.getJavaClass().getSimpleName() + " with ID " + id + " not found." schema.getJavaClass().getSimpleName() + " with ID " + id + " not found."
); );

View File

@ -38,6 +38,7 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne; import jakarta.persistence.OneToOne;
import tech.ailef.dbadmin.external.dto.CompareOperator; import tech.ailef.dbadmin.external.dto.CompareOperator;
import tech.ailef.dbadmin.external.exceptions.DbAdminException; import tech.ailef.dbadmin.external.exceptions.DbAdminException;
import tech.ailef.dbadmin.external.exceptions.UnsupportedFieldTypeException;
/** /**
* The enum for supported database field types. * The enum for supported database field types.
@ -429,6 +430,29 @@ public enum DbFieldType {
throw new DbAdminException("Binary fields are not comparable"); throw new DbAdminException("Binary fields are not comparable");
} }
}, },
UUID {
@Override
public String getFragmentName() {
return "text";
}
@Override
public Object parseValue(Object value) {
return java.util.UUID.fromString(value.toString());
}
@Override
public Class<?> getJavaClass() {
return java.util.UUID.class;
}
@Override
public List<CompareOperator> getCompareOperators() {
return List.of(CompareOperator.STRING_EQ, CompareOperator.CONTAINS);
}
},
ONE_TO_MANY { ONE_TO_MANY {
@Override @Override
public String getFragmentName() { public String getFragmentName() {
@ -609,10 +633,12 @@ public enum DbFieldType {
return OFFSET_DATE_TIME; return OFFSET_DATE_TIME;
} else if (klass == byte.class || klass == Byte.class) { } else if (klass == byte.class || klass == Byte.class) {
return BYTE; return BYTE;
} else if (klass == java.util.UUID.class) {
return UUID;
} else if (klass == char.class || klass == Character.class) { } else if (klass == char.class || klass == Character.class) {
return CHAR; return CHAR;
} else { } else {
throw new DbAdminException("Unsupported field type: " + klass); throw new UnsupportedFieldTypeException("Unsupported field type: " + klass);
} }
} }
} }