Class AbstractDataType<T>

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      int getColumnCount()
      Gets the number of database columns.
      A tentackle type may be mapped to more than one column for multi-column types such as BMoney.
      java.lang.String getColumnGetter​(int index)
      Gets the java getter name of a column.
      java.util.Optional<java.lang.String> getColumnSuffix​(int index)
      Gets the optional suffix.
      Suffixes usually begin with an underscore.
      java.lang.Object getColumnValue​(int index, T value)
      Gets the value of a column.
      java.util.Optional<java.lang.String> getCommentSuffix​(int index)
      Gets the optional comment suffix.
      If present, it will be appended to the comment.
      java.lang.String getDataTypeConstant()
      Gets the name of the datatype constant.
      int getScale​(int index, java.lang.Integer scale)
      Gets the column scale.
      int getSize​(int index, java.lang.Integer size)
      Gets the column size.
      java.lang.String getVariant()
      Gets the optional variant of the type.
      int hashCode()  
      boolean isBool()
      Returns whether this is a boolean or Boolean type.
      boolean isDateOrTime()
      Returns whether this is a date and/or time type.
      boolean isDowncastNecessary()
      For certain numeric types, downcasts are necessary when assigning literals.
      boolean isJavaTypeGenerified()
      Returns whether the inner type describes a generified java type.
      Implies DataType.isModelProvidingInnerType().
      boolean isLiteralSupported()
      Returns whether this type can be used literally in a query String.
      boolean isMapNullSupported()
      Returns whether this type supports mapping null values to some well-defined constant.
      boolean isModelProvidingInnerType()
      Returns whether the model provides an inner type.
      boolean isMutable()
      Returns whether type is a mutable java object.
      Mutable objects may change their state and must implement Freezable.
      boolean isNumeric()
      Returns whether this is a numeric type.
      boolean isPredefined()
      Returns whether this is a predefined type.
      boolean isPrimitive()
      Returns whether type is a primitive.
      boolean isUTCSupported()
      Returns whether this type supports the UTC option.
      java.lang.Object set​(Backend backend, java.sql.PreparedStatement statement, int pos, T object, int index, boolean mapNull, java.lang.Integer size)
      Sets a column of an object into a prepared statement.
      Must be implemented if DataType.isPredefined() returns false.
      java.lang.String toLiteral​(java.lang.String str)
      Takes the string representation of a value and converts it to an SQL literal.
      Some types need single quotes, for example.
      DataType<?> toNonPrimitive()
      Gets the non-primitive type if this is a primitive.
      java.util.Optional<DataType<?>> toPrimitive()
      Gets the primitive type if this is a non-primitive.
      java.lang.String toString()  
      java.lang.String toString​(T object)
      Takes an object and converts it to a string that can in turn be parsed with DataType.valueOf(String).
      The method is used to print a literal (for example the default value of a dumped attribute).
      java.lang.String valueOfLiteralToCode​(java.lang.String str)
      Creates the java code to apply the valueOf method to a String.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • AbstractDataType

        public AbstractDataType()
    • Method Detail

      • isPredefined

        public boolean isPredefined()
        Description copied from interface: DataType
        Returns whether this is a predefined type.
        Specified by:
        isPredefined in interface DataType<T>
        Returns:
        true if explicit methods provided by the persistence layer, false if generic methods must be used
      • getVariant

        public java.lang.String getVariant()
        Description copied from interface: DataType
        Gets the optional variant of the type.
        Specified by:
        getVariant in interface DataType<T>
        Returns:
        the variant, empty string if none, never null
      • getColumnCount

        public int getColumnCount()
        Description copied from interface: DataType
        Gets the number of database columns.
        A tentackle type may be mapped to more than one column for multi-column types such as BMoney.
        Specified by:
        getColumnCount in interface DataType<T>
        Returns:
        default is 1
      • getColumnSuffix

        public java.util.Optional<java.lang.String> getColumnSuffix​(int index)
        Description copied from interface: DataType
        Gets the optional suffix.
        Suffixes usually begin with an underscore.
        Specified by:
        getColumnSuffix in interface DataType<T>
        Parameters:
        index - the column index
        Returns:
        the optional suffix
      • getCommentSuffix

        public java.util.Optional<java.lang.String> getCommentSuffix​(int index)
        Description copied from interface: DataType
        Gets the optional comment suffix.
        If present, it will be appended to the comment.

        Important: for datatypes with more than one column, none or exactly one should be without suffix. See WurbletArgument in tentackle-wurblets.

        Specified by:
        getCommentSuffix in interface DataType<T>
        Parameters:
        index - the column index
        Returns:
        the optional suffix
      • getSize

        public int getSize​(int index,
                           java.lang.Integer size)
        Description copied from interface: DataType
        Gets the column size.
        Specified by:
        getSize in interface DataType<T>
        Parameters:
        index - the column index
        size - the size from the model
        Returns:
        the column size
      • getScale

        public int getScale​(int index,
                            java.lang.Integer scale)
        Description copied from interface: DataType
        Gets the column scale.
        Specified by:
        getScale in interface DataType<T>
        Parameters:
        index - the column index
        scale - the scale from the model
        Returns:
        the column scale
      • getColumnValue

        public java.lang.Object getColumnValue​(int index,
                                               T value)
        Description copied from interface: DataType
        Gets the value of a column.
        Specified by:
        getColumnValue in interface DataType<T>
        Parameters:
        index - the column index
        value - the datatype's value according to the model
        Returns:
        the column's value
      • getColumnGetter

        public java.lang.String getColumnGetter​(int index)
        Description copied from interface: DataType
        Gets the java getter name of a column.
        Specified by:
        getColumnGetter in interface DataType<T>
        Parameters:
        index - the datatype's value according to the model
        Returns:
        the column's getter name, empty string if this is a single column type
      • isPrimitive

        public boolean isPrimitive()
        Description copied from interface: DataType
        Returns whether type is a primitive.
        Specified by:
        isPrimitive in interface DataType<T>
        Returns:
        true if primitive
      • toNonPrimitive

        public DataType<?> toNonPrimitive()
        Description copied from interface: DataType
        Gets the non-primitive type if this is a primitive.
        Specified by:
        toNonPrimitive in interface DataType<T>
        Returns:
        the non-primitive type, this type if it is already a non-primitive
      • toPrimitive

        public java.util.Optional<DataType<?>> toPrimitive()
        Description copied from interface: DataType
        Gets the primitive type if this is a non-primitive.
        Specified by:
        toPrimitive in interface DataType<T>
        Returns:
        the primitive type if there is one
      • isMutable

        public boolean isMutable()
        Description copied from interface: DataType
        Returns whether type is a mutable java object.
        Mutable objects may change their state and must implement Freezable.
        Specified by:
        isMutable in interface DataType<T>
        Returns:
        true if mutable and freezable
      • isNumeric

        public boolean isNumeric()
        Description copied from interface: DataType
        Returns whether this is a numeric type.
        Specified by:
        isNumeric in interface DataType<T>
        Returns:
        true if numeric
      • isDateOrTime

        public boolean isDateOrTime()
        Description copied from interface: DataType
        Returns whether this is a date and/or time type.
        Specified by:
        isDateOrTime in interface DataType<T>
        Returns:
        true if time, date or timestamp
      • isBool

        public boolean isBool()
        Description copied from interface: DataType
        Returns whether this is a boolean or Boolean type.
        Specified by:
        isBool in interface DataType<T>
        Returns:
        true if bool
      • isMapNullSupported

        public boolean isMapNullSupported()
        Description copied from interface: DataType
        Returns whether this type supports mapping null values to some well-defined constant.
        Specified by:
        isMapNullSupported in interface DataType<T>
        Returns:
        true if mapNull supported
      • isUTCSupported

        public boolean isUTCSupported()
        Description copied from interface: DataType
        Returns whether this type supports the UTC option.
        Specified by:
        isUTCSupported in interface DataType<T>
        Returns:
        true if UTC supported
      • isModelProvidingInnerType

        public boolean isModelProvidingInnerType()
        Description copied from interface: DataType
        Returns whether the model provides an inner type.
        Specified by:
        isModelProvidingInnerType in interface DataType<T>
        Returns:
        true if inner type is specified within angle brackets, false if standard type
      • isDowncastNecessary

        public boolean isDowncastNecessary()
        Description copied from interface: DataType
        For certain numeric types, downcasts are necessary when assigning literals.
        Specified by:
        isDowncastNecessary in interface DataType<T>
        Returns:
        true if downcast is necessary
      • isLiteralSupported

        public boolean isLiteralSupported()
        Description copied from interface: DataType
        Returns whether this type can be used literally in a query String.
        Specified by:
        isLiteralSupported in interface DataType<T>
        Returns:
        true if literal String supported, else false
      • toLiteral

        public java.lang.String toLiteral​(java.lang.String str)
        Description copied from interface: DataType
        Takes the string representation of a value and converts it to an SQL literal.
        Some types need single quotes, for example.
        Specified by:
        toLiteral in interface DataType<T>
        Parameters:
        str - the value string
        Returns:
        the SQL literal
      • valueOfLiteralToCode

        public java.lang.String valueOfLiteralToCode​(java.lang.String str)
        Description copied from interface: DataType
        Creates the java code to apply the valueOf method to a String.
        Specified by:
        valueOfLiteralToCode in interface DataType<T>
        Parameters:
        str - the literal to be parsed
        Returns:
        the java code
      • toString

        public java.lang.String toString​(T object)
        Description copied from interface: DataType
        Takes an object and converts it to a string that can in turn be parsed with DataType.valueOf(String).
        The method is used to print a literal (for example the default value of a dumped attribute).

        Notice: the method doesn't use any locale, so the results are always the same regardless of the JVM's locale.

        Specified by:
        toString in interface DataType<T>
        Parameters:
        object - the object of this DataType
        Returns:
        the printable string
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getDataTypeConstant

        public java.lang.String getDataTypeConstant()
        Description copied from interface: DataType
        Gets the name of the datatype constant.
        Specified by:
        getDataTypeConstant in interface DataType<T>
        Returns:
        the DT_...
      • set

        public java.lang.Object set​(Backend backend,
                                    java.sql.PreparedStatement statement,
                                    int pos,
                                    T object,
                                    int index,
                                    boolean mapNull,
                                    java.lang.Integer size)
                             throws java.sql.SQLException
        Description copied from interface: DataType
        Sets a column of an object into a prepared statement.
        Must be implemented if DataType.isPredefined() returns false. Not invoked by framework otherwise.
        Specified by:
        set in interface DataType<T>
        Parameters:
        backend - the database backend
        statement - the prepared statement
        pos - the position of the first SQL value
        object - the object, may be null
        index - the column index
        mapNull - true if map null-values to non-null values
        size - the optional size specified in the model
        Returns:
        the object stored in the prepared statement
        Throws:
        java.sql.SQLException - if failed
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object