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); }
public static void processDynamicFilterParameters( final String sqlFragment, final ParameterContainer container, final HqlSqlWalker walker) { if (walker.getEnabledFilters().isEmpty() && (!hasDynamicFilterParam(sqlFragment)) && (!(hasCollectionFilterParam(sqlFragment)))) { return; } Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect(); String symbols = new StringBuffer() .append(ParserHelper.HQL_SEPARATORS) .append(dialect.openQuote()) .append(dialect.closeQuote()) .toString(); StringTokenizer tokens = new StringTokenizer(sqlFragment, symbols, true); StringBuffer result = new StringBuffer(); while (tokens.hasMoreTokens()) { final String token = tokens.nextToken(); if (token.startsWith(ParserHelper.HQL_VARIABLE_PREFIX)) { final String filterParameterName = token.substring(1); final String[] parts = LoadQueryInfluencers.parseFilterParameterName(filterParameterName); final FilterImpl filter = (FilterImpl) walker.getEnabledFilters().get(parts[0]); final Object value = filter.getParameter(parts[1]); final Type type = filter.getFilterDefinition().getParameterType(parts[1]); final String typeBindFragment = StringHelper.join( ",", ArrayHelper.fillArray( "?", type.getColumnSpan(walker.getSessionFactoryHelper().getFactory()))); final String bindFragment = (value != null && Collection.class.isInstance(value)) ? StringHelper.join( ",", ArrayHelper.fillArray(typeBindFragment, ((Collection) value).size())) : typeBindFragment; result.append(bindFragment); container.addEmbeddedParameter( new DynamicFilterParameterSpecification(parts[0], parts[1], type)); } else { result.append(token); } } container.setText(result.toString()); }