OracleSdoOrdinateArray.java

/*
 *
 * The DbUnit Database Testing Framework
 * Copyright (C)2002-2008, DbUnit.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

package org.dbunit.ext.oracle;

import java.sql.SQLException;
import java.sql.Connection;
import oracle.jdbc.OracleTypes;
import oracle.sql.ORAData;
import oracle.sql.ORADataFactory;
import oracle.sql.Datum;
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.jpub.runtime.MutableArray;

/**
 * This class was generated by oracle jpub.
 *
 * @see OracleSdoGeometryDataType
 * @author clucas@e-miles.com
 * @author Last changed by: $Author$
 * @version $Revision$ $Date$
 * @since ?
 */
public class OracleSdoOrdinateArray implements ORAData, ORADataFactory
{
  /** The Oracle SQL type name backing this array, <code>MDSYS.SDO_ORDINATE_ARRAY</code>. */
  public static final String _SQL_NAME = "MDSYS.SDO_ORDINATE_ARRAY";
  /** The Oracle JDBC type code backing this array, {@link OracleTypes#ARRAY}. */
  public static final int _SQL_TYPECODE = OracleTypes.ARRAY;

  MutableArray _array;

private static final OracleSdoOrdinateArray _OracleSdoOrdinateArrayFactory = new OracleSdoOrdinateArray();

  /**
   * Returns the shared {@link ORADataFactory} for this class.
   *
   * @return the shared {@link ORADataFactory} for this class.
   */
  public static ORADataFactory getORADataFactory()
  { return _OracleSdoOrdinateArrayFactory; }
  /* constructors */
  /**
   * Default constructor.
   */
  public OracleSdoOrdinateArray()
  {
    this((java.math.BigDecimal[])null);
  }

  /**
   * Constructs an array wrapping the given elements.
   *
   * @param a the element values.
   */
  public OracleSdoOrdinateArray(java.math.BigDecimal[] a)
  {
    _array = new MutableArray(2, a, null);
  }

  /* ORAData interface */
  public Datum toDatum(Connection c) throws SQLException
  {
    return _array.toDatum(c, _SQL_NAME);
  }

  /* ORADataFactory interface */
  public ORAData create(Datum d, int sqlType) throws SQLException
  {
    if (d == null) return null;
    OracleSdoOrdinateArray a = new OracleSdoOrdinateArray();
    a._array = new MutableArray(2, (ARRAY) d, null);
    return a;
  }

  /**
   * Returns the number of elements in the array.
   *
   * @return the number of elements in the array.
   * @throws SQLException if the underlying array cannot be read.
   */
  public int length() throws SQLException
  {
    return _array.length();
  }

  /**
   * Returns the JDBC type code of the array's base element type.
   *
   * @return the JDBC type code of the array's base element type.
   * @throws SQLException if the underlying array cannot be read.
   */
  public int getBaseType() throws SQLException
  {
    return _array.getBaseType();
  }

  /**
   * Returns the SQL type name of the array's base element type.
   *
   * @return the SQL type name of the array's base element type.
   * @throws SQLException if the underlying array cannot be read.
   */
  public String getBaseTypeName() throws SQLException
  {
    return _array.getBaseTypeName();
  }

  /**
   * Returns the descriptor of the underlying Oracle array.
   *
   * @return the descriptor of the underlying Oracle array.
   * @throws SQLException if the underlying array cannot be read.
   */
  public ArrayDescriptor getDescriptor() throws SQLException
  {
    return _array.getDescriptor();
  }

  /* array accessor methods */
  /**
   * Returns the array's elements.
   *
   * @return the array's elements.
   * @throws SQLException if the underlying array cannot be read.
   */
  public java.math.BigDecimal[] getArray() throws SQLException
  {
    return (java.math.BigDecimal[]) _array.getObjectArray();
  }

  /**
   * Returns a range of the array's elements.
   *
   * @param index the index of the first element to return.
   * @param count the number of elements to return.
   * @return the requested range of the array's elements.
   * @throws SQLException if the underlying array cannot be read.
   */
  public java.math.BigDecimal[] getArray(long index, int count) throws SQLException
  {
    return (java.math.BigDecimal[]) _array.getObjectArray(index, count);
  }

  /**
   * Replaces the array's elements.
   *
   * @param a the new element values.
   * @throws SQLException if the underlying array cannot be written.
   */
  public void setArray(java.math.BigDecimal[] a) throws SQLException
  {
    _array.setObjectArray(a);
  }

  /**
   * Replaces a range of the array's elements starting at the given index.
   *
   * @param a the new element values.
   * @param index the index of the first element to replace.
   * @throws SQLException if the underlying array cannot be written.
   */
  public void setArray(java.math.BigDecimal[] a, long index) throws SQLException
  {
    _array.setObjectArray(a, index);
  }

  /**
   * Returns a single element of the array.
   *
   * @param index the index of the element to return.
   * @return the element at the given index.
   * @throws SQLException if the underlying array cannot be read.
   */
  public java.math.BigDecimal getElement(long index) throws SQLException
  {
    return (java.math.BigDecimal) _array.getObjectElement(index);
  }

  /**
   * Replaces a single element of the array.
   *
   * @param a the new element value.
   * @param index the index of the element to replace.
   * @throws SQLException if the underlying array cannot be written.
   */
  public void setElement(java.math.BigDecimal a, long index) throws SQLException
  {
    _array.setObjectElement(a, index);
  }

  public String toString()
  { try { String r = "MDSYS.SDO_ORDINATE_ARRAY" + "(";
     java.math.BigDecimal[] a = (java.math.BigDecimal[])getArray();
     for (int i=0; i<a.length; ) {
       r = r + a[i];
       i++; if (i<a.length) r = r + ","; }
     r = r + ")"; return r;
    } catch (SQLException e) { return e.toString(); }
  }

    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }

        if ((obj == null) || (! obj.getClass().equals(this.getClass())))
        {
            return false;
        }

        OracleSdoOrdinateArray otherObject = (OracleSdoOrdinateArray) obj;

        try
        {
            return OracleSdoHelper.objectArraysEquals(getArray(), otherObject.getArray());
        }
        catch (SQLException ex)
        {
            return false;
        }
    }

    public int hashCode()
    {
        try
        {
            return OracleSdoHelper.objectArrayHashCode(getArray());
        }
        catch (SQLException ex)
        {
            return 0;
        }
    }

}