From: <jb...@us...> - 2009-12-01 20:49:43
|
Revision: 1124 http://dbunit.svn.sourceforge.net/dbunit/?rev=1124&view=rev Author: jbhurst Date: 2009-12-01 20:49:33 +0000 (Tue, 01 Dec 2009) Log Message: ----------- [2875253] - Additional refinements for Oracle SDO_GEOMETRY datatype. Thanks Lucas Casey. Modified Paths: -------------- trunk/dbunit/src/changes/changes.xml trunk/dbunit/src/java/org/dbunit/dataset/datatype/StringDataType.java trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometryDataType.java trunk/dbunit/src/test/org/dbunit/dataset/datatype/StringDataTypeTest.java trunk/dbunit/src/test/org/dbunit/operation/UpdateOperationTest.java trunk/dbunit/src/xml/sdoGeometryUpdateTest.xml Added Paths: ----------- trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoElemInfoArray.java trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometry.java trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoHelper.java trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoOrdinateArray.java trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoPointType.java trunk/dbunit/src/test/org/dbunit/ext/oracle/OracleSdoGeometryDataTypeTest.java Modified: trunk/dbunit/src/changes/changes.xml =================================================================== --- trunk/dbunit/src/changes/changes.xml 2009-12-01 07:21:06 UTC (rev 1123) +++ trunk/dbunit/src/changes/changes.xml 2009-12-01 20:49:33 UTC (rev 1124) @@ -12,6 +12,7 @@ <body> <release version="2.4.8" date="TBD" description="TBD"> <action dev="gommma" type="fix" issue="2887115" due-to="unwissender2009">SQL: "Create Domain" ... Data Types are not supported.</action> + <action dev="jbhurst" type="add" issue="2875253" due-to="caseylucas">Additional refinements for Oracle SDO_GEOMETRY datatype</action> </release> <release version="2.4.7" date="Nov 09, 2009" description="Bugfixes and some non breaking refactoring"> <action dev="gommma" type="fix" issue="2685615" due-to="lumpynose">dtd for XmlDataSet</action> Modified: trunk/dbunit/src/java/org/dbunit/dataset/datatype/StringDataType.java =================================================================== --- trunk/dbunit/src/java/org/dbunit/dataset/datatype/StringDataType.java 2009-12-01 07:21:06 UTC (rev 1123) +++ trunk/dbunit/src/java/org/dbunit/dataset/datatype/StringDataType.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -129,7 +129,11 @@ } } - throw new TypeCastException(value, this); + logger.warn("Unknown/unsupported object type '{}' - " + + "will invoke toString() as last fallback which " + + "might produce undesired results", + value.getClass().getName()); + return value.toString(); } public Object getSqlValue(int column, ResultSet resultSet) Added: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoElemInfoArray.java =================================================================== --- trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoElemInfoArray.java (rev 0) +++ trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoElemInfoArray.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -0,0 +1,177 @@ +/* + * + * 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 cl...@e-... + * @author Last changed by: $Author$ + * @version $Revision$ $Date$ + * @since ? + */ +public class OracleSdoElemInfoArray implements ORAData, ORADataFactory +{ + public static final String _SQL_NAME = "MDSYS.SDO_ELEM_INFO_ARRAY"; + public static final int _SQL_TYPECODE = OracleTypes.ARRAY; + + MutableArray _array; + +private static final OracleSdoElemInfoArray _OracleSdoElemInfoArrayFactory = new OracleSdoElemInfoArray(); + + public static ORADataFactory getORADataFactory() + { return _OracleSdoElemInfoArrayFactory; } + /* constructors */ + public OracleSdoElemInfoArray() + { + this((java.math.BigDecimal[])null); + } + + public OracleSdoElemInfoArray(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; + OracleSdoElemInfoArray a = new OracleSdoElemInfoArray(); + a._array = new MutableArray(2, (ARRAY) d, null); + return a; + } + + public int length() throws SQLException + { + return _array.length(); + } + + public int getBaseType() throws SQLException + { + return _array.getBaseType(); + } + + public String getBaseTypeName() throws SQLException + { + return _array.getBaseTypeName(); + } + + public ArrayDescriptor getDescriptor() throws SQLException + { + return _array.getDescriptor(); + } + + /* array accessor methods */ + public java.math.BigDecimal[] getArray() throws SQLException + { + return (java.math.BigDecimal[]) _array.getObjectArray(); + } + + public java.math.BigDecimal[] getArray(long index, int count) throws SQLException + { + return (java.math.BigDecimal[]) _array.getObjectArray(index, count); + } + + public void setArray(java.math.BigDecimal[] a) throws SQLException + { + _array.setObjectArray(a); + } + + public void setArray(java.math.BigDecimal[] a, long index) throws SQLException + { + _array.setObjectArray(a, index); + } + + public java.math.BigDecimal getElement(long index) throws SQLException + { + return (java.math.BigDecimal) _array.getObjectElement(index); + } + + public void setElement(java.math.BigDecimal a, long index) throws SQLException + { + _array.setObjectElement(a, index); + } + + public String toString() + { try { String r = "MDSYS.SDO_ELEM_INFO_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; + } + + OracleSdoElemInfoArray otherObject = (OracleSdoElemInfoArray) 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; + } + } + +} Property changes on: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoElemInfoArray.java ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometry.java =================================================================== --- trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometry.java (rev 0) +++ trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometry.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -0,0 +1,191 @@ +/* + * + * 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.STRUCT; +import oracle.jpub.runtime.MutableStruct; + +/** + * This class was generated by oracle jpub. + * + * @see OracleSdoGeometryDataType + * @author cl...@e-... + * @author Last changed by: $Author$ + * @version $Revision$ $Date$ + * @since ? + */ +public class OracleSdoGeometry implements ORAData, ORADataFactory +{ + public static final String _SQL_NAME = "MDSYS.SDO_GEOMETRY"; + public static final int _SQL_TYPECODE = OracleTypes.STRUCT; + + protected MutableStruct _struct; + + protected static int[] _sqlType = { 2,2,2002,2003,2003 }; + protected static ORADataFactory[] _factory = new ORADataFactory[5]; + static + { + _factory[2] = OracleSdoPointType.getORADataFactory(); + _factory[3] = OracleSdoElemInfoArray.getORADataFactory(); + _factory[4] = OracleSdoOrdinateArray.getORADataFactory(); + } + protected static final OracleSdoGeometry _OracleSdoGeometryFactory = new OracleSdoGeometry(); + + public static ORADataFactory getORADataFactory() + { return _OracleSdoGeometryFactory; } + /* constructors */ + protected void _init_struct(boolean init) + { if (init) _struct = new MutableStruct(new Object[5], _sqlType, _factory); } + public OracleSdoGeometry() + { _init_struct(true); } + public OracleSdoGeometry(java.math.BigDecimal sdoGtype, java.math.BigDecimal sdoSrid, OracleSdoPointType sdoPoint, OracleSdoElemInfoArray sdoElemInfo, OracleSdoOrdinateArray sdoOrdinates) throws SQLException + { _init_struct(true); + setSdoGtype(sdoGtype); + setSdoSrid(sdoSrid); + setSdoPoint(sdoPoint); + setSdoElemInfo(sdoElemInfo); + setSdoOrdinates(sdoOrdinates); + } + + /* ORAData interface */ + public Datum toDatum(Connection c) throws SQLException + { + return _struct.toDatum(c, _SQL_NAME); + } + + + /* ORADataFactory interface */ + public ORAData create(Datum d, int sqlType) throws SQLException + { return create(null, d, sqlType); } + protected ORAData create(OracleSdoGeometry o, Datum d, int sqlType) throws SQLException + { + if (d == null) return null; + if (o == null) o = new OracleSdoGeometry(); + o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory); + return o; + } + /* accessor methods */ + public java.math.BigDecimal getSdoGtype() throws SQLException + { return (java.math.BigDecimal) _struct.getAttribute(0); } + + public void setSdoGtype(java.math.BigDecimal sdoGtype) throws SQLException + { _struct.setAttribute(0, sdoGtype); } + + + public java.math.BigDecimal getSdoSrid() throws SQLException + { return (java.math.BigDecimal) _struct.getAttribute(1); } + + public void setSdoSrid(java.math.BigDecimal sdoSrid) throws SQLException + { _struct.setAttribute(1, sdoSrid); } + + + public OracleSdoPointType getSdoPoint() throws SQLException + { return (OracleSdoPointType) _struct.getAttribute(2); } + + public void setSdoPoint(OracleSdoPointType sdoPoint) throws SQLException + { _struct.setAttribute(2, sdoPoint); } + + + public OracleSdoElemInfoArray getSdoElemInfo() throws SQLException + { return (OracleSdoElemInfoArray) _struct.getAttribute(3); } + + public void setSdoElemInfo(OracleSdoElemInfoArray sdoElemInfo) throws SQLException + { _struct.setAttribute(3, sdoElemInfo); } + + + public OracleSdoOrdinateArray getSdoOrdinates() throws SQLException + { return (OracleSdoOrdinateArray) _struct.getAttribute(4); } + + public void setSdoOrdinates(OracleSdoOrdinateArray sdoOrdinates) throws SQLException + { _struct.setAttribute(4, sdoOrdinates); } + + public String toString() + { try { + return "MDSYS.SDO_GEOMETRY" + "(" + + getSdoGtype() + "," + + getSdoSrid() + "," + + getSdoPoint() + "," + + getSdoElemInfo() + "," + + getSdoOrdinates() + + ")"; + } catch (Exception e) { return e.toString(); } + } + + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + + if (obj == null || ! obj.getClass().equals(this.getClass())) + { + return false; + } + + OracleSdoGeometry otherSdoGeom = (OracleSdoGeometry) obj; + + try + { + return + OracleSdoHelper.objectsEqual(getSdoGtype(), otherSdoGeom.getSdoGtype()) && + OracleSdoHelper.objectsEqual(getSdoSrid(), otherSdoGeom.getSdoSrid()) && + OracleSdoHelper.objectsEqual(getSdoPoint(), otherSdoGeom.getSdoPoint()) && + OracleSdoHelper.objectsEqual(getSdoElemInfo(), otherSdoGeom.getSdoElemInfo()) && + OracleSdoHelper.objectsEqual(getSdoOrdinates(), otherSdoGeom.getSdoOrdinates()); + } + catch (SQLException ex) + { + return false; + } + } + + public int hashCode() + { + try + { + int hash = 7; + Object o; + o = getSdoGtype(); + hash = 31 * hash + (null == o ? 0 : o.hashCode()); + o = getSdoSrid(); + hash = 31 * hash + (null == o ? 0 : o.hashCode()); + o = getSdoPoint(); + hash = 31 * hash + (null == o ? 0 : o.hashCode()); + o = getSdoElemInfo(); + hash = 31 * hash + (null == o ? 0 : o.hashCode()); + o = getSdoOrdinates(); + hash = 31 * hash + (null == o ? 0 : o.hashCode()); + return hash; + } + catch (SQLException ex) + { + return 0; + } + } +} Property changes on: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometry.java ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometryDataType.java =================================================================== --- trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometryDataType.java 2009-12-01 07:21:06 UTC (rev 1123) +++ trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoGeometryDataType.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -27,10 +27,12 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; -import java.text.ParseException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -import oracle.sql.STRUCT; -import oracle.sql.StructDescriptor; +import oracle.jdbc.OracleResultSet; +import oracle.jdbc.OraclePreparedStatement; +import oracle.sql.ORAData; import org.dbunit.dataset.datatype.AbstractDataType; import org.dbunit.dataset.datatype.TypeCastException; @@ -84,6 +86,32 @@ * </code> * </p> * + * <p> + * This class uses the following objects which were rendered using oracle jpub and then + * slightly customized to work with dbunit: + * <ul> + * <li>OracleSdoGeometry - corresponds to oracle SDO_GEOMETRY data type</li> + * <li>OracleSdoPointType - corresponds to oracle SDO_POINT_TYPE data type</li> + * <li>OracleSdoElemInfoArray - corresponds to oracle SDO_ELEM_INFO_ARRAY data type</li> + * <li>OracleSdoOridinateArray - corresponds to oracle SDO_ORDINATE_ARRAY data type</li> + * </ul> + * These classes were rendered via jpub + * (http://download.oracle.com/otn/utilities_drivers/jdbc/10201/jpub_102.zip) + * with the following command syntax: + * <code> + * ./jpub -user=YOUR_USER_ID/YOUR_PASSWORD -url=YOUR_JDBC_URL + * -sql mdsys.sdo_geometry:OracleSdoGeometry, + * mdsys.sdo_point_type:OracleSdoPointType, + * mdsys.sdo_elem_info_array:OracleSdoElemInfoArray, + * mdsys.sdo_ordinate_array:OracleSdoOrdinateArray + * -dir=output_dir -methods=none -package=org.dbunit.ext.oracle -tostring=true + * </code> + * The equals and hashCode methods were then added so that the objects could be compared + * in test cases. Note that I did have to bash the jpub startup script (change classpath) + * because it assumes oracle 10g database but I ran it with 11g. Theoretically, this + * process can be repeated for other custom oracle object data types. + * </p> + * * @author cl...@e-... * @author Last changed by: $Author$ * @version $Revision$ $Date$ @@ -98,91 +126,25 @@ private static final String NULL = "NULL"; private static final String SDO_GEOMETRY = "SDO_GEOMETRY"; - private static final String SDO_POINT_TYPE = "SDO_POINT_TYPE"; - private static final String SDO_ELEM_INFO_ARRAY = "SDO_ELEM_INFO_ARRAY"; - private static final String SDO_ORDINATE_ARRAY = "SDO_ORDINATE_ARRAY"; + // patterns for parsing out the various pieces of the string + // representation of an sdo_geometry object + private static final Pattern sdoGeometryPattern = Pattern.compile( + "^(?:MDSYS\\.)?SDO_GEOMETRY\\s*\\(\\s*([^,\\s]+)\\s*,\\s*([^,\\s]+)\\s*,\\s*"); + private static final Pattern sdoPointTypePattern = Pattern.compile( + "^(?:(?:(?:MDSYS\\.)?SDO_POINT_TYPE\\s*\\(\\s*([^,\\s]+)\\s*,\\s*([^,\\s]+)\\s*,\\s*([^,\\s\\)]+)\\s*\\))|(NULL))\\s*,\\s*"); + private static final Pattern sdoElemInfoArrayPattern = Pattern.compile( + "^(?:(?:(?:(?:MDSYS\\.)?SDO_ELEM_INFO_ARRAY\\s*\\(([^\\)]*)\\))|(NULL)))\\s*,\\s*"); + private static final Pattern sdoOrdinateArrayPattern = Pattern.compile( + "^(?:(?:(?:(?:MDSYS\\.)?SDO_ORDINATE_ARRAY\\s*\\(([^\\)]*)\\))|(NULL)))\\s*\\)\\s*"); + OracleSdoGeometryDataType () { - super(SDO_GEOMETRY, Types.STRUCT, java.sql.Struct.class, false); + super(SDO_GEOMETRY, Types.STRUCT, OracleSdoGeometry.class, false); } public Object typeCast(Object value) throws TypeCastException { - return typeCast(value, null); - } - - /** - * This method parses out a list of numbers similar to: - * <ul> - * <li> - * SDO_ORDINATE_ARRAY(2, 2, 0, 2, 4, 2, 8, 4, 8, 12, 4, 12, 12, 10, NULL, 8) - * </li> - * <li> - * SDO_POINT_TYPE(96.8233, 32.5261, NULL) - * </li> - * </ul> - * - * @param input input string to parse (may be null) - * @param name name of array (ex: SDO_ORDINATE_ARRAY) - * @return array of parsed numbers some of which may be null - */ - private BigDecimal [] parseNumbers(String input, String name) throws ParseException - { - logger.debug("parseNumbers(input={}, name={}) - start", input, name); - if (input == null) - { - return null; - } - - int workIndex = 0; - if (name != null) - { - if (! input.startsWith(name)) - { - throw new ParseException("missing " + name, workIndex); - } - workIndex += name.length(); - } - - if (workIndex+1 >= input.length() || input.charAt(workIndex) != '(') - { - throw new ParseException("missing (", workIndex); - } - if (input.charAt(input.length() - 1) != ')') - { - throw new ParseException("missing )", input.length() - 1); - } - String [] numberStrings = input.substring(workIndex + 1, input.length() - 1).split(","); - if (numberStrings == null) - { - return null; - } - BigDecimal returnVal [] = new BigDecimal[numberStrings.length]; - for (int index=0; index<numberStrings.length; index++) - { - String valToParse = numberStrings[index].trim(); - logger.debug("parsing {} as BigDecimal", valToParse); - if (NULL.equals(valToParse)) - { - returnVal[index] = null; - } - else - { - returnVal[index] = new BigDecimal(valToParse); - } - } - - return returnVal; - } - - /** - * This method performs a typeCast using a jdbc connection. The connection is required - * for working with oracle STRUCTs. - * - */ - public Object typeCast(Object value, Connection connection) throws TypeCastException - { logger.debug("typeCast(value={}) - start", value); if (value == null || value == ITable.NO_VALUE) @@ -190,168 +152,135 @@ return null; } - if (value instanceof java.sql.Struct) + + if (value instanceof OracleSdoGeometry) { - return value; + return (OracleSdoGeometry) value; } if (value instanceof String) { // attempt to parse the SDO_GEOMETRY - if (connection == null) - { - throw new TypeCastException(value, this); - } - try { - String upperVal = ((String) value).toUpperCase(); + // all upper case for parse purposes + String upperVal = ((String) value).toUpperCase().trim(); if (NULL.equals(upperVal)) { return null; } - if (! (upperVal.startsWith(SDO_GEOMETRY + "(") && upperVal.endsWith(")"))) + // parse out sdo_geometry + Matcher sdoGeometryMatcher = sdoGeometryPattern.matcher(upperVal); + if (! sdoGeometryMatcher.find()) { throw new TypeCastException(value, this); } + BigDecimal gtype = NULL.equals(sdoGeometryMatcher.group(1)) ? + null : new BigDecimal(sdoGeometryMatcher.group(1)); + BigDecimal srid = NULL.equals(sdoGeometryMatcher.group(2)) ? + null : new BigDecimal(sdoGeometryMatcher.group(2)); - String workingVal = upperVal.substring( - (SDO_GEOMETRY + "(").length(), upperVal.length() - 1); - int workingIndex = 0; - - // parse out SDO_GTYPE - int commaIndex = workingVal.indexOf(",", workingIndex); - if (commaIndex == -1 || commaIndex == workingIndex || - commaIndex+1 == workingVal.length()) + // parse out sdo_point_type + upperVal = upperVal.substring(sdoGeometryMatcher.end()); + Matcher sdoPointTypeMatcher = sdoPointTypePattern.matcher(upperVal); + if (! sdoPointTypeMatcher.find()) { throw new TypeCastException(value, this); } - String gtypeString = workingVal.substring(workingIndex, commaIndex).trim(); - Integer gtype = NULL.equals(gtypeString) ? null : new Integer(gtypeString); - workingIndex = commaIndex + 1; - // parse out SDO_SRID - commaIndex = workingVal.indexOf(",", workingIndex); - if (commaIndex == -1 || commaIndex == workingIndex || - commaIndex+1 == workingVal.length()) + OracleSdoPointType sdoPoint; + if (NULL.equals(sdoPointTypeMatcher.group(4))) { - throw new TypeCastException(value, this); + sdoPoint = null; } - String sridString = workingVal.substring(workingIndex, commaIndex).trim(); - Integer srid = NULL.equals(sridString) ? null : new Integer(sridString); - workingIndex = commaIndex + 1; - - // parse out SDO_POINT - workingVal = workingVal.substring(workingIndex).trim(); - workingIndex = 0; - - BigDecimal pointValues []; - if (workingVal.startsWith(NULL)) - { - pointValues = null; - } else { - int closingParenIndex = workingVal.indexOf(")", workingIndex); - if (closingParenIndex == -1) - { - throw new TypeCastException(value, this); - } - pointValues = parseNumbers(workingVal.substring( - workingIndex, closingParenIndex + 1), SDO_POINT_TYPE); - workingIndex = closingParenIndex + 1; + sdoPoint = new OracleSdoPointType( + NULL.equals(sdoPointTypeMatcher.group(1)) ? null : + new BigDecimal(sdoPointTypeMatcher.group(1)), + NULL.equals(sdoPointTypeMatcher.group(2)) ? null : + new BigDecimal(sdoPointTypeMatcher.group(2)), + NULL.equals(sdoPointTypeMatcher.group(3)) ? null : + new BigDecimal(sdoPointTypeMatcher.group(3))); } - - // eat the comma - commaIndex = workingVal.indexOf(",", workingIndex); - if (commaIndex == -1 || commaIndex+1 == workingVal.length()) + // parse out sdo_elem_info_array + upperVal = upperVal.substring(sdoPointTypeMatcher.end()); + Matcher sdoElemInfoArrayMatcher = sdoElemInfoArrayPattern.matcher(upperVal); + if (! sdoElemInfoArrayMatcher.find()) { throw new TypeCastException(value, this); } - workingVal = workingVal.substring(commaIndex + 1).trim(); - workingIndex = 0; - - BigDecimal elemInfos []; - if (workingVal.startsWith(NULL)) + OracleSdoElemInfoArray sdoElemInfoArray; + if (NULL.equals(sdoElemInfoArrayMatcher.group(2))) { - elemInfos = null; + sdoElemInfoArray = null; } else { - int closingParenIndex = workingVal.indexOf(")", workingIndex); - if (closingParenIndex == -1) + String [] elemInfoStrings = sdoElemInfoArrayMatcher.group(1). + trim().split("\\s*,\\s*"); + if (elemInfoStrings.length == 1 && "".equals(elemInfoStrings[0])) { - throw new TypeCastException(value, this); + sdoElemInfoArray = new OracleSdoElemInfoArray(); } - elemInfos = parseNumbers(workingVal.substring( - workingIndex, closingParenIndex + 1), SDO_ELEM_INFO_ARRAY); - workingIndex = closingParenIndex + 1; + else + { + BigDecimal [] elemInfos = new BigDecimal[elemInfoStrings.length]; + for (int index = 0; index < elemInfoStrings.length; index++) + { + elemInfos[index] = NULL.equals(elemInfoStrings[index]) ? + null : new BigDecimal(elemInfoStrings[index]); + } + sdoElemInfoArray = new OracleSdoElemInfoArray(elemInfos); + } } - // eat the comma - commaIndex = workingVal.indexOf(",", workingIndex); - if (commaIndex == -1 || commaIndex+1 == workingVal.length()) + // parse out sdo_ordinate_array + upperVal = upperVal.substring(sdoElemInfoArrayMatcher.end()); + Matcher sdoOrdinateArrayMatcher = sdoOrdinateArrayPattern.matcher(upperVal); + if (! sdoOrdinateArrayMatcher.find()) { throw new TypeCastException(value, this); } - workingVal = workingVal.substring(commaIndex + 1).trim(); - workingIndex = 0; - - BigDecimal ordinates []; - if (workingVal.startsWith(NULL)) + + OracleSdoOrdinateArray sdoOrdinateArray; + if (NULL.equals(sdoOrdinateArrayMatcher.group(2))) { - ordinates = null; + sdoOrdinateArray = null; } else { - int closingParenIndex = workingVal.indexOf(")", workingIndex); - if (closingParenIndex == -1) + String [] ordinateStrings = sdoOrdinateArrayMatcher.group(1). + trim().split("\\s*,\\s*"); + if (ordinateStrings.length == 1 && "".equals(ordinateStrings[0])) { - throw new TypeCastException(value, this); + sdoOrdinateArray = new OracleSdoOrdinateArray(); } - ordinates = parseNumbers(workingVal.substring( - workingIndex, closingParenIndex + 1), SDO_ORDINATE_ARRAY); - workingIndex = closingParenIndex + 1; - } - - - // Now package it all up in an oracle STRUCT object - - // SDO_POINT_TYPE - STRUCT pointStruct; - if (pointValues == null) - { - pointStruct = null; - } - else - { - // SDO_POINT_TYPE has x,y,z coordinates - if (pointValues.length != 3) + else { - throw new TypeCastException(value, this); + BigDecimal [] ordinates = new BigDecimal[ordinateStrings.length]; + for (int index = 0; index < ordinateStrings.length; index++) + { + ordinates[index] = NULL.equals(ordinateStrings[index]) ? + null : new BigDecimal(ordinateStrings[index]); + } + sdoOrdinateArray = new OracleSdoOrdinateArray(ordinates); } - StructDescriptor pointDescriptor = StructDescriptor.createDescriptor(SDO_POINT_TYPE, connection); - Object [] pointAttributes = new Object [] - { pointValues[0], pointValues[1], pointValues[2] }; - pointStruct = new STRUCT(pointDescriptor, connection, pointAttributes); } - // SDO_GEOMETRY - StructDescriptor geometryDescriptor = StructDescriptor.createDescriptor(SDO_GEOMETRY, connection); - Object [] geometryAttributes = new Object [] - { gtype, srid, pointStruct, elemInfos, ordinates }; - STRUCT geometryStruct = new STRUCT(geometryDescriptor, connection, geometryAttributes); + OracleSdoGeometry sdoGeometry = new OracleSdoGeometry( + gtype, srid, sdoPoint, sdoElemInfoArray, sdoOrdinateArray); - return geometryStruct; + return sdoGeometry; } - catch (ParseException e) + catch (SQLException e) { throw new TypeCastException(value, this, e); } - catch (SQLException e) + catch (NumberFormatException e) { throw new TypeCastException(value, this, e); } @@ -361,30 +290,6 @@ } - protected void appendNamedArray(StringBuffer buf, String name, - java.sql.Array array) throws SQLException - { - if (array == null) - { - buf.append(NULL); - } - else - { - buf.append(name); - buf.append("("); - Object elements [] = (Object[]) array.getArray(); - for (int index=0; index<elements.length; index++) - { - buf.append(elements[index] == null ? NULL : elements[index]); - if (index+1 != elements.length) - { - buf.append(", "); - } - } - buf.append(")"); - } - } - public Object getSqlValue(int column, ResultSet resultSet) throws SQLException, TypeCastException { @@ -395,55 +300,27 @@ Object data = null; try { - data = resultSet.getObject(column); + data = ((OracleResultSet) resultSet). + getORAData(column, OracleSdoGeometry.getORADataFactory()); - if (data != null) - { - if (! (data instanceof STRUCT)) - { - throw new TypeCastException(data, this); - } + // It would be preferable to return the actual object, but there are + // a few dbunit issues with this: + // + // 1. Dbunit does not support nulls for user defined types (at least + // with oracle.) PreparedStatement.setNull(int, int) is always used + // but PreparedStatement.setNull(int, int, String) is required + // for sdo_geometry (and other similar custom object types). + // + // 2. Dbunit does not support rendering custom objects (such as + // OracleSdoGeometry) as strings. + // + // So, instead we return the object as a String or "NULL". - Object attributes [] = ((STRUCT) data).getAttributes(); + // return data; - // build out a string representing the SDO_GEOMETRY - StringBuffer buf = new StringBuffer(); - - Object attribute; - buf.append(SDO_GEOMETRY); - buf.append("("); - attribute = attributes[0]; - buf.append(attribute == null ? NULL : attribute); - buf.append(", "); - attribute = attributes[1]; - buf.append(attribute == null ? NULL : attribute); - buf.append(", "); - attribute = attributes[2]; - if (attribute == null) - { - buf.append(NULL); - } - else - { - buf.append(SDO_POINT_TYPE); - buf.append("("); - Object [] pointAttributes = ((STRUCT) attribute).getAttributes(); - buf.append(pointAttributes[0] == null ? NULL : pointAttributes[0]); - buf.append(", "); - buf.append(pointAttributes[1] == null ? NULL : pointAttributes[1]); - buf.append(", "); - buf.append(pointAttributes[2] == null ? NULL : pointAttributes[2]); - buf.append(")"); - } - buf.append(", "); - - appendNamedArray(buf, SDO_ELEM_INFO_ARRAY, (java.sql.Array) attributes[3]); - buf.append(", "); - appendNamedArray(buf, SDO_ORDINATE_ARRAY, (java.sql.Array) attributes[4]); - - buf.append(")"); - - return buf.toString(); + if (data != null) + { + return data.toString(); } else { @@ -460,16 +337,75 @@ } } - public void setSqlValue(Object value, int column, PreparedStatement statement) throws SQLException, TypeCastException + public void setSqlValue(Object value, int column, PreparedStatement statement) + throws SQLException, TypeCastException { - Object castValue = typeCast(value, statement.getConnection()); + Object castValue = typeCast(value); if (castValue == null) { - statement.setNull(column, Types.STRUCT, SDO_GEOMETRY); + statement.setNull(column, OracleSdoGeometry._SQL_TYPECODE, + OracleSdoGeometry._SQL_NAME); } else { - statement.setObject(column, castValue, Types.STRUCT); + ((OraclePreparedStatement) statement).setORAData(column, (ORAData) castValue); } } + + /** + * This method is copied from AbstractDataType and customized to call equals + * after the typeCast because OracleSdoGeometry objects are not Comparables + * but can test for equality (via equals method.) It is needed for test + * cases that check for equality between data in xml files and data read + * from the database. + */ + public int compare(Object o1, Object o2) throws TypeCastException + { + logger.debug("compare(o1={}, o2={}) - start", o1, o2); + + try + { + // New in 2.3: Object level check for equality - should give massive performance improvements + // in the most cases because the typecast can be avoided (null values and equal objects) + if(areObjectsEqual(o1, o2)) + { + return 0; + } + + + // Comparable check based on the results of method "typeCast" + Object value1 = typeCast(o1); + Object value2 = typeCast(o2); + + // Check for "null"s again because typeCast can produce them + + if (value1 == null && value2 == null) + { + return 0; + } + + if (value1 == null && value2 != null) + { + return -1; + } + + if (value1 != null && value2 == null) + { + return 1; + } + + if (value1.equals(value2)) + { + return 0; + } + + return compareNonNulls(value1, value2); + + } + catch (ClassCastException e) + { + throw new TypeCastException(e); + } + } + } Added: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoHelper.java =================================================================== --- trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoHelper.java (rev 0) +++ trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoHelper.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -0,0 +1,83 @@ +/* + * + * 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.math.BigDecimal; + +/** + * This class provides some basic functionality shared among the OracleSdo* + * objects. + * + * @author cl...@e-... + * @author Last changed by: $Author$ + * @version $Revision$ $Date$ + * @since ? + */ +class OracleSdoHelper +{ + public static boolean objectsEqual(Object object1, Object object2) + { + return + (object1 != null && object1.equals(object2)) || + (object1 == null && object2 == null) || + // special case for BigDecimal support + (object1 != null && object2 != null && + object1 instanceof BigDecimal && object2 instanceof BigDecimal && + ((BigDecimal)object1).compareTo((BigDecimal)object2) == 0); + } + + public static boolean objectArraysEquals(Object [] objects1, Object [] objects2) + { + if (objects1 == objects2) + { + return true; + } + + if (objects1 == null || objects2 == null || objects1.length != objects2.length) + { + return false; + } + + for (int index = 0; index<objects1.length; index++) + { + if (! objectsEqual(objects1[index], objects2[index])) + { + return false; + } + } + + return true; + } + + public static int objectArrayHashCode(Object [] objects) + { + int hash = 7; + if (objects != null) + { + for (int index = 0; index<objects.length; index++) + { + hash = 31 * hash + (null == objects[index] ? 0 : objects[index].hashCode()); + } + } + return hash; + } +} Property changes on: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoHelper.java ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoOrdinateArray.java =================================================================== --- trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoOrdinateArray.java (rev 0) +++ trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoOrdinateArray.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -0,0 +1,177 @@ +/* + * + * 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 cl...@e-... + * @author Last changed by: $Author$ + * @version $Revision$ $Date$ + * @since ? + */ +public class OracleSdoOrdinateArray implements ORAData, ORADataFactory +{ + public static final String _SQL_NAME = "MDSYS.SDO_ORDINATE_ARRAY"; + public static final int _SQL_TYPECODE = OracleTypes.ARRAY; + + MutableArray _array; + +private static final OracleSdoOrdinateArray _OracleSdoOrdinateArrayFactory = new OracleSdoOrdinateArray(); + + public static ORADataFactory getORADataFactory() + { return _OracleSdoOrdinateArrayFactory; } + /* constructors */ + public OracleSdoOrdinateArray() + { + this((java.math.BigDecimal[])null); + } + + 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; + } + + public int length() throws SQLException + { + return _array.length(); + } + + public int getBaseType() throws SQLException + { + return _array.getBaseType(); + } + + public String getBaseTypeName() throws SQLException + { + return _array.getBaseTypeName(); + } + + public ArrayDescriptor getDescriptor() throws SQLException + { + return _array.getDescriptor(); + } + + /* array accessor methods */ + public java.math.BigDecimal[] getArray() throws SQLException + { + return (java.math.BigDecimal[]) _array.getObjectArray(); + } + + public java.math.BigDecimal[] getArray(long index, int count) throws SQLException + { + return (java.math.BigDecimal[]) _array.getObjectArray(index, count); + } + + public void setArray(java.math.BigDecimal[] a) throws SQLException + { + _array.setObjectArray(a); + } + + public void setArray(java.math.BigDecimal[] a, long index) throws SQLException + { + _array.setObjectArray(a, index); + } + + public java.math.BigDecimal getElement(long index) throws SQLException + { + return (java.math.BigDecimal) _array.getObjectElement(index); + } + + 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; + } + } + +} Property changes on: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoOrdinateArray.java ___________________________________________________________________ Added: svn:keywords + Id Added: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoPointType.java =================================================================== --- trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoPointType.java (rev 0) +++ trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoPointType.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -0,0 +1,161 @@ +/* + * + * 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.STRUCT; +import oracle.jpub.runtime.MutableStruct; + +/** + * This class was generated by oracle jpub. + * + * @see OracleSdoGeometryDataType + * @author cl...@e-... + * @author Last changed by: $Author$ + * @version $Revision$ $Date$ + * @since ? + */ +public class OracleSdoPointType implements ORAData, ORADataFactory +{ + public static final String _SQL_NAME = "MDSYS.SDO_POINT_TYPE"; + public static final int _SQL_TYPECODE = OracleTypes.STRUCT; + + protected MutableStruct _struct; + + protected static int[] _sqlType = { 2,2,2 }; + protected static ORADataFactory[] _factory = new ORADataFactory[3]; + protected static final OracleSdoPointType _OracleSdoPointTypeFactory = new OracleSdoPointType(); + + public static ORADataFactory getORADataFactory() + { return _OracleSdoPointTypeFactory; } + /* constructors */ + protected void _init_struct(boolean init) + { if (init) _struct = new MutableStruct(new Object[3], _sqlType, _factory); } + public OracleSdoPointType() + { _init_struct(true); } + public OracleSdoPointType(java.math.BigDecimal x, java.math.BigDecimal y, java.math.BigDecimal z) throws SQLException + { _init_struct(true); + setX(x); + setY(y); + setZ(z); + } + + /* ORAData interface */ + public Datum toDatum(Connection c) throws SQLException + { + return _struct.toDatum(c, _SQL_NAME); + } + + + /* ORADataFactory interface */ + public ORAData create(Datum d, int sqlType) throws SQLException + { return create(null, d, sqlType); } + protected ORAData create(OracleSdoPointType o, Datum d, int sqlType) throws SQLException + { + if (d == null) return null; + if (o == null) o = new OracleSdoPointType(); + o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory); + return o; + } + /* accessor methods */ + public java.math.BigDecimal getX() throws SQLException + { return (java.math.BigDecimal) _struct.getAttribute(0); } + + public void setX(java.math.BigDecimal x) throws SQLException + { _struct.setAttribute(0, x); } + + + public java.math.BigDecimal getY() throws SQLException + { return (java.math.BigDecimal) _struct.getAttribute(1); } + + public void setY(java.math.BigDecimal y) throws SQLException + { _struct.setAttribute(1, y); } + + + public java.math.BigDecimal getZ() throws SQLException + { return (java.math.BigDecimal) _struct.getAttribute(2); } + + public void setZ(java.math.BigDecimal z) throws SQLException + { _struct.setAttribute(2, z); } + + public String toString() + { try { + return "MDSYS.SDO_POINT_TYPE" + "(" + + getX() + "," + + getY() + "," + + getZ() + + ")"; + } catch (Exception e) { return e.toString(); } + } + + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + + if ((obj == null) || (! obj.getClass().equals(this.getClass()))) + { + return false; + } + + OracleSdoPointType otherObject = (OracleSdoPointType) obj; + + try + { + return + OracleSdoHelper.objectsEqual(getX(), otherObject.getX()) && + OracleSdoHelper.objectsEqual(getY(), otherObject.getY()) && + OracleSdoHelper.objectsEqual(getZ(), otherObject.getZ()); + } + catch (SQLException ex) + { + return false; + } + } + + public int hashCode() + { + try + { + int hash = 7; + Object o; + o = getX(); + hash = 31 * hash + (null == o ? 0 : o.hashCode()); + o = getY(); + hash = 31 * hash + (null == o ? 0 : o.hashCode()); + o = getZ(); + hash = 31 * hash + (null == o ? 0 : o.hashCode()); + return hash; + } + catch (SQLException ex) + { + return 0; + } + } +} Property changes on: trunk/dbunit/src/java/org/dbunit/ext/oracle/OracleSdoPointType.java ___________________________________________________________________ Added: svn:keywords + Id Modified: trunk/dbunit/src/test/org/dbunit/dataset/datatype/StringDataTypeTest.java =================================================================== --- trunk/dbunit/src/test/org/dbunit/dataset/datatype/StringDataTypeTest.java 2009-12-01 07:21:06 UTC (rev 1123) +++ trunk/dbunit/src/test/org/dbunit/dataset/datatype/StringDataTypeTest.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -25,6 +25,7 @@ import org.dbunit.dataset.ITable; import java.sql.Types; +import java.sql.SQLException; /** * @author Manuel Laflamme @@ -133,26 +134,64 @@ } } + /** + * Return a bad clob that throws SQLException on all its operations. + */ + private Object getBadClob() + { + // need to use proxy / reflection to work arround Clob differences + // in jdk 1.4+ + java.lang.reflect.InvocationHandler alwaysThrowSqlExceptionHandler = + new java.lang.reflect.InvocationHandler() + { + public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) + throws Throwable + { + if ("toString".equals(method.getName())) + { + return this.toString(); + } + else if ("equals".equals(method.getName())) + { + return Boolean.FALSE; + } + throw new SQLException(); + } + }; + + return java.lang.reflect.Proxy.newProxyInstance( + java.sql.Clob.class.getClassLoader(), new Class[] { java.sql.Clob.class }, + alwaysThrowSqlExceptionHandler); + } + public void testTypeCastInvalid() throws Exception { Object[] values = { - new Object() + new Object() { public String toString() { return "ABC123";} }, + new Object() { public String toString() { return "XXXX";} }, + new Object() { public String toString() { return "X";} }, }; for (int i = 0; i < TYPES.length; i++) { for (int j = 0; j < values.length; j++) { - try - { - TYPES[i].typeCast(values[j]); - fail("Should throw TypeCastException"); - } - catch (TypeCastException e) - { - } + assertEquals(TYPES[i].typeCast(values[j]), values[j].toString()); } } + + Object badClob = getBadClob(); + for (int i = 0; i < TYPES.length; i++) + { + try + { + TYPES[i].typeCast(badClob); + fail("Should throw TypeCastException"); + } + catch (TypeCastException e) + { + } + } } public void testCompareEquals() throws Exception @@ -197,7 +236,7 @@ public void testCompareInvalid() throws Exception { Object[] values1 = { - new Object(), + getBadClob(), }; Object[] values2 = { null, Added: trunk/dbunit/src/test/org/dbunit/ext/oracle/OracleSdoGeometryDataTypeTest.java =================================================================== --- trunk/dbunit/src/test/org/dbunit/ext/oracle/OracleSdoGeometryDataTypeTest.java (rev 0) +++ trunk/dbunit/src/test/org/dbunit/ext/oracle/OracleSdoGeometryDataTypeTest.java 2009-12-01 20:49:33 UTC (rev 1124) @@ -0,0 +1,403 @@ +/* + * + * The DbUnit Database Testing Framework + * Copyright (C)2002-2004, 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 org.dbunit.database.ExtendedMockSingleRowResultSet; +import org.dbunit.dataset.datatype.AbstractDataTypeTest; +import org.dbunit.dataset.datatype.DataType; +import org.dbunit.dataset.datatype.TypeCastException; +import org.dbunit.dataset.ITable; + +import java.math.BigDecimal; +import java.sql.Types; + +/** + * @author + * @version + */ + +public class OracleSdoGeometryDataTypeTest extends AbstractDataTypeTest +{ + private final static DataType THIS_TYPE = OracleDataTypeFactory.ORACLE_SDO_GEOMETRY_TYPE; + + public OracleSdoGeometryDataTypeTest(String name) + { + super(name); + } + + /** + * + */ + public void testToString() throws Exception + { + assertEquals("name", "SDO_GEOMETRY", THIS_TYPE.toString()); + } + + /** + * + */ + public void testGetTypeClass() throws Exception + { + assertEquals("class", org.dbunit.ext.oracle.OracleSdoGeometry.class, THIS_TYPE.getTypeClass()); + } + + /** + * + */ + public void testIsNumber() throws Exception + { + assertEquals("is number", false, THIS_TYPE.isNumber()); + } + + public void testIsDateTime() throws Exception + { + assertEquals("is date/time", false, THIS_TYPE.isDateTime()); + } + + public void testTypeCast() throws Exception + { + Object[] values = { + null, + new OracleSdoGeometry(null, null, null, null, null), + new OracleSdoGeometry(new BigDecimal(123), null, null, null, null), + new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), null, null, null), + new OracleSdoGeometry(null, null, new OracleSdoPointType(null, null, null), null, null), + new OracleSdoGeometry(null, null, new OracleSdoPointType(new BigDecimal(1), new BigDecimal(2), new BigDecimal(3)), null, null), + new OracleSdoGeometry(null, null, null, new OracleSdoElemInfoArray(), null), + new OracleSdoGeometry(null, null, null, null, new OracleSdoOrdinateArray()), + new OracleSdoGeometry(new BigDecimal(123), new BigDecimal("45.6"), + new OracleSdoPointType(new BigDecimal("-1234.564"), new BigDecimal("5.3403"), new BigDecimal(57)), + new OracleSdoElemInfoArray( + new BigDecimal [] { new BigDecimal(10), new BigDecimal(9), new BigDecimal(8), new BigDecimal(7) } ), + new OracleSdoOrdinateArray( + new BigDecimal [] { new BigDecimal(6), new BigDecimal(5), new BigDecimal(4), new BigDecimal(3) } )), + "NULL", + " NULL ", + "sdo_geometry(123, null, null, null, null)", + "sdo_gEOMEtry(123, null, null, null, null)", + "mdsys.sdo_geometry(123, 45.6, null, null, null)", + "mdsys.sdo_geometry(123, 45.6, sdo_point_type(null,null,nul... [truncated message content] |