Class PlsqlIndexByTable2

java.lang.Object
com.mcpdbwizard.pub.PlsqlIndexByTable2
All Implemented Interfaces:
PlsqlArray

public class PlsqlIndexByTable2 extends Object implements PlsqlArray
Holds state variables for PL/SQL Index By Table parameters

This class represents an Oracle PL/SQL Index By Table. In addition to the table data it also holds information about the data type of the elements in the table, their maximum length and the maximum number of elements this table can have after an update or retrieval. For this reason this class is always instantiated even for OUT parameters. As of Oracle 10g INDEX BY tables can have two types of parameters - Numbers or Strings. Parameter types can not be mixed within the same table. MCPDBWizard converts other data types to numbers or strings.

Under normal circumstances MCPDBWizard users will have no reason to use this class directly - the generated code will use it.

Copyright 2003-2026 ATB Consultancy Services Ltd (formerly Orinda Software Ltd, Dublin, Ireland)

Since:
Oracle 10g/5.0.2556
Version:
7
Author:
[email protected]
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Date format mask used by Java for converting Timestamp to String
    static final String
    Date format mask used by Oracle for converting date to String
    static final String
    Date format mask used by Oracle for converting timestamp to String
    static final String
    Date format mask used by Oracle for converting a ZONED timestamp to and from String.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PlsqlIndexByTable2(int realDataTypeCode, int realDataTypePrecision)
    Contruct an empty INDEX BY table
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Give every element a fractional-seconds part, so that a zoned conversion mask will accept it.
    Get the array data
    Get the array data as java.math.BigDecimal[] This convenience method returns the contents of the array as an array of BigDecimal.
    double[]
    getArrayAsDouble(double nullToken)
    Get the array data as double[] This convenience method returns the contents of the array as an array of double.
    Get the array data as Double[] This convenience method returns the contents of the array as an array of BigDecimal.
    float[]
    getArrayAsFloat(float nullToken)
    Get the array data as float[] This convenience method returns the contents of the array as an array of float.
    Get the array data as Float[] This convenience method returns the contents of the array as an array of BigDecimal.
    int[]
    getArrayAsInt(int nullToken)
    Get the array data as int[] This convenience method returns the contents of the array as an array of int.
    Get the array data as Integer[] This convenience method returns the contents of the array as an array of BigDecimal.
    long[]
    getArrayAsLong(long nullToken)
    Get the array data as long[] This convenience method returns the contents of the array as an array of long.
    Get the array data as Long[] This convenience method returns the contents of the array as an array of BigDecimal.
    byte[][]
    Get the array data as byte[] This convenience method returns the contents of the array as an array of byte[].
    Get the array data as String[] This convenience method returns the contents of the array as an array of String.
    Get the array data as java.sql.Timestamp This convenience method returns the contents of the array as an array of java.sql.Timestamp.
    int
    Get the length of the array
    An index-by table has no SQL type name -- it exists only inside PL/SQL and is bound element-wise, never as a named collection -- so there is no name to return.
    The current contents.
    int
    Get the official OracleType code for the array.
    int
    Get the maximum size this table can be after an update or retrieval.
    int
    Get the maximum length of an element in the table
    int
    Get the actual OracleType code for the array.
    void
    setArray(byte[][] newArray)
    Set the array data using byte[][] This convenience method returns sets the array using an array of byte[][]
    void
    setArray(double[] newArray)
    Set the array data using double[] This convenience method returns sets the array using an array of double[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
    void
    setArray(float[] newArray)
    Set the array data using float[] This convenience method returns sets the array using an array of float[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
    void
    setArray(int[] newArray)
    Set the array data using int[] This convenience method sets the array using an array of int[]
    void
    setArray(long[] newArray)
    Set the array data using long[] This convenience method returns sets the array using an array of long[]
    void
    setArray(Double[] newArray)
    Set the array data using Double[] This convenience method returns sets the array using an array of Double[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
    void
    setArray(Float[] newArray)
    Set the array data using Float[] This convenience method returns sets the array using an array of Float[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
    void
    setArray(Integer[] newArray)
    Set the array data using Integer[] This convenience method returns sets the array using an array of Integer[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
    void
    setArray(Long[] newArray)
    Set the array data using Long[] This convenience method returns sets the array using an array of Long[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
    void
    setArray(Object[] newDataArray)
    Set the contents of the Array.
    void
    setArray(Timestamp[] newArray)
    Set the array data using java.sql.Timestamp[] This convenience method returns sets the array using an array of java.sql.Timestamp[]
    void
    setDataType(int dataTypeCode)
    Set the official Oracle data type
    void
    setElementMaxCount(int elementMaxCount)
    Set the maximum size this table can be after an update or retrieval.
    void
    setElementMaxLength(int elementMaxLength)
    Set the maximum length of an element in the table
    void
    Replace the contents from a generic Object[], as PlsqlArray requires.
    void
    setRealDataType(int realDataTypeCode)
    Set the actual Oracle data type

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ORACLE_TIMESTAMP_TO_CHAR_MASK

      public static final String ORACLE_TIMESTAMP_TO_CHAR_MASK
      Date format mask used by Oracle for converting timestamp to String
      See Also:
    • ORACLE_TIMESTAMPTZ_TO_CHAR_MASK

      public static final String ORACLE_TIMESTAMPTZ_TO_CHAR_MASK
      Date format mask used by Oracle for converting a ZONED timestamp to and from String.

      TZR rather than TZH:TZM, and the choice is not arbitrary. Measured against 12c and 23ai: TZR accepts both a numeric offset (+05:30) and a region name (Asia/Calcutta), where TZH:TZM accepts only the offset and rejects a region with ORA-01858. A region name is the only form that survives a daylight-saving transition correctly, so losing it would leave the zone technically present and practically wrong twice a year.

      The cost, and why ensureFractionalSeconds() exists. Adding a zone element to the mask makes Oracle stop tolerating a missing fractional-seconds part: this mask rejects '2019-03-01 14:25:36' with ORA-01843, which the older unzoned ORACLE_TIMESTAMP_TO_CHAR_MASK accepts. That would have been a silent regression for anyone hand-writing timestamp strings, so the value is normalised before it is bound rather than the mask being weakened.

      Since:
      2.0.0
      See Also:
    • ORACLE_DATE_TO_CHAR_MASK

      public static final String ORACLE_DATE_TO_CHAR_MASK
      Date format mask used by Oracle for converting date to String
      See Also:
    • JAVA_DATE_TO_CHAR_MASK

      public static final String JAVA_DATE_TO_CHAR_MASK
      Date format mask used by Java for converting Timestamp to String
      See Also:
  • Constructor Details

    • PlsqlIndexByTable2

      public PlsqlIndexByTable2(int realDataTypeCode, int realDataTypePrecision)
      Contruct an empty INDEX BY table
      Parameters:
      realDataTypeCode - One of oracle.jdbc.OracleTypes.NUMBER or oracle.jdbc.OracleTypes.VARCHAR
      realDataTypePrecision - How many decimal places of precision.
  • Method Details

    • getDataTypeCode

      public int getDataTypeCode()
      Get the official OracleType code for the array.
    • getRealDataTypeCode

      public int getRealDataTypeCode()
      Get the actual OracleType code for the array.
    • setDataType

      public void setDataType(int dataTypeCode)
      Set the official Oracle data type
    • setRealDataType

      public void setRealDataType(int realDataTypeCode)
      Set the actual Oracle data type
    • getElementMaxLength

      public int getElementMaxLength()
      Get the maximum length of an element in the table
    • setElementMaxLength

      public void setElementMaxLength(int elementMaxLength)
      Set the maximum length of an element in the table
    • getElementMaxCount

      public int getElementMaxCount()
      Get the maximum size this table can be after an update or retrieval.
    • setElementMaxCount

      public void setElementMaxCount(int elementMaxCount)
      Set the maximum size this table can be after an update or retrieval. This is used to decide how big the output array should be.
    • getArray

      public Object[] getArray()
      Get the array data
    • setNewValuesAsObject

      public void setNewValuesAsObject(Object[] newValues) throws CSException
      Replace the contents from a generic Object[], as PlsqlArray requires.

      Delegates to setArray(Object[]), which coerces each element to String or BigDecimal according to realDataTypeCode -- so the type code passed to the constructor decides how the values are interpreted, exactly as for every other entry point on this class.

      Specified by:
      setNewValuesAsObject in interface PlsqlArray
      Parameters:
      newValues - an array of Object
      Throws:
      CSException - when array is not usable or is not composed of Object
    • getCurrentValuesAsObject

      public Object[] getCurrentValuesAsObject(Connection theConnection)
      The current contents. The Connection argument is part of the PlsqlArray contract because a generated collection class may need to talk to the database to resolve its SQL type; an index-by table is a purely client-side PL/SQL construct with no SQL type of its own, so the argument is deliberately ignored and may be null.
      Specified by:
      getCurrentValuesAsObject in interface PlsqlArray
      Parameters:
      theConnection - - only used when working with STRUCT.
      Returns:
      Object[]
    • getArrayName

      public String getArrayName()
      An index-by table has no SQL type name -- it exists only inside PL/SQL and is bound element-wise, never as a named collection -- so there is no name to return. The PlsqlArray contract needs the method; callers that key off the name should treat empty as "not a named SQL collection".
      Specified by:
      getArrayName in interface PlsqlArray
      Returns:
      String The Array Name.
    • setArray

      public void setArray(Object[] newDataArray)
      Set the contents of the Array. This method assumes that the user is providing a 1 dimensional array of numbers or strings. The values of elementMaxCount and elementMaxLength are updated by this method. If you are passing in an array that will be appended and returned to you you should call setElementMaxCount and setElementMaxLength after calling setArray. 'null' is not an acceptable value for dataArray and will be turned into Object[0]. This is so that getArrayLength works reliably.
      Parameters:
      newDataArray -
      See Also:
    • setArray

      public void setArray(int[] newArray)
      Set the array data using int[] This convenience method sets the array using an array of int[]
      Parameters:
      newArray -
    • setArray

      public void setArray(Integer[] newArray)
      Set the array data using Integer[] This convenience method returns sets the array using an array of Integer[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
      Parameters:
      newArray -
    • setArray

      public void setArray(long[] newArray)
      Set the array data using long[] This convenience method returns sets the array using an array of long[]
      Parameters:
      newArray -
    • setArray

      public void setArray(Long[] newArray)
      Set the array data using Long[] This convenience method returns sets the array using an array of Long[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
      Parameters:
      newArray -
    • setArray

      public void setArray(float[] newArray)
      Set the array data using float[] This convenience method returns sets the array using an array of float[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
      Parameters:
      newArray -
    • setArray

      public void setArray(Float[] newArray)
      Set the array data using Float[] This convenience method returns sets the array using an array of Float[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
      Parameters:
      newArray -
    • setArray

      public void setArray(double[] newArray)
      Set the array data using double[] This convenience method returns sets the array using an array of double[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
      Parameters:
      newArray -
    • setArray

      public void setArray(Double[] newArray)
      Set the array data using Double[] This convenience method returns sets the array using an array of Double[] WARNING: The precision of the value actually stored is limited to what the underlying Oracle object expects, so if you pass 1.00003f into a NUMBER(4,2) the '3' will be lost
      Parameters:
      newArray -
    • setArray

      public void setArray(Timestamp[] newArray) throws CSNoNanosAllowedException
      Set the array data using java.sql.Timestamp[] This convenience method returns sets the array using an array of java.sql.Timestamp[]
      Parameters:
      newArray -
      Throws:
      CSNoNanosAllowedException - when nanoseconds provided for an Oracle DATE field
    • setArray

      public void setArray(byte[][] newArray)
      Set the array data using byte[][] This convenience method returns sets the array using an array of byte[][]
      Parameters:
      newArray -
    • getArrayAsInt

      public int[] getArrayAsInt(int nullToken) throws CSNumberFormatException
      Get the array data as int[] This convenience method returns the contents of the array as an array of int. Because the array can have null elements and an 'int' can never be null you need to say how nulls should be treated.
      Parameters:
      nullToken - The int you will use to represent null. e.g. Integer.MIN_VALUE
      Returns:
      int[] An array of numbers. If the array is empty you will get int[0] back.
      Throws:
      ClassCastException - if the array isn't of numbers.
      CSNumberFormatException - if the array cant be turned into int.
    • getArrayAsLong

      public long[] getArrayAsLong(long nullToken) throws CSNumberFormatException
      Get the array data as long[] This convenience method returns the contents of the array as an array of long. Because the array can have null elements and a 'long' can never be null you need to say how nulls should be treated.
      Parameters:
      nullToken - The long you will use to represent null. e.g. Long.MIN_VALUE
      Returns:
      long[] An array of numbers. If the array is empty you will get long[0] back.
      Throws:
      ClassCastException - if the array isn't of numbers.
      CSNumberFormatException
    • getArrayAsFloat

      public float[] getArrayAsFloat(float nullToken) throws CSNumberFormatException
      Get the array data as float[] This convenience method returns the contents of the array as an array of float. Because the array can have null elements and a 'float' can never be null you need to say how nulls should be treated.
      Parameters:
      nullToken - The float you will use to represent null. e.g. Float.MIN_VALUE
      Returns:
      float[] An array of numbers. If the array is empty you will get float[0] back.
      Throws:
      ClassCastException - if the array isn't of numbers.
      CSNumberFormatException
    • getArrayAsDouble

      public double[] getArrayAsDouble(double nullToken) throws CSNumberFormatException
      Get the array data as double[] This convenience method returns the contents of the array as an array of double. Because the array can have null elements and a 'double' can never be null you need to say how nulls should be treated.
      Parameters:
      nullToken - The double you will use to represent null. e.g. Double.MIN_VALUE
      Returns:
      double[] An array of numbers. If the array is empty you will get double[0] back.
      Throws:
      ClassCastException - if the array isn't of numbers.
      CSNumberFormatException
    • getArrayAsString

      public String[] getArrayAsString()
      Get the array data as String[] This convenience method returns the contents of the array as an array of String. Because the array can have null elements and an 'double' can never be null you need to say how nulls should be treated.
      Returns:
      String[] An array of Strings. If the array is empty you will get double[0] back.
    • getArrayAsBigDecimal

      public BigDecimal[] getArrayAsBigDecimal() throws CSNumberFormatException
      Get the array data as java.math.BigDecimal[] This convenience method returns the contents of the array as an array of BigDecimal.
      Returns:
      BigDecimal[] An array of BigDecimal
      Throws:
      CSNumberFormatException - if this isn't an array of numbers
      Since:
      4.0.2108
    • getArrayAsDoubleObject

      public Double[] getArrayAsDoubleObject() throws CSNumberFormatException
      Get the array data as Double[] This convenience method returns the contents of the array as an array of BigDecimal.
      Returns:
      Double[] An array Double
      Throws:
      CSNumberFormatException - if this isn't an array of numbers
      Since:
      4.0.2108
    • getArrayAsFloatObject

      public Float[] getArrayAsFloatObject() throws CSNumberFormatException
      Get the array data as Float[] This convenience method returns the contents of the array as an array of BigDecimal.
      Returns:
      Float[] An array of Float
      Throws:
      CSNumberFormatException - if this isn't an array of numbers
      Since:
      4.0.2108
    • getArrayAsIntegerObject

      public Integer[] getArrayAsIntegerObject() throws CSNumberFormatException
      Get the array data as Integer[] This convenience method returns the contents of the array as an array of BigDecimal.
      Returns:
      Integer[] An array of Integer
      Throws:
      CSNumberFormatException - if this isn't an array of numbers
      Since:
      4.0.2108
    • getArrayAsLongObject

      public Long[] getArrayAsLongObject() throws CSNumberFormatException
      Get the array data as Long[] This convenience method returns the contents of the array as an array of BigDecimal.
      Returns:
      Long[] An array of Long
      Throws:
      CSNumberFormatException - if this isn't an array of numbers
      Since:
      4.0.2108
    • getArrayAsTimestamp

      public Timestamp[] getArrayAsTimestamp() throws CSException
      Get the array data as java.sql.Timestamp This convenience method returns the contents of the array as an array of java.sql.Timestamp.
      Returns:
      java.sql.Timestamp[] An array of numbers. If the array is empty you will get java.sql.Timestamp[0] back.
      Throws:
      ClassCastException - if the array isn't of Strings.
      CSException
    • getArrayAsRaw

      public byte[][] getArrayAsRaw()
      Get the array data as byte[] This convenience method returns the contents of the array as an array of byte[].
      Returns:
      byte[][] An array of numbers. If the array is empty you will get byte[][0] back.
      Throws:
      ClassCastException - if the array isn't of numbers.
    • ensureFractionalSeconds

      public void ensureFractionalSeconds()
      Give every element a fractional-seconds part, so that a zoned conversion mask will accept it.

      Generated code calls this on a TIMESTAMP WITH [LOCAL] TIME ZONE index-by table immediately before binding, and on nothing else. It exists because ORACLE_TIMESTAMPTZ_TO_CHAR_MASK carries a TZR element, and Oracle stops tolerating a missing fraction once the mask names a zone: '2019-03-01 14:25:36' parses under the unzoned mask and raises ORA-01843 under the zoned one. Rather than weaken the mask -- which would cost region-name support, the half of the fix that matters across a daylight-saving boundary -- the value is made acceptable here.

      The transformation is deliberately narrow: it appends .0 to the time token of a date time [zone] string that has no . in that token, and leaves everything else exactly as it was. So '2019-03-01 14:25:36 +05:30' becomes '2019-03-01 14:25:36.0 +05:30' -- the zone is not touched and cannot be reordered -- while a value that already carries a fraction, a null, a non-String element, or anything that does not look like a timestamp at all is passed through untouched. **It must not try to validate**: a malformed value should still reach Oracle and be rejected there, with Oracle's own message, rather than be silently altered into something that parses.

      Since:
      2.0.0
    • getArrayLength

      public int getArrayLength()
      Get the length of the array