@Override
  public synchronized ServerCQ executeCq(final @NotNull String cqName,
      final @NotNull String queryString, final int cqState,
      final @NotNull ClientProxyMembershipID clientProxyId,
      final @Nullable CacheClientNotifier ccn,
      final boolean isDurable,
      final boolean manageEmptyRegions,
      @Nullable DataPolicy regionDataPolicy,
      final @NotNull Map<String, Integer> emptyRegionsMap)
      throws CqException, RegionNotFoundException, CqClosedException {
    if (!isServer()) {
      throw new IllegalStateException(
          String.format("Server side executeCq method is called on client. CqName : %s",
              cqName));
    }

    final String serverCqName = constructServerCqName(cqName, clientProxyId);
    final ServerCQImpl cQuery;

    // If this CQ is not yet registered in Server, register CQ.
    if (!isCqExists(serverCqName)) {
      cQuery = new ServerCQImpl(this, cqName, queryString, isDurable,
          constructServerCqName(cqName, clientProxyId));

      try {
        cQuery.registerCq(clientProxyId, ccn, cqState);
        if (manageEmptyRegions) {
          if (emptyRegionsMap.containsKey(cQuery.getBaseRegionName())) {
            regionDataPolicy = DataPolicy.EMPTY;
          }

          final CacheClientProxy proxy = getCacheClientProxy(clientProxyId, ccn);
          ccn.updateMapOfEmptyRegions(
              proxy.getRegionsWithEmptyDataPolicy(),
              cQuery.getBaseRegionName(), regionDataPolicy);
        }
      } catch (CqException cqe) {
        logger.info("Exception while registering CQ on server. CqName : {}",
            cQuery.getName());
        throw cqe;
      }

    } else {
      cQuery = (ServerCQImpl) getCq(serverCqName);
      resumeCQ(cqState, cQuery);
    }

    if (logger.isDebugEnabled()) {
      logger.debug("Successfully created CQ on the server. CqName : {}", cQuery.getName());
    }

    return cQuery;
  }
Executes the given CqQuery, if the CqQuery for that name is not there it registers the one and
executes. This is called on the Server.

@param manageEmptyRegions whether to update the 6.1 emptyRegions map held in the CCN
@param regionDataPolicy the data policy of the region associated with the query. This is only
       needed if manageEmptyRegions is true.
@param emptyRegionsMap map of empty regions.
@throws IllegalStateException if this is called at client side.
geode-cq/src/main/java/org/apache/geode/cache/query/cq/internal/CqServiceImpl.java