Class DefaultValue


  • public final class DefaultValue
    extends java.lang.Object
    Represents a default value for a field. Essentially this is a wrapper around the actual value, as in some special cases the database can define "magical" values such as "sysdate" which are not parseable as valid values.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static DefaultValue create​(java.lang.Object value)
      This method is the simplest way for creating new DefaultValue instance.
      static DefaultValue create​(java.lang.String[] stringValues, java.lang.Object convertedValue)
      Create a non-null default value.
      static DefaultValue create​(java.lang.String stringValue, java.lang.Object convertedValue)
      Create a non-null default value for single-column field.
      static DefaultValue createForString​(java.lang.String str)
      Create an instance of DefaultValue for String.
      static DefaultValue createNull​(int columnsCount)
      Create DefaultValue instance for NULL.
      boolean equals​(java.lang.Object obj)  
      java.lang.Object getConvertedValue()  
      java.lang.String[] getStringValues()
      The JDBC derived defaults for each column used by the field.
      int hashCode()  
      boolean isNull()  
      static DefaultValue parse​(java.lang.String stringValue, DFDataConvertor convertor)
      Try to parse from string representation (created e.g.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • getConvertedValue

        public java.lang.Object getConvertedValue()
        Returns:
        The converted value, if there is one. Can return null if it's either special value or if its DEFAULT_NULL.
      • getStringValues

        public java.lang.String[] getStringValues()
        The JDBC derived defaults for each column used by the field. Typically a field represents a single column so then the array contains only a single String. Can return null if this is DEFAULT_NULL instance.
        Returns:
        The String values of the column defaults
      • createNull

        public static DefaultValue createNull​(int columnsCount)
        Create DefaultValue instance for NULL. It's necessary to specify number of columns, because getStringValues() of this new instance will return array of this length (all values in the array will be null).
        Parameters:
        columnsCount -
        Returns:
        The default value instance
      • createForString

        public static DefaultValue createForString​(java.lang.String str)
        Create an instance of DefaultValue for String. If the parameter is null or it's string with length 0 then it's delegated to createNull(int).
        Parameters:
        str -
        Returns:
        The default value instance
      • create

        public static DefaultValue create​(java.lang.Object value)
        This method is the simplest way for creating new DefaultValue instance. If you have an original value e.g. Integer(100), Date instance, etc. you can create DefaultValue from this object directly.

        This method can be used only for single-column fields. getStringValues() method of returned instance will return String[1] where the only element will be created using value.toString()

        Parameters:
        value - The original object in Field's own specific format. Null is allowed.
        Returns:
        The new DefaultValue instance
      • create

        public static DefaultValue create​(java.lang.String stringValue,
                                          java.lang.Object convertedValue)
        Create a non-null default value for single-column field. If you want to create default value for NULL plesase use createNull(int) instead.
        Parameters:
        stringValue - This is the original default value from the database. Null is not allowed.
        convertedValue - Converted value can be specified, but it's not required. You can pass null here. Then the special DefaultValue is created - for example if default value is SYSDATE on Oracle, etc.
        Returns:
        The new instance of DefaultValue
      • create

        public static DefaultValue create​(java.lang.String[] stringValues,
                                          java.lang.Object convertedValue)
        Create a non-null default value. If you want to create default value for NULL plesase use createNull(int) instead.
        Parameters:
        stringValues - This is array of original default values from the database. Each value of the array corresponds to default value for one column. The array's length must be > 0.
        convertedValue - Converted value can be specified, but it's not required. You can pass null here. Then the special DefaultValue is created - for example if default value is SYSDATE on Oracle, etc.
        Returns:
        The new instance of DefaultValue
      • parse

        public static DefaultValue parse​(java.lang.String stringValue,
                                         DFDataConvertor convertor)
        Try to parse from string representation (created e.g. using toString().
        Parameters:
        stringValue - String representation e.g. "123" or "a,b" or "null"
        convertor - Convertor used for preparation of value as correct object (e.g. Integer(123))
        Returns:
        The parsed value
      • isNull

        public boolean isNull()
      • toString

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

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

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