private void addJoinNodes(QueryNode query, JoinSequence join, FromElement fromElement) {
    JoinFragment joinFragment =
        join.toJoinFragment(
            walker.getEnabledFilters(),
            fromElement.useFromFragment()
                || fromElement.isDereferencedBySuperclassOrSubclassProperty(),
            fromElement.getWithClauseFragment(),
            fromElement.getWithClauseJoinAlias());

    String frag = joinFragment.toFromFragmentString();
    String whereFrag = joinFragment.toWhereFragmentString();

    // If the from element represents a JOIN_FRAGMENT and it is
    // a theta-style join, convert its type from JOIN_FRAGMENT
    // to FROM_FRAGMENT
    if (fromElement.getType() == JOIN_FRAGMENT
        && (join.isThetaStyle() || StringHelper.isNotEmpty(whereFrag))) {
      fromElement.setType(FROM_FRAGMENT);
      fromElement
          .getJoinSequence()
          .setUseThetaStyle(true); // this is used during SqlGenerator processing
    }

    // If there is a FROM fragment and the FROM element is an explicit, then add the from part.
    if (fromElement.useFromFragment() /*&& StringHelper.isNotEmpty( frag )*/) {
      String fromFragment = processFromFragment(frag, join).trim();
      LOG.debugf("Using FROM fragment [%s]", fromFragment);
      processDynamicFilterParameters(fromFragment, fromElement, walker);
    }

    syntheticAndFactory.addWhereFragment(joinFragment, whereFrag, query, fromElement, walker);
  }
Exemplo n.º 2
0
 private void addJoin(JoinSequence joinSequence, QueryTranslatorImpl q) throws QueryException {
   // JoinFragment fromClause = q.createJoinFragment(true);
   // fromClause.addJoins( join.toJoinFragment().toFromFragmentString(), StringHelper.EMPTY_STRING
   // );
   q.addFromJoinOnly(pathExpressionParser.getName(), joinSequence);
   try {
     addToCurrentJoin(
         joinSequence.toJoinFragment(q.getEnabledFilters(), true).toWhereFragmentString());
   } catch (MappingException me) {
     throw new QueryException(me);
   }
 }
Exemplo n.º 3
0
  private void mergeJoins(JoinFragment ojf) throws MappingException, QueryException {

    Iterator iter = joins.entrySet().iterator();
    while (iter.hasNext()) {
      Map.Entry me = (Map.Entry) iter.next();
      String name = (String) me.getKey();
      JoinSequence join = (JoinSequence) me.getValue();
      join.setSelector(
          new JoinSequence.Selector() {
            public boolean includeSubclasses(String alias) {
              boolean include = returnedTypes.contains(alias) && !isShallowQuery();
              return include;
            }
          });

      if (typeMap.containsKey(name)) {
        ojf.addFragment(join.toJoinFragment(enabledFilters, true));
      } else if (collections.containsKey(name)) {
        ojf.addFragment(join.toJoinFragment(enabledFilters, true));
      } else {
        // name from a super query (a bit inelegant that it shows up here)
      }
    }
  }
Exemplo n.º 4
0
 public static String createCollectionSubquery(
     JoinSequence joinSequence, Map enabledFilters, String[] columns) {
   try {
     JoinFragment join = joinSequence.toJoinFragment(enabledFilters, true);
     return new StringBuilder("select ")
         .append(StringHelper.join(", ", columns))
         .append(" from ")
         .append(join.toFromFragmentString().substring(2)) // remove initial ", "
         .append(" where ")
         .append(join.toWhereFragmentString().substring(5)) // remove initial " and "
         .toString();
   } catch (MappingException me) {
     throw new QueryException(me);
   }
 }
  public void token(String token, QueryTranslatorImpl q) throws QueryException {

    if (token != null) path.append(token);

    String alias = q.getPathAlias(path.toString());
    if (alias != null) {
      reset(q); // reset the dotcount (but not the path)
      currentName = alias; // after reset!
      currentPropertyMapping = q.getPropertyMapping(currentName);
      if (!ignoreInitialJoin) {
        JoinSequence ojf = q.getPathJoin(path.toString());
        try {
          joinSequence.addCondition(
              ojf.toJoinFragment(q.getEnabledFilters(), true)
                  .toWhereFragmentString()); // after reset!
        } catch (MappingException me) {
          throw new QueryException(me);
        }
        // we don't need to worry about any condition in the ON clause
        // here (toFromFragmentString), since anything in the ON condition
        // is already applied to the whole query
      }
    } else if (".".equals(token)) {
      dotcount++;
    } else {
      if (dotcount == 0) {
        if (!continuation) {
          if (!q.isName(token)) throw new QueryException("undefined alias: " + token);
          currentName = token;
          currentPropertyMapping = q.getPropertyMapping(currentName);
        }
      } else if (dotcount == 1) {
        if (currentName != null) {
          currentProperty = token;
        } else if (collectionName != null) {
          // processCollectionProperty(token, q.getCollectionPersister(collectionRole),
          // collectionName);
          continuation = false;
        } else {
          throw new QueryException("unexpected");
        }
      } else { // dotcount>=2

        // Do the corresponding RHS
        Type propertyType = getPropertyType();

        if (propertyType == null) {
          throw new QueryException("unresolved property: " + path);
        }

        if (propertyType.isComponentType()) {
          dereferenceComponent(token);
        } else if (propertyType.isEntityType()) {
          if (!isCollectionValued()) dereferenceEntity(token, (EntityType) propertyType, q);
        } else if (propertyType.isCollectionType()) {
          dereferenceCollection(token, ((CollectionType) propertyType).getRole(), q);

        } else {
          if (token != null) throw new QueryException("dereferenced: " + path);
        }
      }
    }
  }