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;
 }
 public Collection getIndexes() {
   ArrayList allIndexes = new ArrayList();
   Iterator rootRegions = cache.rootRegions().iterator();
   while (rootRegions.hasNext()) {
     Region region = (Region) rootRegions.next();
     Collection indexes = getIndexes(region);
     if (indexes != null) allIndexes.addAll(indexes);
     Iterator subRegions = region.subregions(true).iterator();
     while (subRegions.hasNext()) {
       indexes = getIndexes((Region) subRegions.next());
       if (indexes != null) allIndexes.addAll(indexes);
     }
   }
   return allIndexes;
 }
 /**
  * Asif : Gets an exact match index ( match level 0)
  *
  * @param regionPath String containing the region name
  * @param definitions An array of String objects containing canonicalized definitions of
  *     RuntimeIterators. A Canonicalized definition of a RuntimeIterator is the canonicalized
  *     expression obtainded from its underlying collection expression.
  * @param indexType IndexType object which can be either of type RangeIndex or PrimaryKey Index
  * @param indexedExpression CompiledValue containing the path expression on which index needs to
  *     be created
  * @param context ExecutionContext
  * @return IndexData object
  * @throws NameResolutionException
  * @throws TypeMismatchException
  * @throws AmbiguousNameException
  */
 public IndexData getIndex(
     String regionPath,
     String[] definitions,
     IndexType indexType,
     CompiledValue indexedExpression,
     ExecutionContext context)
     throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
   Region region = cache.getRegion(regionPath);
   if (region == null) {
     return null;
   }
   IndexManager indexManager = IndexUtils.getIndexManager(region, true);
   IndexData indexData = indexManager.getIndex(indexType, definitions, indexedExpression, context);
   return indexData;
 }
  public void removeIndexes() {
    if (pool != null) {
      throw new UnsupportedOperationException(
          "Index Operation is not supported on the Server Region.");
    }

    Iterator rootRegions = cache.rootRegions().iterator();
    while (rootRegions.hasNext()) {
      Region region = (Region) rootRegions.next();
      Iterator subRegions = region.subregions(true).iterator();
      while (subRegions.hasNext()) {
        removeIndexes((Region) subRegions.next());
      }
      removeIndexes(region);
    }
  }
 /**
  * Asif: Gets a best match index which is available. An index with match level equal to 0 is the
  * best index to use as it implies that the query from clause iterators belonging to the region
  * exactly match the index from clause iterators ( the difference in the relative positions of the
  * iterators do not matter). A match level less than 0 means that number of iteratots in the index
  * resultset is more than that present in the query from clause and hence index resultset will
  * need a cutdown. A match level greater than 0 means that there definitely is atleast one
  * iterator in the query from clause which is more than the index from clause iterators & hence
  * definitely expansion of index results will be needed. Pls note that a match level greater than
  * 0 does not imply that index from clause does not have an extra iterator in it , too. Hence a
  * match level greater than 0 will definitely mean expansion of index results but may also require
  * a cut down of results . The order of preference is match level 0 , less than 0 and lastly
  * greater than 0
  *
  * @param regionPath String containing the region name
  * @param definitions An array of String objects containing canonicalized definitions of
  *     RuntimeIterators. A Canonicalized definition of a RuntimeIterator is the canonicalized
  *     expression obtainded from its underlying collection expression.
  * @param indexType IndexType object which can be either of type RangeIndex or PrimaryKey Index
  * @param indexedExpression CompiledValue representing the path expression on which index needs to
  *     be created
  * @param context ExecutionContext object
  * @return IndexData object
  * @throws NameResolutionException
  * @throws TypeMismatchException
  * @throws AmbiguousNameException
  */
 public IndexData getBestMatchIndex(
     String regionPath,
     String definitions[],
     IndexType indexType,
     CompiledValue indexedExpression,
     ExecutionContext context)
     throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
   Region region = cache.getRegion(regionPath);
   if (region == null) {
     return null;
   }
   // return getBestMatchIndex(region, indexType, definitions,
   // indexedExpression);
   IndexManager indexManager = IndexUtils.getIndexManager(region, false);
   if (indexManager == null) {
     return null;
   }
   return indexManager.getBestMatchIndex(indexType, definitions, indexedExpression, context);
 }
 /** @return CqService */
 public CqService getCqService() throws CqException {
   CqService service = cache.getCqService();
   service.start();
   return service;
 }
 /** Close the CQ Service after clean up if any. */
 public void closeCqService() {
   cache.getCqService().close();
 }