private LinkedHashMap<String, LinkedHashSet<GBrowseTrackInfo>> getSubGbrowseTrack(
      List<SpanQueryResultRow> spanResults) {

    LinkedHashMap<String, LinkedHashSet<GBrowseTrackInfo>> subGTrack =
        new LinkedHashMap<String, LinkedHashSet<GBrowseTrackInfo>>();
    for (SpanQueryResultRow aRow : spanResults) {
      if (MetadataCache.getTracksByDccId(aRow.getSubDCCid()).size() > 0) {
        List<GBrowseTrack> trackList = MetadataCache.getTracksByDccId(aRow.getSubDCCid());
        LinkedHashSet<GBrowseTrackInfo> trackInfoList = new LinkedHashSet<GBrowseTrackInfo>();
        for (GBrowseTrack aTrack : trackList) {
          GBrowseTrackInfo aTrackInfo =
              new GBrowseTrackInfo(
                  aTrack.getOrganism(), aTrack.getTrack(),
                  aTrack.getSubTrack(), aTrack.getDCCid());
          trackInfoList.add(aTrackInfo);
        }
        subGTrack.put(aRow.getSubDCCid(), trackInfoList);
      }
    }

    return subGTrack;
  }
  /** The method to run all the queries. */
  @SuppressWarnings("rawtypes")
  private void queryExecutor() {

    // Use spanOverlapFullResultMap to store the data in the session
    @SuppressWarnings("unchecked")
    Map<String, Map<GenomicRegion, List<SpanQueryResultRow>>> spanOverlapFullResultMap =
        (Map<String, Map<GenomicRegion, List<SpanQueryResultRow>>>)
            request.getSession().getAttribute("spanOverlapFullResultMap");

    if (spanOverlapFullResultMap == null) {
      spanOverlapFullResultMap =
          new HashMap<String, Map<GenomicRegion, List<SpanQueryResultRow>>>();
    }

    Map<GenomicRegion, List<SpanQueryResultRow>> spanOverlapResultDisplayMap =
        Collections.synchronizedMap(new LinkedHashMap<GenomicRegion, List<SpanQueryResultRow>>());

    // GBrowse track
    @SuppressWarnings("unchecked")
    Map<String, Map<GenomicRegion, LinkedHashMap<String, LinkedHashSet<GBrowseTrackInfo>>>>
        gbrowseFullTrackMap =
            (HashMap<
                    String,
                    Map<GenomicRegion, LinkedHashMap<String, LinkedHashSet<GBrowseTrackInfo>>>>)
                request.getSession().getAttribute("gbrowseFullTrackMap");

    if (gbrowseFullTrackMap == null) {
      gbrowseFullTrackMap =
          new HashMap<
              String, Map<GenomicRegion, LinkedHashMap<String, LinkedHashSet<GBrowseTrackInfo>>>>();
    }

    Map<GenomicRegion, LinkedHashMap<String, LinkedHashSet<GBrowseTrackInfo>>> gbrowseTrackMap =
        Collections.synchronizedMap(
            new LinkedHashMap<
                GenomicRegion, LinkedHashMap<String, LinkedHashSet<GBrowseTrackInfo>>>());

    if (!spanOverlapFullResultMap.containsKey(spanUUIDString)) {
      spanOverlapFullResultMap.put(spanUUIDString, spanOverlapResultDisplayMap);
      request.getSession().setAttribute("spanOverlapFullResultMap", spanOverlapFullResultMap);

      gbrowseFullTrackMap.put(spanUUIDString, gbrowseTrackMap);
      request.getSession().setAttribute("gbrowseFullTrackMap", gbrowseFullTrackMap);

      try {
        Query q;
        for (GenomicRegion aSpan : spanList) {
          q = new Query();
          q.setDistinct(true);

          String chrPID = aSpan.getChr();
          Integer start = aSpan.getStart();
          Integer end = aSpan.getEnd();

          /*
          >>>>> TEST CODE <<<<<
          LOG.info("OrgName: " + orgName);
          LOG.info("chrPID: " + chrPID);
          LOG.info("start: " + start);
          LOG.info("end: " + end);
          LOG.info("FeatureTypes: " + ftKeys);
          LOG.info("Submissions: " + subKeys);
          >>>>> TEST CODE <<<<<
          */

          // DB tables
          QueryClass qcOrg = new QueryClass(Organism.class);
          QueryClass qcChr = new QueryClass(Chromosome.class);
          QueryClass qcFeature = new QueryClass(SequenceFeature.class);
          QueryClass qcLoc = new QueryClass(Location.class);
          QueryClass qcSubmission = new QueryClass(Submission.class);

          QueryField qfOrgName = new QueryField(qcOrg, "shortName");
          QueryField qfChrPID = new QueryField(qcChr, "primaryIdentifier");
          QueryField qfFeaturePID = new QueryField(qcFeature, "primaryIdentifier");
          QueryField qfFeatureId = new QueryField(qcFeature, "id");
          QueryField qfFeatureClass = new QueryField(qcFeature, "class");
          QueryField qfSubmissionTitle = new QueryField(qcSubmission, "title");
          QueryField qfSubmissionDCCid = new QueryField(qcSubmission, "DCCid");
          QueryField qfChr = new QueryField(qcChr, "primaryIdentifier");
          QueryField qfLocStart = new QueryField(qcLoc, "start");
          QueryField qfLocEnd = new QueryField(qcLoc, "end");

          q.addToSelect(qfFeatureId);
          q.addToSelect(qfFeaturePID);
          q.addToSelect(qfFeatureClass);
          q.addToSelect(qfChr);
          q.addToSelect(qfLocStart);
          q.addToSelect(qfLocEnd);
          q.addToSelect(qfSubmissionDCCid);
          q.addToSelect(qfSubmissionTitle);

          q.addFrom(qcChr);
          q.addFrom(qcOrg);
          q.addFrom(qcFeature);
          q.addFrom(qcLoc);
          q.addFrom(qcSubmission);

          q.addToOrderBy(qfLocStart, "ascending");

          ConstraintSet constraints = new ConstraintSet(ConstraintOp.AND);

          q.setConstraint(constraints);

          // SequenceFeature.organism = Organism
          QueryObjectReference organism = new QueryObjectReference(qcFeature, "organism");
          ContainsConstraint ccOrg = new ContainsConstraint(organism, ConstraintOp.CONTAINS, qcOrg);
          constraints.addConstraint(ccOrg);

          // Organism.name = orgName
          SimpleConstraint scOrg =
              new SimpleConstraint(qfOrgName, ConstraintOp.EQUALS, new QueryValue(orgName));
          constraints.addConstraint(scOrg);

          // Location.feature = SequenceFeature
          QueryObjectReference locSubject = new QueryObjectReference(qcLoc, "feature");
          ContainsConstraint ccLocSubject =
              new ContainsConstraint(locSubject, ConstraintOp.CONTAINS, qcFeature);
          constraints.addConstraint(ccLocSubject);

          // Location.locatedOn = Chromosome
          QueryObjectReference locObject = new QueryObjectReference(qcLoc, "locatedOn");
          ContainsConstraint ccLocObject =
              new ContainsConstraint(locObject, ConstraintOp.CONTAINS, qcChr);
          constraints.addConstraint(ccLocObject);

          // Chromosome.primaryIdentifier = chrPID
          SimpleConstraint scChr =
              new SimpleConstraint(qfChrPID, ConstraintOp.EQUALS, new QueryValue(chrPID));
          constraints.addConstraint(scChr);

          // SequenceFeature.submissions = Submission
          QueryCollectionReference submission =
              new QueryCollectionReference(qcFeature, "submissions");
          ContainsConstraint ccSubmission =
              new ContainsConstraint(submission, ConstraintOp.CONTAINS, qcSubmission);
          constraints.addConstraint(ccSubmission);

          // SequenceFeature.class in a list
          constraints.addConstraint(new BagConstraint(qfFeatureClass, ConstraintOp.IN, ftKeys));
          // Submission.CCDid in a list
          constraints.addConstraint(new BagConstraint(qfSubmissionDCCid, ConstraintOp.IN, subKeys));

          OverlapRange overlapInput =
              new OverlapRange(new QueryValue(start), new QueryValue(end), locObject);
          OverlapRange overlapFeature =
              new OverlapRange(
                  new QueryField(qcLoc, "start"), new QueryField(qcLoc, "end"), locObject);
          OverlapConstraint oc =
              new OverlapConstraint(overlapInput, ConstraintOp.OVERLAPS, overlapFeature);
          constraints.addConstraint(oc);

          Results results = im.getObjectStore().execute(q);

          /*
          >>>>> TEST CODE <<<<<
          LOG.info("Query: " + q.toString());
          LOG.info("Result Size: " + results.size());
          LOG.info("Result >>>>> " + results);
          >>>>> TEST CODE <<<<<
          */

          List<SpanQueryResultRow> spanResults = new ArrayList<SpanQueryResultRow>();
          if (results == null || results.isEmpty()) {
            spanOverlapResultDisplayMap.put(aSpan, null);
            gbrowseTrackMap.put(aSpan, null);
          } else {
            for (Iterator<?> iter = results.iterator(); iter.hasNext(); ) {
              ResultsRow<?> row = (ResultsRow<?>) iter.next();

              SpanQueryResultRow aRow = new SpanQueryResultRow();
              aRow.setFeatureId((Integer) row.get(0));
              aRow.setFeaturePID((String) row.get(1));
              aRow.setFeatureClass(((Class) row.get(2)).getSimpleName());
              aRow.setChr((String) row.get(3));
              aRow.setStart((Integer) row.get(4));
              aRow.setEnd((Integer) row.get(5));
              aRow.setSubDCCid((String) row.get(6));
              aRow.setSubTitle((String) row.get(7));

              spanResults.add(aRow);
            }
            spanOverlapResultDisplayMap.put(aSpan, spanResults);
            gbrowseTrackMap.put(aSpan, getSubGbrowseTrack(spanResults)); // Gbrowse
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }