Examples of TypeCastException


Examples of org.dbunit.dataset.datatype.TypeCastException

        catch (SQLException e)
        {
            // JH_TODO: shouldn't freeTemporary be called in finally {} ?
            // It wasn't done like that in the original reflection-styled DbUnit code.
            freeTemporaryBlob(tempBlob);
            throw new TypeCastException(value, this, e);
        }
        catch (IOException e)
        {
            freeTemporaryBlob(tempBlob);
            throw new TypeCastException(value, this, e);
        }

        return tempBlob;
    }
View Full Code Here

Examples of org.dbunit.dataset.datatype.TypeCastException

        {
            tempBlob.freeTemporary();
        }
        catch (SQLException e)
        {
            throw new TypeCastException("Error freeing Oracle BLOB", e);
        }
    }
View Full Code Here

Examples of org.dbunit.dataset.datatype.TypeCastException

                                  statement.addValue(table.getValue(row,
                                          column.getColumnName()), column.getDataType());
                }
                                catch (TypeCastException e)
                {
                          throw new TypeCastException("Error casting value for table '" + table.getTableMetaData().getTableName()
                              +"' and column '" + column.getColumnName() + "'", e);
                }
                            }
                        }
                        statement.addBatch();
View Full Code Here

Examples of org.dbunit.dataset.datatype.TypeCastException

            closeMethod.invoke(tempClob, new Object[0]);
        }
        catch (IllegalAccessException e)
        {
            freeTemporaryClob(tempClob);
            throw new TypeCastException(value, this, e);
        }
        catch (NoSuchMethodException e)
        {
            freeTemporaryClob(tempClob);
            throw new TypeCastException(value, this, e);
        }
        catch (IOException e)
        {
            freeTemporaryClob(tempClob);
            throw new TypeCastException(value, this, e);
        }
        catch (InvocationTargetException e)
        {
            freeTemporaryClob(tempClob);
            throw new TypeCastException(value, this, e.getTargetException());
        }
        catch (ClassNotFoundException e)
        {
            freeTemporaryClob(tempClob);
            throw new TypeCastException(value, this, e);
        }

        return tempClob;
    }
View Full Code Here

Examples of org.dbunit.dataset.datatype.TypeCastException

            Method freeTemporaryMethod = tempClob.getClass().getMethod("freeTemporary", new Class[0]);
            freeTemporaryMethod.invoke(tempClob, new Object[0]);
        }
        catch (NoSuchMethodException e)
        {
            throw new TypeCastException("Error freeing Oracle CLOB", e);
        }
        catch (IllegalAccessException e)
        {
            throw new TypeCastException("Error freeing Oracle CLOB", e);
        }
        catch (InvocationTargetException e)
        {
            throw new TypeCastException("Error freeing Oracle CLOB", e.getTargetException());
        }
    }
View Full Code Here

Examples of org.dbunit.dataset.datatype.TypeCastException

            closeMethod.invoke(tempBlob, new Object[0]);
        }
        catch (IllegalAccessException e)
        {
            freeTemporaryBlob(tempBlob);
            throw new TypeCastException(value, this, e);
        }
        catch (NoSuchMethodException e)
        {
            freeTemporaryBlob(tempBlob);
            throw new TypeCastException(value, this, e);
        }
        catch (IOException e)
        {
            freeTemporaryBlob(tempBlob);
            throw new TypeCastException(value, this, e);
        }
        catch (InvocationTargetException e)
        {
            freeTemporaryBlob(tempBlob);
            throw new TypeCastException(value, this, e);
        }
        catch (ClassNotFoundException e)
        {
            freeTemporaryBlob(tempBlob);
            throw new TypeCastException(value, this, e);
        }

        return tempBlob;
    }
View Full Code Here

Examples of org.dbunit.dataset.datatype.TypeCastException

            Method freeTemporaryMethod = tempBlob.getClass().getMethod("freeTemporary", new Class[0]);
            freeTemporaryMethod.invoke(tempBlob, new Object[0]);
        }
        catch (NoSuchMethodException e)
        {
            throw new TypeCastException("Error freeing Oracle BLOB", e);
        }
        catch (IllegalAccessException e)
        {
            throw new TypeCastException("Error freeing Oracle BLOB", e);
        }
        catch (InvocationTargetException e)
        {
            throw new TypeCastException("Error freeing Oracle BLOB", e.getTargetException());
        }
    }
View Full Code Here

Examples of org.dbunit.dataset.datatype.TypeCastException

            Method formOfUse = statementClass.getMethod("setFormOfUse", new Class[] { Integer.TYPE, Short.TYPE });
            formOfUse.invoke(statement, new Object[] { new Integer(column), FORM_NCHAR });
        }
        catch (IllegalAccessException e)
        {
            throw new TypeCastException(value, this, e);
        }
        catch (NoSuchMethodException e)
        {
            throw new TypeCastException(value, this, e);
        }
        catch (InvocationTargetException e)
        {
            throw new TypeCastException(value, this, e.getTargetException());
        }
        catch (ClassNotFoundException e)
        {
            throw new TypeCastException(value, this, e);
        }
       
        statement.setObject(column, getClob(value, statement.getConnection()));
    }
