Package tenapull.data.persistence
Class MultiTypeWrapper
java.lang.Object
tenapull.data.persistence.MultiTypeWrapper
public final class MultiTypeWrapper
extends java.lang.Object
Used to represent a field which may have multiple JSON primitive data types. When
entering into the DB, a varchar(255) field is used where the first character represents
the primary data type and the remaining characters represent the value.
The "primary type" refers to the type used -- e.g. an AtomicInteger may be grouped
with an Integer, etc
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MultiTypeWrapper.Converter
Hibernate converter, for converting between a string for the DB and a MultiTypeWrapper instance -
Field Summary
Fields Modifier and Type Field Description static java.util.List<java.lang.Class>
BIGDECIMAL_TYPES
The constant BIGDECIMAL_TYPES.static java.util.List<java.lang.Class>
BIGINT_TYPES
The constant BIGINT_TYPES.static java.util.List<java.lang.Class>
BOOLEAN_TYPES
The constant BOOLEAN_TYPES.static java.util.List<java.lang.Class>
BYTE_TYPES
The constant BYTE_TYPES.static java.util.List<java.lang.Class>
DOUBLE_TYPES
The constant DOUBLE_TYPES.static java.util.List<java.lang.Class>
FLOAT_TYPES
The constant FLOAT_TYPES.static java.util.List<java.lang.Class>
INT_TYPES
The constant INT_TYPES.static java.util.List<java.lang.Class>
LONG_TYPES
The constant LONG_TYPES.static java.lang.String
MISSING_TYPE
The MISSING_TYPE error stringstatic java.lang.String
MISSING_VALUE
The MISSING_VALUE error stringstatic java.lang.String
NULL_TYPE
The NULL_TYPE error messagestatic java.lang.String
NULL_TYPE_STRING
The NULL_TYPE_STRING error messagestatic java.lang.String
NULL_VALUE
The NULL_VALUE error messagestatic java.util.List<java.lang.Class>
SHORT_TYPES
The constant SHORT_TYPES.static java.util.List<java.lang.Class>
STRING_TYPES
The constant STRING_TYPES.static java.util.Map<java.lang.Character,java.util.List<java.lang.Class>>
TYPE_MAP
The map of types, with their type-character prefix as the key.static char
UNKNOWN
The constant UNKNOWN, used as the data type prefix for Objects of a type not represented by the defined "primary types" -
Method Summary
Modifier and Type Method Description static MultiTypeWrapper
buildFrom(java.lang.String dbString)
Build a MultiTypeWrapper from the provided dbString, or provide an already-constructed one if it already existsstatic void
clearInstances()
Clear instances by replacing the instances trackers.boolean
equals(java.lang.Object o)
static long
getCounter()
Gets the number of instances constructed total, including ones which may have been GC'djava.lang.Object
getObject()
Gets the value which the MultiTypeWrapper is wrappingjava.lang.Class
getPrimaryType()
Gets primary type for a MultiTypeWrapperstatic java.lang.Class
getPrimaryType(java.lang.Object object)
Gets the primary type of a provided objectstatic java.util.Map.Entry<java.lang.Character,java.lang.Class>
getPrimaryTypeWithChar(java.lang.Object object)
Gets the primary type based on the character prefix from the DBjava.lang.String
getTypeString()
Gets type string for a MultiTypeWrapperint
hashCode()
static java.lang.String
makeDbStringFor(java.lang.Object object)
Make the MultiTypeWrapper db string for a provided objectstatic void
resetCounter()
Reset the counter.static int
size()
Returns the size of the MultiTypeWrapper's instances tracker (aka, the number of viable instances of MultiTypeWrapper currently in working memory)java.lang.String
toDb()
Gets the db string for a MultiTypeWrapperjava.lang.String
toString()
static MultiTypeWrapper
wrap(java.lang.Object object)
Creates a multi-type wrapper for the provided object (or an unequivilent in its primary type or returns an already existing one which represents an equivalent value of its primary type.
-
Field Details
-
UNKNOWN
public static char UNKNOWNThe constant UNKNOWN, used as the data type prefix for Objects of a type not represented by the defined "primary types" -
STRING_TYPES
public static final java.util.List<java.lang.Class> STRING_TYPESThe constant STRING_TYPES. -
INT_TYPES
public static final java.util.List<java.lang.Class> INT_TYPESThe constant INT_TYPES. -
BOOLEAN_TYPES
public static final java.util.List<java.lang.Class> BOOLEAN_TYPESThe constant BOOLEAN_TYPES. -
DOUBLE_TYPES
public static final java.util.List<java.lang.Class> DOUBLE_TYPESThe constant DOUBLE_TYPES. -
LONG_TYPES
public static final java.util.List<java.lang.Class> LONG_TYPESThe constant LONG_TYPES. -
BYTE_TYPES
public static final java.util.List<java.lang.Class> BYTE_TYPESThe constant BYTE_TYPES. -
SHORT_TYPES
public static final java.util.List<java.lang.Class> SHORT_TYPESThe constant SHORT_TYPES. -
FLOAT_TYPES
public static final java.util.List<java.lang.Class> FLOAT_TYPESThe constant FLOAT_TYPES. -
BIGINT_TYPES
public static final java.util.List<java.lang.Class> BIGINT_TYPESThe constant BIGINT_TYPES. -
BIGDECIMAL_TYPES
public static final java.util.List<java.lang.Class> BIGDECIMAL_TYPESThe constant BIGDECIMAL_TYPES. -
TYPE_MAP
public static final java.util.Map<java.lang.Character,java.util.List<java.lang.Class>> TYPE_MAPThe map of types, with their type-character prefix as the key. The first class in each list is the "Primary type", that will be used when instantiating entities from DB varchar values. Character == first character of DB varchar value, to indicate the type of the subsequent string All primary types MUST have a single-argument String constructor -
NULL_VALUE
public static final java.lang.String NULL_VALUEThe NULL_VALUE error message -
NULL_TYPE
public static final java.lang.String NULL_TYPEThe NULL_TYPE error message -
NULL_TYPE_STRING
public static final java.lang.String NULL_TYPE_STRINGThe NULL_TYPE_STRING error message -
MISSING_TYPE
public static final java.lang.String MISSING_TYPEThe MISSING_TYPE error string -
MISSING_VALUE
public static final java.lang.String MISSING_VALUEThe MISSING_VALUE error string
-
-
Method Details
-
wrap
Creates a multi-type wrapper for the provided object (or an unequivilent in its primary type or returns an already existing one which represents an equivalent value of its primary type.- Parameters:
object
- the object needing a MultiTypeWrapper representation- Returns:
- the multi type wrapper representing the passed value
-
buildFrom
Build a MultiTypeWrapper from the provided dbString, or provide an already-constructed one if it already exists- Parameters:
dbString
- the db string- Returns:
- the multi type wrapper
-
size
public static int size()Returns the size of the MultiTypeWrapper's instances tracker (aka, the number of viable instances of MultiTypeWrapper currently in working memory)- Returns:
- the int
-
getCounter
public static long getCounter()Gets the number of instances constructed total, including ones which may have been GC'd- Returns:
- the counter
-
resetCounter
public static void resetCounter()Reset the counter. Used mostly for benchamrking and testing -
clearInstances
public static void clearInstances()Clear instances by replacing the instances trackers. Used mostly for benchmarking and testing -
getPrimaryType
public static java.lang.Class getPrimaryType(java.lang.Object object)Gets the primary type of a provided object- Parameters:
object
- the object- Returns:
- the primary type
-
getPrimaryTypeWithChar
public static java.util.Map.Entry<java.lang.Character,java.lang.Class> getPrimaryTypeWithChar(java.lang.Object object)Gets the primary type based on the character prefix from the DB- Parameters:
object
- the object- Returns:
- the primary type with char
-
makeDbStringFor
public static java.lang.String makeDbStringFor(java.lang.Object object)Make the MultiTypeWrapper db string for a provided object- Parameters:
object
- the object- Returns:
- the db string
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
getTypeString
public java.lang.String getTypeString()Gets type string for a MultiTypeWrapper- Returns:
- the type string
-
getPrimaryType
public java.lang.Class getPrimaryType()Gets primary type for a MultiTypeWrapper- Returns:
- the primary type
-
toDb
public java.lang.String toDb()Gets the db string for a MultiTypeWrapper- Returns:
- the string
-
getObject
public java.lang.Object getObject()Gets the value which the MultiTypeWrapper is wrapping- Returns:
- the object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equals
in classjava.lang.Object
-