private Region getRegionFromPath(String imports, String fromClause)
     throws RegionNotFoundException {
   QCompiler compiler = new QCompiler();
   if (imports != null) {
     compiler.compileImports(imports);
   }
   List list = compiler.compileFromClause(fromClause);
   CompiledValue cv =
       QueryUtils.obtainTheBottomMostCompiledValue(
           ((CompiledIteratorDef) list.get(0)).getCollectionExpr());
   String regionPath = null;
   if (cv.getType() == OQLLexerTokenTypes.RegionPath) {
     regionPath = ((CompiledRegion) cv).getRegionPath();
   } else {
     throw new RegionNotFoundException(
         LocalizedStrings
             .DefaultQueryService_DEFAULTQUERYSERVICECREATEINDEXFIRST_ITERATOR_OF_INDEX_FROM_CLAUSE_DOES_NOT_EVALUATE_TO_A_REGION_PATH_THE_FROM_CLAUSE_USED_FOR_INDEX_CREATION_IS_0
             .toLocalizedString(fromClause));
   }
   Region region = cache.getRegion(regionPath);
   if (region == null) {
     throw new RegionNotFoundException(
         LocalizedStrings.DefaultQueryService_REGION_0_NOT_FOUND_FROM_1.toLocalizedString(
             new Object[] {regionPath, fromClause}));
   }
   return region;
 }
Exemplo n.º 2
0
 public static Object nvl(CompiledValue arg1, CompiledValue arg2, ExecutionContext context)
     throws FunctionDomainException, TypeMismatchException, NameResolutionException,
         QueryInvocationTargetException {
   Object value = arg1.evaluate(context);
   if (value == null) {
     return arg2.evaluate(context);
   }
   return value;
 }
Exemplo n.º 3
0
  public static Date to_date(CompiledValue cv1, CompiledValue cv2, ExecutionContext context)
      throws FunctionDomainException, TypeMismatchException, NameResolutionException,
          QueryInvocationTargetException {
    Object value1 = cv1.evaluate(context);
    Object value2 = cv2.evaluate(context);
    if (!(value1 instanceof String) || !(value2 instanceof String)) {
      throw new QueryInvalidException(
          LocalizedStrings
              .Functions_PARAMETERS_TO_THE_TO_DATE_FUNCTION_SHOULD_BE_STRICTLY_SIMPLE_STRINGS
              .toLocalizedString());
    }
    String dateStr = (String) value1;
    String format = (String) value2;
    Date dt = null;
    try {
      // Removed the following line so that to data format conforms to
      // SimpleDateFormat exactly (bug 39144)
      // format = ((format.replaceAll("Y", "y")).replaceAll("m", "M")).replaceAll("D", "d");

      /*if((format.indexOf("MM") == -1 && format.indexOf("M") == -1) || (format.
      indexOf("dd") == -1 && format.indexOf("d") == -1) || (format.indexOf("yyyy") ==
      -1 && format.indexOf("yy") == -1))
            {
              throw new QueryInvalidException("Malformed date format string");
            }
            if(format.indexOf("MMM") != -1 || format.indexOf("ddd") != -1 || format.in
      dexOf("yyyyy") != -1)
            {
              throw new QueryInvalidException("Malformed date format string");
            } */

      SimpleDateFormat sdf1 = new SimpleDateFormat(format);
      dt = sdf1.parse(dateStr);

    } catch (Exception ex) {
      throw new QueryInvalidException(
          LocalizedStrings.Functions_MALFORMED_DATE_FORMAT_STRING_AS_THE_FORMAT_IS_0
              .toLocalizedString(format),
          ex);
    }
    return dt;
  }