View Full Code Here

Examples of org.g4studio.core.exception.TypeCastException

      if ("Double".equals(type) || "java.lang.Double".equals(type))
        try {
          Number tempNum = getNf(locale).parse(str);
          return new Double(tempNum.doubleValue());
        } catch (ParseException e) {
          throw new TypeCastException("Could not convert " + str + " to " + type + ": ",
              e);
        }
      if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type))
        try {
          BigDecimal retBig = new BigDecimal(str);
          int iscale = str.indexOf(".");
          int keylen = str.length();
          if (iscale > -1) {
            iscale = keylen - (iscale + 1);
            return retBig.setScale(iscale, 5);
          } else {
            return retBig.setScale(0, 5);
          }
        } catch (Exception e) {
          throw new TypeCastException("Could not convert " + str + " to " + type + ": ",
              e);
        }
      if ("Float".equals(type) || "java.lang.Float".equals(type))
        try {
          Number tempNum = getNf(locale).parse(str);
          return new Float(tempNum.floatValue());
        } catch (ParseException e) {
          throw new TypeCastException("Could not convert " + str + " to " + type + ": ",
              e);
        }
      if ("Long".equals(type) || "java.lang.Long".equals(type))
        try {
          NumberFormat nf = getNf(locale);
          nf.setMaximumFractionDigits(0);
          Number tempNum = nf.parse(str);
          return new Long(tempNum.longValue());
        } catch (ParseException e) {
          throw new TypeCastException("Could not convert " + str + " to " + type + ": ",
              e);
        }
      if ("Integer".equals(type) || "java.lang.Integer".equals(type))
        try {
          NumberFormat nf = getNf(locale);
          nf.setMaximumFractionDigits(0);
          Number tempNum = nf.parse(str);
          return new Integer(tempNum.intValue());
        } catch (ParseException e) {
          throw new TypeCastException("Could not convert " + str + " to " + type + ": ",
              e);
        }
      if ("Date".equals(type) || "java.sql.Date".equals(type)) {
        if (format == null || format.length() == 0)
          try {
            return Date.valueOf(str);
          } catch (Exception e) {
            try {
              DateFormat df = null;
              if (locale != null)
                df = DateFormat.getDateInstance(3, locale);
              else
                df = DateFormat.getDateInstance(3);
              java.util.Date fieldDate = df.parse(str);
              return new Date(fieldDate.getTime());
            } catch (ParseException e1) {
              throw new TypeCastException("Could not convert " + str + " to " + type
                  + ": ", e);
            }
          }
        try {
          SimpleDateFormat sdf = new SimpleDateFormat(format);
          java.util.Date fieldDate = sdf.parse(str);
          return new Date(fieldDate.getTime());
        } catch (ParseException e) {
          throw new TypeCastException("Could not convert " + str + " to " + type + ": ",
              e);
        }
      }
      if ("Timestamp".equals(type) || "java.sql.Timestamp".equals(type)) {
        if (str.length() == 10)
          str = str + " 00:00:00";
        if (format == null || format.length() == 0)
          try {
            return Timestamp.valueOf(str);
          } catch (Exception e) {
            try {
              DateFormat df = null;
              if (locale != null)
                df = DateFormat.getDateTimeInstance(3, 3, locale);
              else
                df = DateFormat.getDateTimeInstance(3, 3);
              java.util.Date fieldDate = df.parse(str);
              return new Timestamp(fieldDate.getTime());
            } catch (ParseException e1) {
              throw new TypeCastException("Could not convert " + str + " to " + type
                  + ": ", e);
            }
          }
        try {
          SimpleDateFormat sdf = new SimpleDateFormat(format);
          java.util.Date fieldDate = sdf.parse(str);
          return new Timestamp(fieldDate.getTime());
        } catch (ParseException e) {
          throw new TypeCastException("Could not convert " + str + " to " + type + ": ",
              e);
        }
      } else {
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
      }
    }
    if (obj instanceof BigDecimal) {
      fromType = "BigDecimal";
      BigDecimal bigD = (BigDecimal) obj;
      if ("String".equals(type))
        return getNf(locale).format(bigD.doubleValue());
      if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type))
        return obj;
      if ("Double".equals(type))
        return new Double(bigD.doubleValue());
      if ("Float".equals(type))
        return new Float(bigD.floatValue());
      if ("Long".equals(type))
        return new Long(Math.round(bigD.doubleValue()));
      if ("Integer".equals(type))
        return new Integer((int) Math.round(bigD.doubleValue()));
      else
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
    }
    if (obj instanceof Double) {
      fromType = "Double";
      Double dbl = (Double) obj;
      if ("String".equals(type) || "java.lang.String".equals(type))
        return getNf(locale).format(dbl.doubleValue());
      if ("Double".equals(type) || "java.lang.Double".equals(type))
        return obj;
      if ("Float".equals(type) || "java.lang.Float".equals(type))
        return new Float(dbl.floatValue());
      if ("Long".equals(type) || "java.lang.Long".equals(type))
        return new Long(Math.round(dbl.doubleValue()));
      if ("Integer".equals(type) || "java.lang.Integer".equals(type))
        return new Integer((int) Math.round(dbl.doubleValue()));
      if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type))
        return new BigDecimal(dbl.toString());
      else
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
    }
    if (obj instanceof Float) {
      fromType = "Float";
      Float flt = (Float) obj;
      if ("String".equals(type))
        return getNf(locale).format(flt.doubleValue());
      if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type))
        return new BigDecimal(flt.doubleValue());
      if ("Double".equals(type))
        return new Double(flt.doubleValue());
      if ("Float".equals(type))
        return obj;
      if ("Long".equals(type))
        return new Long(Math.round(flt.doubleValue()));
      if ("Integer".equals(type))
        return new Integer((int) Math.round(flt.doubleValue()));
      else
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
    }
    if (obj instanceof Long) {
      fromType = "Long";
      Long lng = (Long) obj;
      if ("String".equals(type) || "java.lang.String".equals(type))
        return getNf(locale).format(lng.longValue());
      if ("Double".equals(type) || "java.lang.Double".equals(type))
        return new Double(lng.doubleValue());
      if ("Float".equals(type) || "java.lang.Float".equals(type))
        return new Float(lng.floatValue());
      if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type))
        return new BigDecimal(lng.toString());
      if ("Long".equals(type) || "java.lang.Long".equals(type))
        return obj;
      if ("Integer".equals(type) || "java.lang.Integer".equals(type))
        return new Integer(lng.intValue());
      else
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
    }
    if (obj instanceof Integer) {
      fromType = "Integer";
      Integer intgr = (Integer) obj;
      if ("String".equals(type) || "java.lang.String".equals(type))
        return getNf(locale).format(intgr.longValue());
      if ("Double".equals(type) || "java.lang.Double".equals(type))
        return new Double(intgr.doubleValue());
      if ("Float".equals(type) || "java.lang.Float".equals(type))
        return new Float(intgr.floatValue());
      if ("BigDecimal".equals(type) || "java.math.BigDecimal".equals(type)) {
        String str = intgr.toString();
        BigDecimal retBig = new BigDecimal(intgr.doubleValue());
        int iscale = str.indexOf(".");
        int keylen = str.length();
        if (iscale > -1) {
          iscale = keylen - (iscale + 1);
          return retBig.setScale(iscale, 5);
        } else {
          return retBig.setScale(0, 5);
        }
      }
      if ("Long".equals(type) || "java.lang.Long".equals(type))
        return new Long(intgr.longValue());
      if ("Integer".equals(type) || "java.lang.Integer".equals(type))
        return obj;
      else
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
    }
    if (obj instanceof Date) {
      fromType = "Date";
      Date dte = (Date) obj;
      if ("String".equals(type) || "java.lang.String".equals(type))
        if (format == null || format.length() == 0) {
          return dte.toString();
        } else {
          SimpleDateFormat sdf = new SimpleDateFormat(format);
          return sdf.format(new java.util.Date(dte.getTime()));
        }
      if ("Date".equals(type) || "java.sql.Date".equals(type))
        return obj;
      if ("Time".equals(type) || "java.sql.Time".equals(type))
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
      if ("Timestamp".equals(type) || "java.sql.Timestamp".equals(type))
        return new Timestamp(dte.getTime());
      else
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
    }
    if (obj instanceof Timestamp) {
      fromType = "Timestamp";
      Timestamp tme = (Timestamp) obj;
      if ("String".equals(type) || "java.lang.String".equals(type))
        if (format == null || format.length() == 0) {
          return (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(tme).toString();
        } else {
          SimpleDateFormat sdf = new SimpleDateFormat(format);
          return sdf.format(new java.util.Date(tme.getTime()));
        }
      if ("Date".equals(type) || "java.sql.Date".equals(type))
        return new Date(tme.getTime());
      if ("Time".equals(type) || "java.sql.Time".equals(type))
        return new Time(tme.getTime());
      if ("Timestamp".equals(type) || "java.sql.Timestamp".equals(type))
        return obj;
      else
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
    }
    if (obj instanceof Boolean) {
      fromType = "Boolean";
      Boolean bol = (Boolean) obj;
      if ("Boolean".equals(type) || "java.lang.Boolean".equals(type))
        return bol;
      if ("String".equals(type) || "java.lang.String".equals(type))
        return bol.toString();
      if ("Integer".equals(type) || "java.lang.Integer".equals(type)) {
        if (bol.booleanValue())
          return new Integer(1);
        else
          return new Integer(0);
      } else {
        throw new TypeCastException("Conversion from " + fromType + " to " + type
            + " not currently supported");
      }
    }
    if ("String".equals(type) || "java.lang.String".equals(type))
      return obj.toString();
    else
      throw new TypeCastException("Conversion from " + obj.getClass().getName() + " to "
          + type + " not currently supported");
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.