Package com.meidusa.amoeba.sqljep

Examples of com.meidusa.amoeba.sqljep.ParseException


      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


        try {
          return b.longValueExact();
        } catch (Exception e) {
        }
      } catch (Exception e) {
        throw new ParseException(e.getMessage());
      }
      return b;
    }
    if (param instanceof Double || param instanceof Float) {
      return ((Number)param).longValue();
    }
    if (param instanceof Number) {    // Long, Integer, Short, Byte
      return param;
    }
    if (param instanceof Date) {
      Date ts = (Date)param;
      cal.setTimeInMillis(ts.getTime());
      int year = cal.get(YEAR);
      int month = cal.get(MONTH);
      int date = cal.get(DATE);
      cal.clear();
      cal.set(year, month, date);
      return new Timestamp(cal.getTimeInMillis());
    }
    throw new ParseException(WRONG_TYPE+" trunc("+param.getClass()+")");
    }finally{
      if(param instanceof Comparative){
        param = ((Comparative)param).getValue();
      }
    }
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_DOWN);
      }
      else if (param1 instanceof Double || param1 instanceof Float) {
        double d = ((Number)param1).doubleValue();
        long mult = 1;
        for (int i = 0; i < scale; i++) {
          mult *= 10;
        }
        long l = (long)d*mult;
        return ((double)l)/mult;
      } else {
        return param1;      // Long, Integer, Short, Byte
      }
    }
    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);
          cal.clear();
          cal.set((year/100)*100, 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);
          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);
          cal.clear();
          cal.set(year, (month/3)*3, 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);
          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);
          cal.set(year, month, day - (dw<dayOfWeek ? 7-(dayOfWeek-dw) : dw-dayOfWeek));
          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);
          cal.set(year, month, day - (dw<dayOfWeek ? 7-(dayOfWeek-dw) : dw-dayOfWeek));
          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);
          cal.clear();
          cal.set(year, month, day-(dw-cal.getFirstDayOfWeek()));
          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);
          }
          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);
          }
          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,param3};
    } 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 l1 & l2;
       
      }
    }
     else {
      throw new ParseException(WRONG_TYPE+"  ("+param1.getClass()+"+"+param2.getClass()+")");
    }
  }
View Full Code Here

      }
      else if (param1 instanceof java.sql.Date) {
        java.sql.Date d = (java.sql.Date)param1;
        return new java.sql.Date(d.getTime()-days*86400000);
      } else {
        throw new ParseException();
      }
    } catch (ParseException e) {
      throw new ParseException(WRONG_TYPE+"  subDate("+param1.getClass()+","+param2.getClass()+")");
    }
  }
View Full Code Here

    if (param instanceof Timestamp || param instanceof java.sql.Time) {
      java.util.Date ts = (java.util.Date)param;
      cal.setTimeInMillis(ts.getTime());
      return new Integer(cal.get(MINUTE));
    }
    throw new ParseException(WRONG_TYPE+" minute("+param.getClass()+")");
  }
View Full Code Here

      return null;
    }
    try {
      if (param1 instanceof java.util.Date && param2 instanceof java.util.Date) {
        if (param1 instanceof Time || param2 instanceof Time) {
          throw new ParseException();
        }
        java.util.Date d1 = (java.util.Date)param1;
        java.util.Date d2 = (java.util.Date)param2;
        return new Long((d1.getTime()-d2.getTime())/86400000);
      } else {
        throw new ParseException();
      }
    } catch (ParseException e) {
      throw new ParseException(WRONG_TYPE+"  ("+param1.getClass()+"+"+param2.getClass()+")");
    }
  }
View Full Code Here

    if (param instanceof Timestamp || param instanceof Date) {
      java.util.Date ts = (java.util.Date)param;
      cal.setTimeInMillis(ts.getTime());
      return new Integer(cal.get(DAY_OF_YEAR));
    }
    throw new ParseException(WRONG_TYPE+" weekofyear("+param.getClass()+")");
  }
View Full Code Here

      cal.setTimeInMillis(d.getTime());
      int day = cal.getActualMaximum(DAY_OF_MONTH);
      cal.set(DATE, day);
      return new java.util.Date(cal.getTimeInMillis());
    } else {
      throw new ParseException(WRONG_TYPE+"  last_day("+param.getClass()+")");
    }
  }
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.