Package com.meidusa.amoeba.sqljep

Examples of com.meidusa.amoeba.sqljep.ParseException


    String chars = param3.toString();
    int length;
    try {
      length = getInteger(param2);
    } catch (ParseException e) {
      throw new ParseException(PARAM_EXCEPTION);
    }
    if (length == inputStr.length()) {
      return inputStr;
    }
    else if (length < inputStr.length()) {
View Full Code Here


      Comparable<?>  param1 = runtime.stack.pop();
      return new Comparable<?>[]{param1,param2};
    } else {
      // remove all parameters from stack and push null
      removeParams(runtime.stack, num);
      throw new ParseException(PARAMS_NUMBER+" for instr");
    }
  }
View Full Code Here

      return param1;
    }
    else if (param1 instanceof Boolean) {
      return ((Boolean)param1).booleanValue() ? 1 : 0;
    } else {
      throw new ParseException(FORMAT_EXCEPTION);
    }
  }
View Full Code Here

    }
    if (param1 instanceof Number) {
      return param1;
    }
    if (!(param1 instanceof String) || !(param2 instanceof String)) {
      throw new ParseException(WRONG_TYPE+"  to_number("+param1.getClass()+"+"+param2.getClass()+")");
    }
    //StringBuilder d = new StringBuilder((String)param1);
    try {
      OracleNumberFormat format = new OracleNumberFormat((String)param2);
      return (Comparable)format.parseObject((String)param1);
    } catch (java.text.ParseException e) {
      if (BaseJEP.debug) {
        e.printStackTrace();
      }
      throw new ParseException(e.getMessage());
    }
  }
View Full Code Here

      int day = ((Number)param2).intValue();
      cal.clear();
      cal.set(year, 0, day);
      return new java.sql.Date(cal.getTimeInMillis());
    }
    throw new ParseException(WRONG_TYPE+" makedate("+param1.getClass()+","+param2.getClass()+")");
  }
View Full Code Here

      Comparable<?>  param1 = runtime.stack.pop();
      return new Comparable<?>[]{param1,param2};
    } else {
      // remove all parameters from stack and push null
      removeParams(runtime.stack, num);
      throw new ParseException(PARAMS_NUMBER+" for trunc");
    }
  }
View Full Code Here

        date++;
      }
      cal.set(year, month, date);
      return new Timestamp(cal.getTimeInMillis());
    }
    throw new ParseException(WRONG_TYPE+" round("+param.getClass()+")");
  }
