Class TObject

java.lang.Object
com.mckoi.database.TObject
All Implemented Interfaces:
Serializable

public final class TObject extends Object implements 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:
  • Field Details

    • 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 Details

    • TObject

      public TObject(TType type, Object ob)
      Constructs the TObject as the given type.
  • Method Details

    • 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 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 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 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(String str)
      Returns a TObject of VARCHAR type that represents the given String value.
    • dateVal

      public static TObject dateVal(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(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(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 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, 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 String toString()
      Overrides:
      toString in class Object