Class TObject

  • All Implemented Interfaces:
    java.io.Serializable

    public final class TObject
    extends java.lang.Object
    implements java.io.Serializable
    A TObject is a strongly typed object in a database engine. A TObject must maintain type information (eg. STRING, NUMBER, etc) along with the object value being represented itself.
    Author:
    Tobias Downer
    See Also:
    Serialized Form
    • Field Detail

      • BOOLEAN_TRUE

        public static final TObject BOOLEAN_TRUE
      • BOOLEAN_FALSE

        public static final TObject BOOLEAN_FALSE
      • BOOLEAN_NULL

        public static final TObject BOOLEAN_NULL
      • NULL_OBJECT

        public static final TObject NULL_OBJECT
    • Constructor Detail

      • TObject

        public TObject​(TType type,
                       java.lang.Object ob)
        Constructs the TObject as the given type.
    • Method Detail

      • getTType

        public TType getTType()
        Returns the type of this object.
      • isNull

        public boolean isNull()
        Returns true if the object is null. Note that we must still be able to determine type information for an object that is NULL.
      • getObject

        public java.lang.Object getObject()
        Returns a java.lang.Object that is the data behind this object.
      • approximateMemoryUse

        public int approximateMemoryUse()
        Returns the approximate memory use of this object in bytes. This is used when the engine is caching objects and we need a general indication of how much space it takes up in memory.
      • comparableTypes

        public boolean comparableTypes​(TObject ob)
        Returns true if the type of this object is logically comparable to the type of the given object. For example, VARCHAR and LONGVARCHAR are comparable types. DOUBLE and FLOAT are comparable types. DOUBLE and VARCHAR are not comparable types.
      • toBigNumber

        public BigNumber toBigNumber()
        Returns the BigNumber of this object if this object is a numeric type. If the object is not a numeric type or is NULL then a null object is returned. This method can not be used to cast from a type to a number.
      • toBoolean

        public java.lang.Boolean toBoolean()
        Returns the Boolean of this object if this object is a boolean type. If the object is not a boolean type or is NULL then a null object is returned. This method must not be used to cast from a type to a boolean.
      • toStringValue

        public java.lang.String toStringValue()
        Returns the String of this object if this object is a string type. If the object is not a string type or is NULL then a null object is returned. This method must not be used to cast from a type to a string.
      • booleanVal

        public static TObject booleanVal​(boolean b)
        Returns a TObject of boolean type that is either true or false.
      • intVal

        public static TObject intVal​(int val)
        Returns a TObject of numeric type that represents the given int value.
      • longVal

        public static TObject longVal​(long val)
        Returns a TObject of numeric type that represents the given long value.
      • doubleVal

        public static TObject doubleVal​(double val)
        Returns a TObject of numeric type that represents the given double value.
      • bigNumberVal

        public static TObject bigNumberVal​(BigNumber val)
        Returns a TObject of numeric type that represents the given BigNumber value.
      • stringVal

        public static TObject stringVal​(StringObject str)
        Returns a TObject of VARCHAR type that represents the given StringObject value.
      • stringVal

        public static TObject stringVal​(java.lang.String str)
        Returns a TObject of VARCHAR type that represents the given String value.
      • dateVal

        public static TObject dateVal​(java.util.Date d)
        Returns a TObject of DATE type that represents the given time value.
      • nullVal

        public static TObject nullVal()
        Returns a TObject of NULL type that represents a null value.
      • objectVal

        public static TObject objectVal​(java.lang.Object ob)
        Returns a TObject from the given Java value.
      • compareToNoNulls

        public int compareToNoNulls​(TObject tob)
        Compares this object with the given object (which is of a logically comparable type). Returns 0 if the value of the objects are equal, < 0 if this object is smaller than the given object, and > 0 if this object is greater than the given object.

        This can not be used to compare null values so it assumes that checks for null have already been made.

      • compareTo

        public int compareTo​(TObject tob)
        Compares this object with the given object (which is of a logically comparable type). Returns 0 if the value of the objects are equal, < 0 if this object is smaller than the given object, and > 0 if this object is greater than the given object.

        This compares NULL values before non null values, and null values are equal.

      • equals

        public boolean equals​(java.lang.Object ob)
        Equality test. This will throw an exception if it is used. The reason for this is because it's not clear what we would be testing the equality of with this method. Equality of the object + the type or equality of the objects only?
        Overrides:
        equals in class java.lang.Object
      • valuesEqual

        public boolean valuesEqual​(TObject ob)
        Equality test. Returns true if this object is equivalent to the given TObject. This means the types are the same, and the object itself is the same.
      • operatorOr

        public TObject operatorOr​(TObject val)
        Bitwise OR operation of this object with the given object. If either numeric value has a scale of 1 or greater then it returns null. If this or the given object is not a numeric type then it returns null. If either this object or the given object is NULL, then the NULL object is returned.
      • operatorAdd

        public TObject operatorAdd​(TObject val)
        Mathematical addition of this object to the given object. If this or the given object is not a numeric type then it returns null. If either this object or the given object is NULL, then the NULL object is returned.
      • operatorSubtract

        public TObject operatorSubtract​(TObject val)
        Mathematical subtraction of this object to the given object. If this or the given object is not a numeric type then it returns null. If either this object or the given object is NULL, then the NULL object is returned.
      • operatorMultiply

        public TObject operatorMultiply​(TObject val)
        Mathematical multiply of this object to the given object. If this or the given object is not a numeric type then it returns null. If either this object or the given object is NULL, then the NULL object is returned.
      • operatorDivide

        public TObject operatorDivide​(TObject val)
        Mathematical division of this object to the given object. If this or the given object is not a numeric type then it returns null. If either this object or the given object is NULL, then the NULL object is returned.
      • operatorConcat

        public TObject operatorConcat​(TObject val)
        String concat of this object to the given object. If this or the given object is not a string type then it returns null. If either this object or the given object is NULL, then the NULL object is returned.

        This operator always returns an object that is a VARCHAR string type of unlimited size with locale inherited from either this or val depending on whether the locale information is defined or not.

      • operatorIs

        public TObject operatorIs​(TObject val)
        Comparison of this object and the given object. The compared objects must be the same type otherwise it returns false. This is able to compare null values.
      • operatorEquals

        public TObject operatorEquals​(TObject val)
        Comparison of this object and the given object. The compared objects must be the same type otherwise it returns null (doesn't know). If either this object or the given object is NULL then NULL is returned.
      • operatorNotEquals

        public TObject operatorNotEquals​(TObject val)
        Comparison of this object and the given object. The compared objects must be the same type otherwise it returns null (doesn't know). If either this object or the given object is NULL then NULL is returned.
      • operatorGreater

        public TObject operatorGreater​(TObject val)
        Comparison of this object and the given object. The compared objects must be the same type otherwise it returns null (doesn't know). If either this object or the given object is NULL then NULL is returned.
      • operatorGreaterEquals

        public TObject operatorGreaterEquals​(TObject val)
        Comparison of this object and the given object. The compared objects must be the same type otherwise it returns null (doesn't know). If either this object or the given object is NULL then NULL is returned.
      • operatorLess

        public TObject operatorLess​(TObject val)
        Comparison of this object and the given object. The compared objects must be the same type otherwise it returns null (doesn't know). If either this object or the given object is NULL then NULL is returned.
      • operatorLessEquals

        public TObject operatorLessEquals​(TObject val)
        Comparison of this object and the given object. The compared objects must be the same type otherwise it returns null (doesn't know). If either this object or the given object is NULL then NULL is returned.
      • operatorNot

        public TObject operatorNot()
        Performs a logical NOT on this value.
      • createAndCastFromObject

        public static TObject createAndCastFromObject​(TType type,
                                                      java.lang.Object ob)
        Returns a TObject of the given type and with the given Java object. If the object is not of the right type then it is cast to the correct type.
      • castTo

        public TObject castTo​(TType cast_to_type)
        Casts this object to the given type and returns a new TObject.
      • toString

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