Package net.sf.basedb.core
Enum Type
- All Implemented Interfaces:
Serializable
,Comparable<Type>
,java.lang.constant.Constable
public enum Type extends Enum<Type>
This class defines constants for supported value types in BASE.
- Version:
- 2.0
- Author:
- Samuel, Nicklas
- Last modified
- $Date: 2023-11-20 09:28:00 +0100 (Mon, 20 Nov 2023) $
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants Enum Constant Description BOOLEAN
Boolean type.DATE
The parameter is a date value.DOUBLE
Double type.FLOAT
Float type.INT
Integer type.LONG
Long integer type.STRING
String type where maximum length allowed is 255 characters.TEXT
Text blob type.TIMESTAMP
The parameter is a date+time value. -
Field Summary
Fields Modifier and Type Field Description private boolean
canEnumerate
private String
displayValue
private boolean
isNumerical
private boolean
isTemporal
private boolean
isText
private static Map<String,Type>
stringMapping
private String
stringValue
private String
tableName
private TypeWrapper<?>
typeWrapper
private int
value
private Class<?>
valueClass
private static Map<Integer,Type>
valueMapping
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
canEnumerate()
If it makes sense to use values of this type as an enumeration to choose from.Number
convertNumber(Number num)
Convert a number to the appropriate class.static Type
fromHibernateType(Type hibernateType)
Try to find a matching Type instance given a Hibernate Type object.static Type
fromValue(int value)
Get theType
object when you know the integer code.static Type
fromValue(String value)
Get theType
object when you know the string value.int
getSQLType()
Get the type of this parameter as specified by thejava.sql.Types
class.String
getStringValue()
Get the string value representation of this type.String
getTableName()
Get the name of the database table, parameter and annotation values of this value type are stored in.TypeWrapper<?>
getTypeWrapper()
Get a wrapper for accessing underlying type information from Hibernate.int
getValue()
Get the integer value that is used when storing a type in the database.Class<?>
getValueClass()
Get the class of objects that can be used as values for this type.boolean
isCorrectType(Object value)
Check if the value is an object of the correct type.boolean
isNumerical()
If the values of this type are numerical values.boolean
isTemporal()
If the values of this type are date/time related.boolean
isText()
If the values of this type are text values.(package private) abstract ParameterValueData<?>
newParameterValueData()
Create a newParameterValueData
subclass which is used to store values of this value type in the database.abstract Object
parseString(String value)
Parse a string and return a value of the correct type.Object
parseString(String value, NumberFormat numberFormat, boolean nullIfException)
Parse a string and return a value of the correct type using a specific number format for numerical values, optionally ignoring unparsable numbers.Object
parseString(String value, Formatter<Date> dateFormat, boolean nullIfException)
Parse a string and return a value of the correct type using a specific date format for date values, optionally ignoring unparsable dates.Object[]
parseStrings(String[] values)
Parse an array of strings and try to convert them to values of the correct object type.abstract Serializable
readValue(ObjectInputStream in)
Read a value of this type to the input stream.abstract int
sizeOf(Object value)
Get the size in bytes an object of this type requires when stored in the database.String
toString()
void
validate(Object value)
Check if an object is a value of the correct type.void
validate(List<?> values)
Check if a list of values contain only objects of the correct type.static Type
valueOf(String name)
Returns the enum constant of this type with the specified name.static Type[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.abstract void
writeValue(Serializable value, ObjectOutputStream out)
Write a value of this type to the output stream.
-
Enum Constant Details
-
INT
Integer type. -
LONG
Long integer type. -
FLOAT
Float type. -
DOUBLE
Double type. -
STRING
String type where maximum length allowed is 255 characters.- See Also:
TEXT
-
TEXT
Text blob type.- See Also:
STRING
-
BOOLEAN
Boolean type. -
DATE
The parameter is a date value. -
TIMESTAMP
The parameter is a date+time value.- Since:
- 2.16
-
-
Field Details
-
valueMapping
-
stringMapping
-
typeWrapper
-
value
private final int value -
valueClass
-
tableName
-
stringValue
-
displayValue
-
canEnumerate
private final boolean canEnumerate -
isNumerical
private final boolean isNumerical -
isTemporal
private final boolean isTemporal -
isText
private final boolean isText
-
-
Constructor Details
-
Type
private Type(TypeWrapper<?> typeWrapper, int value, Class<?> valueClass, String stringValue, String displayValue, String tableName, boolean canEnumerate, boolean isNumerical, boolean isTemporal, boolean isText)
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
toString
-
getTypeWrapper
Get a wrapper for accessing underlying type information from Hibernate.- Since:
- 2.16
-
getValue
public int getValue()Get the integer value that is used when storing a type in the database.- Returns:
- an int.
-
getValueClass
Get the class of objects that can be used as values for this type.- Returns:
- a Class
- See Also:
isCorrectType(Object)
-
getStringValue
Get the string value representation of this type.- Returns:
- a java.lang.String
-
getSQLType
public int getSQLType()Get the type of this parameter as specified by thejava.sql.Types
class.- Returns:
- The type-code of the parameter
-
getTableName
Get the name of the database table, parameter and annotation values of this value type are stored in.- Since:
- 2.9
-
canEnumerate
public boolean canEnumerate()If it makes sense to use values of this type as an enumeration to choose from. For example, theBOOLEAN
andTEXT
type can't be enumerated.- Returns:
- TRUE if it does, FALSE otherwise.
-
isNumerical
public boolean isNumerical()If the values of this type are numerical values.- Returns:
- TRUE if the values are numerical, FALSE otherwise
-
isTemporal
public boolean isTemporal()If the values of this type are date/time related.- Returns:
- TRUE if the values are temporal, FALSE otherwise
- Since:
- 2.16
-
isText
public boolean isText()If the values of this type are text values.- Returns:
- TRUE if the values are text, FALSE otherwise
- Since:
- 3.19.9
-
validate
Check if an object is a value of the correct type. Null is allowed.- Parameters:
value
- Value object to be checked.- Throws:
InvalidDataException
- If the value isn't of the correct type
-
validate
Check if a list of values contain only objects of the correct type.- Parameters:
values
- List of objects to be checked.- Throws:
InvalidDataException
- If the list contains one or more nulls or values of incorrect object type
-
isCorrectType
Check if the value is an object of the correct type.- Parameters:
value
- Value object to be checked.- Returns:
- TRUE if it is of correct type, FALSE otherwise.
-
newParameterValueData
Create a newParameterValueData
subclass which is used to store values of this value type in the database. -
sizeOf
Get the size in bytes an object of this type requires when stored in the database. If the value is null, 0 is returned, otherwise the actual value is only used if it affects the size, ie. it is a string.- Parameters:
value
- The value to get the size of- Returns:
- an integer
-
writeValue
Write a value of this type to the output stream. Eg. depending on which Type is ised one of ObjectOutputStream.write*(value) methods should be used.- Parameters:
value
- A value which must be of the correct type (not checked)out
- Stream to write to- Throws:
IOException
- Since:
- 3.4
-
readValue
public abstract Serializable readValue(ObjectInputStream in) throws IOException, ClassNotFoundExceptionRead a value of this type to the input stream. Eg. depending on which Type is ised one of ObjectInputStream.read*(value) methods should be used.- Parameters:
in
- Stream to read from- Throws:
IOException
ClassNotFoundException
- Since:
- 3.4
-
convertNumber
Convert a number to the appropriate class. The default implementation returns null. Each numeric type overrides this method to create a number of the correct type.- Parameters:
num
- The number to convert.- Returns:
- Null if this method not have been overridden.
- Since:
- 2.2
-
parseString
Parse a string and return a value of the correct type.- Parameters:
value
- The string to get the type object from.- Returns:
- a java.lang.Object or null if the parameter is null.
- Throws:
InvalidDataException
- If the argument is corrupt.
-
parseString
Parse a string and return a value of the correct type using a specific number format for numerical values, optionally ignoring unparsable numbers.- Parameters:
value
- The string value to parsenumberFormat
- The number format, or null to useparseString(String)
nullIfException
- TRUE to return null for unparsable numeric values, or FALSE to throw an exception- Returns:
- a java.lang.Object, or null.
- Throws:
NumberFormatException
- If the type is numerical and the string can't be parsed as a number and the nullIfException parameter is false- Since:
- 2.4
-
parseString
Parse a string and return a value of the correct type using a specific date format for date values, optionally ignoring unparsable dates.- Parameters:
value
- The string value to parsedateFormat
- The date format, or null to useparseString(String)
nullIfException
- TRUE to return null for unparsable date values, or FALSE to throw an exception- Returns:
- a java.lang.Object, or null.
- Since:
- 3.15
-
parseStrings
Parse an array of strings and try to convert them to values of the correct object type.- Parameters:
values
- An array of values to parse through.- Returns:
- An array of objects, or null of the array is null
- Throws:
InvalidDataException
- If at least one of the strings could not be parsed to the correct type
-
fromValue
Get theType
object when you know the integer code.- Parameters:
value
- The integer code to get the Type object for.- Returns:
- a net.sf.basedb.core.Type object
-
fromValue
Get theType
object when you know the string value.- Parameters:
value
- The string value to get the Type object for.- Returns:
- a net.sf.basedb.core.Type object.
-
fromHibernateType
Try to find a matching Type instance given a Hibernate Type object.- Parameters:
hibernateType
- The Hibernate type- Returns:
- A Type instance or null if not found
- Since:
- 2.15
-