java.lang.Object
com.aoindustries.aoserv.client.DbEnum
A registry of converters from Java
Enum to/from the underlying PostgreSQL enum value.
All enum types used for implementations of Type.ENUM must be registered.- Author:
- AO Industries, Inc.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDbEnum.FromDbValue<E extends Enum<?>>static interfaceDbEnum.ToDbValue<E extends Enum<?>> -
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends Enum<?>>
EfromDbValue(Class<E> enumClass, String dbValue) Maps a database value to the matchingEnum.static <E extends Enum<?>>
voidRegisters a new type with defaultDbEnum.ToDbValueofEnum.name()andDbEnum.FromDbValueofEnum.valueOf(java.lang.Class, java.lang.String).static <E extends Enum<?>>
voidregister(Class<E> enumClass, DbEnum.ToDbValue<E> toDbValue, DbEnum.FromDbValue<E> fromDbValue) Registers a new type with providedDbEnum.ToDbValueandDbEnum.FromDbValue.toDbValue(E value) Maps anEnumvalue to the matching database value.
-
Method Details
-
register
public static <E extends Enum<?>> void register(Class<E> enumClass, DbEnum.ToDbValue<E> toDbValue, DbEnum.FromDbValue<E> fromDbValue) Registers a new type with providedDbEnum.ToDbValueandDbEnum.FromDbValue. -
register
Registers a new type with defaultDbEnum.ToDbValueofEnum.name()andDbEnum.FromDbValueofEnum.valueOf(java.lang.Class, java.lang.String). -
toDbValue
Maps anEnumvalue to the matching database value.This does not directly match the value from the database, but will match the underlying database value at the time of this client schema version. In other words, the underlying database may change, but this value will stay constant within a single schema version.
- Parameters:
value- The Java enum value, may benull- Returns:
- The Java enum value corresponding to the give database value or
nullwhendbValue == null. - Throws:
IllegalStateException- ifDbEnum.ToDbValuenot registered orDbEnum.ToDbValuereturns unexpectednull
-
fromDbValue
public static <E extends Enum<?>> E fromDbValue(Class<E> enumClass, String dbValue) throws IllegalStateException, IllegalArgumentException Maps a database value to the matchingEnum.This does not directly match the value from the database, but will match the underlying database value at the time of this client schema version. In other words, the underlying database may change, but this value will stay constant within a single schema version.
- Parameters:
dbValue- The database value, may benull- Returns:
- The Java enum value corresponding to the give database value or
nullwhendbValue == null. - Throws:
IllegalStateException- ifDbEnum.FromDbValuenot registered orDbEnum.FromDbValuereturns unexpectednullIllegalArgumentException- when unable to map the database value to theEnum.
-