View Full Code Here

    if (param1 instanceof Number) {
      int scale;
      try {
        scale = getInteger(param2);
      } catch (ParseException e) {
        throw new ParseException(PARAM_EXCEPTION);
      }
      if (scale < 0) {
        return ZERO;
      }
      if (param1 instanceof BigDecimal) {    // BigInteger is not supported
        return ((BigDecimal)param1).setScale(scale, BigDecimal.ROUND_HALF_UP);
      }
      if (param1 instanceof Double || param1 instanceof Float) {
        double d = ((Number)param1).doubleValue();
        long mult = 1;
        for (int i = 0; i < scale; i++) {
          mult *= 10;
        }
        d *= mult;
        return (Math.round(d))/mult;
      }
      if (param1 instanceof Number) {    // Long, Integer, Short, Byte
        return param1;
      }
      throw new ParseException(WRONG_TYPE+" round("+param1.getClass()+","+param2.getClass()+")");
    }
    else if (param1 instanceof java.util.Date) {
      if (param2 instanceof String) {
        String s = (String)param2;
        java.util.Date d = (java.util.Date)param1;
        cal.setTimeInMillis(d.getTime());
        if (s.equalsIgnoreCase("CC") || s.equalsIgnoreCase("SCC")) {
          if (d instanceof java.sql.Time) {
            throw new ParseException(TIME_EXCEPTION);
          }
          int year = cal.get(YEAR);
          int year1 = (year/100)*100;
          if (year-year1 > 50) {
            year1 += 100;
          }
          cal.clear();
          cal.set(year1+1, 0, 1);
          return new Timestamp(cal.getTimeInMillis());
        }
        else if (s.equalsIgnoreCase("SYYYY") || s.equalsIgnoreCase("YYYY") || s.equalsIgnoreCase("YYY") ||
              s.equalsIgnoreCase("Y") || s.equalsIgnoreCase("YEAR") || s.equalsIgnoreCase("SYEAR")) {
          if (d instanceof java.sql.Time) {
            throw new ParseException(TIME_EXCEPTION);
          }
          int year = cal.get(YEAR);
          int month = cal.get(MONTH);
          if (month > 6) {
            year++;
          }
          cal.clear();
          cal.set(year, 0, 1);
          return new Timestamp(cal.getTimeInMillis());
        }
        else if (s.equalsIgnoreCase("IYYY") || s.equalsIgnoreCase("IY") || s.equalsIgnoreCase("I")) {
          throw new ParseException(NOT_IMPLIMENTED_EXCEPTION);
        }
        else if (s.equalsIgnoreCase("Q")) {
          if (d instanceof java.sql.Time) {
            throw new ParseException(TIME_EXCEPTION);
          }
          int year = cal.get(YEAR);
          int month = cal.get(MONTH);
          int q = (month/3)*3;
          if (month > q+1) {
            q++;
          }
          else if (month > q) {
            int day = cal.get(DAY_OF_MONTH);
            if (day > 15) {
              q++;
            }
          }
          cal.clear();
          cal.set(year, q, 1);
          return new Timestamp(cal.getTimeInMillis());
        }
        else if (s.equalsIgnoreCase("MONTH") || s.equalsIgnoreCase("MON") ||
              s.equalsIgnoreCase("MM") || s.equalsIgnoreCase("RM")) {
          if (d instanceof java.sql.Time) {
            throw new ParseException(TIME_EXCEPTION);
          }
          int year = cal.get(YEAR);
          int month = cal.get(MONTH);
          int day = cal.get(DAY_OF_MONTH);
          if (day > 15) {
            month++;
          }
          cal.clear();
          cal.set(year, month, 1);
          return new Timestamp(cal.getTimeInMillis());
        }
        else if (s.equalsIgnoreCase("WW")) {
          if (d instanceof java.sql.Time) {
            throw new ParseException(TIME_EXCEPTION);
          }
          int year = cal.get(YEAR);
          int month = cal.get(MONTH);
          int day = cal.get(DAY_OF_MONTH);
          int dw = cal.get(DAY_OF_WEEK);
          cal.clear();
          cal.set(year, 0, 1);
          int dayOfWeek = cal.get(DAY_OF_WEEK);
          int delta = (dw<dayOfWeek ? 7-(dayOfWeek-dw) : dw-dayOfWeek);
          if (delta > 2) {
            delta = delta-7;
          }
          cal.set(year, month, day-delta);
          return new Timestamp(cal.getTimeInMillis());
        }
        else if (s.equalsIgnoreCase("W")) {
          if (d instanceof java.sql.Time) {
            throw new ParseException(TIME_EXCEPTION);
          }
          int year = cal.get(YEAR);
          int month = cal.get(MONTH);
          int day = cal.get(DAY_OF_MONTH);
          int dw = cal.get(DAY_OF_WEEK);
          cal.clear();
          cal.set(year, month, 1);
          int dayOfWeek = cal.get(DAY_OF_WEEK);
          int delta = (dw<dayOfWeek ? 7-(dayOfWeek-dw) : dw-dayOfWeek);
          if (delta > 2) {
            delta = delta-7;
          }
          cal.set(year, month, day-delta);
          return new Timestamp(cal.getTimeInMillis());
        }
        else if (s.equalsIgnoreCase("IW")) {
          throw new ParseException(NOT_IMPLIMENTED_EXCEPTION);
        }
        else if (s.equalsIgnoreCase("DAY") || s.equalsIgnoreCase("DY") || s.equalsIgnoreCase("D")) {
          if (d instanceof java.sql.Time) {
            throw new ParseException(TIME_EXCEPTION);
          }
          int year = cal.get(YEAR);
          int month = cal.get(MONTH);
          int day = cal.get(DAY_OF_MONTH);
          int dw = cal.get(DAY_OF_WEEK);
          int delta = dw-cal.getFirstDayOfWeek();
          if (delta > 2) {
            delta = delta-7;
          }
          cal.clear();
          cal.set(year, month, day-delta);
          return new Timestamp(cal.getTimeInMillis());
        }
        else if (s.equalsIgnoreCase("HH") || s.equalsIgnoreCase("HH12") || s.equalsIgnoreCase("HH24")) {
          if (d instanceof java.sql.Date) {
            throw new ParseException(DATE_EXCEPTION);
          }
          int minute = cal.get(MINUTE);
          if (minute >= 30) {
            cal.get(HOUR_OF_DAY);
            cal.add(HOUR_OF_DAY, 1);
          }
          cal.set(MINUTE, 0);
          cal.set(SECOND, 0);
          cal.set(MILLISECOND, 0);
          return new Timestamp(cal.getTimeInMillis());
        }
        else if (s.equalsIgnoreCase("MI")) {
          if (d instanceof java.sql.Date) {
            throw new ParseException(DATE_EXCEPTION);
          }
          int second = cal.get(SECOND);
          if (second >= 30) {
            cal.get(MINUTE);
            cal.add(MINUTE, 1);
          }
          cal.set(SECOND, 0);
          cal.set(MILLISECOND, 0);
          return new Timestamp(cal.getTimeInMillis());
        } else {
          throw new ParseException(FORMAT_EXCEPTION);
        }
      }
    }
    throw new ParseException(WRONG_TYPE+" trunc("+param1.getClass()+","+param2.getClass()+")");
  }
View Full Code Here

      Comparable<?>  param1 = runtime.stack.pop();
      return new  Comparable<?>[]{param1,param2};
    } else {
      // remove all parameters from stack and push null
      removeParams(runtime.stack, num);
      throw new ParseException("Wrong number of parameters for instr");
    }
  }
View Full Code Here

      return null;
    }
    else if (param1 instanceof String) {
      return Timestamp.valueOf((String)param1);
    } else {
      throw new ParseException(FORMAT_EXCEPTION);
    }
  }
View Full Code Here

TOP

Related Classes of com.meidusa.amoeba.sqljep.ParseException

Copyright © 2018 www.massapicom. 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.