public QuerySelect copy() { QuerySelect copy = new QuerySelect( dialect ); copy.joins = this.joins.copy(); copy.select.append( this.select.toString() ); copy.where.append( this.where.toString() ); copy.groupBy.append( this.groupBy.toString() ); copy.orderBy.append( this.orderBy.toString() ); copy.having.append( this.having.toString() ); copy.comment = this.comment; copy.distinct = this.distinct; return copy; }
/** * Adds another join fragment to this one. * * @param ojf The other join fragment */ public void addFragment(JoinFragment ojf) { if ( ojf.hasThetaJoins() ) { hasThetaJoins = true; } addJoins( ojf.toFromFragmentString(), ojf.toWhereFragmentString() ); }
public static String createCollectionSubquery( JoinSequence joinSequence, Map enabledFilters, String[] columns) { try { JoinFragment join = joinSequence.toJoinFragment( enabledFilters, true ); return "select " + String.join( ", ", columns ) + " from " + join.toFromFragmentString().substring( 2 ) + " where " + join.toWhereFragmentString().substring( 5 ); } catch (MappingException me) { throw new QueryException( me ); } } }
/** * Adds a join, with an additional ON clause fragment * * @param tableName The name of the table to be joined * @param alias The alias to apply to the joined table * @param fkColumns The names of the columns which reference the joined table * @param pkColumns The columns in the joined table being referenced * @param joinType The type of join * @param on The additional ON fragment */ public void addJoin(String tableName, String alias, String[][] fkColumns, String[] pkColumns, JoinType joinType, String on) { if ( fkColumns.length > 1 ) { throw new UnsupportedOperationException( "The join fragment does not support multiple foreign key columns: " + getClass() ); } addJoin( tableName, alias, fkColumns[0], pkColumns, joinType, on ); }
@Override public String whereJoinFragment(String alias, boolean innerJoin, boolean includeSubclasses) { // NOTE : Not calling createJoin here is just a performance optimization return getSubclassTableSpan() == 1 ? "" : createJoin( alias, innerJoin, includeSubclasses, Collections.emptySet() ).toWhereFragmentString(); }
@Override public String fromJoinFragment(String alias, boolean innerJoin, boolean includeSubclasses) { // NOTE : Not calling createJoin here is just a performance optimization return getSubclassTableSpan() == 1 ? "" : createJoin( alias, innerJoin, includeSubclasses, Collections.emptySet() ).toFromFragmentString(); }
private void addSubclassJoins( JoinFragment joinFragment, String alias, Joinable joinable, boolean innerJoin, boolean includeSubclassJoins, Set<String> treatAsDeclarations) { final boolean include = includeSubclassJoins && isIncluded( alias ); joinFragment.addJoins( joinable.fromJoinFragment( alias, innerJoin, include, treatAsDeclarations ), joinable.whereJoinFragment( alias, innerJoin, include, treatAsDeclarations ) ); }
if ( !fromElement.useWhereFragment() && !joinFragment.hasThetaJoins() ) { return;
public boolean hasFilterCondition() { return joinFragment.hasFilterCondition(); }
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() { @Override public boolean includeSubclasses(String alias) { return returnedTypes.contains( alias ) && !isShallowQuery(); } } ); if ( typeMap.containsKey( name ) ) { ojf.addFragment( join.toJoinFragment( enabledFilters, true ) ); } else if ( collections.containsKey( name ) ) { ojf.addFragment( join.toJoinFragment( enabledFilters, true ) ); } } }
buf.append( "distinct " ); String from = joins.toFromFragmentString(); if ( from.startsWith( "," ) ) { from = from.substring( 1 ); .append( from ); String outerJoinsAfterWhere = joins.toWhereFragmentString().trim(); String whereConditions = where.toString().trim(); boolean hasOuterJoinsAfterWhere = outerJoinsAfterWhere.length() > 0;
private void addJoin(String tableName, String alias, String concreteAlias, String[] fkColumns, String[] pkColumns, JoinType joinType, String on) { if ( !useThetaStyleInnerJoins || joinType != JoinType.INNER_JOIN ) { JoinFragment jf = dialect.createOuterJoinFragment(); jf.addJoin( tableName, alias, fkColumns, pkColumns, joinType, on ); addFragment( jf ); } else { addCrossJoin( tableName, alias ); addCondition( concreteAlias, fkColumns, pkColumns ); addCondition( on ); } }
@Override public String whereJoinFragment( String alias, boolean innerJoin, boolean includeSubclasses, Set<String> treatAsDeclarations) { // NOTE : Not calling createJoin here is just a performance optimization return getSubclassTableSpan() == 1 ? "" : createJoin( alias, innerJoin, includeSubclasses, treatAsDeclarations ).toWhereFragmentString(); }
@Override public String fromJoinFragment( String alias, boolean innerJoin, boolean includeSubclasses, Set<String> treatAsDeclarations) { // NOTE : Not calling createJoin here is just a performance optimization return getSubclassTableSpan() == 1 ? "" : createJoin( alias, innerJoin, includeSubclasses, treatAsDeclarations ).toFromFragmentString(); }
private void addExtraJoins(JoinFragment joinFragment, String alias, Joinable joinable, boolean innerJoin) { boolean include = isIncluded( alias ); joinFragment.addJoins( joinable.fromJoinFragment( alias, innerJoin, include ), joinable.whereJoinFragment( alias, innerJoin, include ) ); }
return; else if ( !fromElement.useWhereFragment() && !joinFragment.hasThetaJoins() ) { return;
public boolean hasFilterCondition() { return joinFragment.hasFilterCondition(); }
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) } } }
/** * Adds another join fragment to this one. * * @param ojf The other join fragment */ public void addFragment(JoinFragment ojf) { if ( ojf.hasThetaJoins() ) { hasThetaJoins = true; } addJoins( ojf.toFromFragmentString(), ojf.toWhereFragmentString() ); }