Class TupleLiteral

  • All Implemented Interfaces:
    Tuple, Pinnable, java.io.Serializable

    public class TupleLiteral
    extends java.lang.Object
    implements Tuple, java.io.Serializable
    A simple implementation of the Tuple interface for storing literal tuple values.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int storageSize
      The cached storage size of the tuple literal in bytes, or -1 if the size has not been computed and cached.
      private java.util.ArrayList<java.lang.Object> values
      The actual values of the columns in the tuple.
    • Constructor Summary

      Constructors 
      Constructor Description
      TupleLiteral()
      Construct a new tuple-literal that initially has zero columns.
      TupleLiteral​(java.lang.Object... inputs)
      Constructs a new tuple-literal that contains the specified values.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addValue​(java.lang.Object value)
      Appends the specified value to the end of the tuple-literal.
      void appendTuple​(Tuple tuple)
      Appends the specified tuple's contents to this tuple-literal object.
      boolean equals​(java.lang.Object obj)  
      static TupleLiteral fromTuple​(Tuple tuple)
      Constructs a new tuple-literal that is a copy of the specified tuple.
      int getColumnCount()
      Returns a count of the number of columns in the tuple.
      java.lang.Object getColumnValue​(int colIndex)
      Returns the value of a column, or null if the column's SQL value is NULL.
      FilePointer getExternalReference()
      This method returns an external reference to the tuple, which can be stored and used to look up this tuple.
      int getPinCount()
      For in-memory tuples, pinning and unpinning is a no-op.
      int getStorageSize()
      Get the cached storage size of the tuple.
      int hashCode()  
      boolean isDiskBacked()
      In-memory tuples are obviously not disk-backed!
      boolean isNullValue​(int colIndex)
      Returns true if the specified column's value is NULL.
      boolean isPinned()
      For in-memory tuples, pinning and unpinning is a no-op.
      static TupleLiteral ofSize​(int numCols)
      Construct a new tuple-literal with the specified number of columns, each of which is initialized to the SQL NULL (Java null) value.
      void pin()
      For in-memory tuples, pinning and unpinning is a no-op.
      void setColumnValue​(int colIndex, java.lang.Object value)
      Sets the value of a column.
      void setStorageSize​(int size)
      Set the cached storage size of the tuple.
      java.lang.String toString()  
      void unpin()
      For in-memory tuples, pinning and unpinning is a no-op.
      • Methods inherited from class java.lang.Object

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

      • values

        private java.util.ArrayList<java.lang.Object> values
        The actual values of the columns in the tuple.
      • storageSize

        private int storageSize
        The cached storage size of the tuple literal in bytes, or -1 if the size has not been computed and cached.
    • Constructor Detail

      • TupleLiteral

        public TupleLiteral​(java.lang.Object... inputs)
        Constructs a new tuple-literal that contains the specified values.
        Parameters:
        inputs - the collection of values to store in the tuple
    • Method Detail

      • ofSize

        public static TupleLiteral ofSize​(int numCols)
        Construct a new tuple-literal with the specified number of columns, each of which is initialized to the SQL NULL (Java null) value. Each column's type-information is also set to null.
        Parameters:
        numCols - the number of columns to create for the tuple
      • fromTuple

        public static TupleLiteral fromTuple​(Tuple tuple)
        Constructs a new tuple-literal that is a copy of the specified tuple. After construction, the new tuple-literal object can be manipulated in various ways, just like all tuple-literals.
        Parameters:
        tuple - the tuple to make a copy of
      • getStorageSize

        public int getStorageSize()
        Get the cached storage size of the tuple.
        Returns:
        the storage size
      • setStorageSize

        public void setStorageSize​(int size)
        Set the cached storage size of the tuple.
      • isDiskBacked

        public boolean isDiskBacked()
        In-memory tuples are obviously not disk-backed!
        Specified by:
        isDiskBacked in interface Tuple
        Returns:
        false always.
      • pin

        public void pin()
        For in-memory tuples, pinning and unpinning is a no-op.
        Specified by:
        pin in interface Pinnable
      • unpin

        public void unpin()
        For in-memory tuples, pinning and unpinning is a no-op.
        Specified by:
        unpin in interface Pinnable
      • getPinCount

        public int getPinCount()
        For in-memory tuples, pinning and unpinning is a no-op.
        Specified by:
        getPinCount in interface Pinnable
        Returns:
        the total number of times the object has been pinned.
      • isPinned

        public boolean isPinned()
        For in-memory tuples, pinning and unpinning is a no-op.
        Specified by:
        isPinned in interface Pinnable
      • addValue

        public void addValue​(java.lang.Object value)
        Appends the specified value to the end of the tuple-literal.
        Parameters:
        value - the value to append. This is allowed to be null.
      • appendTuple

        public void appendTuple​(Tuple tuple)
        Appends the specified tuple's contents to this tuple-literal object.
        Parameters:
        tuple - the tuple data to copy into this tuple-literal
        Throws:
        java.lang.IllegalArgumentException - if tuple is null.
      • getColumnCount

        public int getColumnCount()
        Description copied from interface: Tuple
        Returns a count of the number of columns in the tuple.
        Specified by:
        getColumnCount in interface Tuple
        Returns:
        a count of the number of columns in the tuple.
      • isNullValue

        public boolean isNullValue​(int colIndex)
        Description copied from interface: Tuple
        Returns true if the specified column's value is NULL.
        Specified by:
        isNullValue in interface Tuple
        Parameters:
        colIndex - the index of the column to check for NULLness.
        Returns:
        true if the specified column is NULL, false otherwise.
      • getColumnValue

        public java.lang.Object getColumnValue​(int colIndex)
        Description copied from interface: Tuple
        Returns the value of a column, or null if the column's SQL value is NULL.
        Specified by:
        getColumnValue in interface Tuple
        Parameters:
        colIndex - the index of the column to retrieve the value for
        Returns:
        the value of the column, or null if the column is NULL.
      • setColumnValue

        public void setColumnValue​(int colIndex,
                                   java.lang.Object value)
        Description copied from interface: Tuple
        Sets the value of a column. If null is passed, the column is set to the SQL NULL value.
        Specified by:
        setColumnValue in interface Tuple
        Parameters:
        colIndex - the index of the column to set the value for
        value - the value to store for the column, or null if the column should be set to NULL.
      • getExternalReference

        public FilePointer getExternalReference()
        This method returns an external reference to the tuple, which can be stored and used to look up this tuple. This implementation throws an UnsupportedOperationException when the method is called, since it doesn't support tuples stored in data files.
        Specified by:
        getExternalReference in interface Tuple
        Returns:
        a file-pointer that can be used to look up this tuple
        Throws:
        java.lang.UnsupportedOperationException - if this operation is unsupported
      • hashCode

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

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

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