mirror of
https://github.com/dalbodeule/snap-admin.git
synced 2025-06-09 05:48:20 +00:00
Support for UUID type (#13)
This commit is contained in:
parent
3452eae52b
commit
30384b7381
@ -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."
|
||||||
);
|
);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user