-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted shared code into StageUtil
and restored original Stage ordering.
- Loading branch information
Showing
6 changed files
with
97 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
cayenne/src/main/java/org/apache/cayenne/access/translator/select/StageUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.apache.cayenne.access.translator.select; | ||
|
||
import java.sql.Types; | ||
|
||
import org.apache.cayenne.exp.parser.ASTAggregateFunctionCall; | ||
import org.apache.cayenne.query.Ordering; | ||
|
||
public class StageUtil | ||
{ | ||
private static final int[] UNSUPPORTED_DISTINCT_TYPES = { | ||
Types.BLOB, | ||
Types.CLOB, | ||
Types.NCLOB, | ||
Types.LONGVARCHAR, | ||
Types.LONGNVARCHAR, | ||
Types.LONGVARBINARY | ||
}; | ||
|
||
private static boolean isUnsupportedForDistinct(int type) { | ||
for (int unsupportedDistinctType : UNSUPPORTED_DISTINCT_TYPES) { | ||
if (unsupportedDistinctType == type) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
static boolean isDistinct(TranslatorContext context) { | ||
// explicit suppressing of distinct | ||
if(context.getMetadata().isSuppressingDistinct()) { | ||
context.setDistinctSuppression(true); | ||
return false; | ||
} | ||
|
||
// query forcing distinct or query have joins (qualifier or prefetch) | ||
if(!context.getQuery().isDistinct() && !context.getTableTree().hasToManyJoin()) { | ||
return false; | ||
} | ||
|
||
// unsuitable jdbc type for distinct clause | ||
for(ResultNodeDescriptor node : context.getResultNodeList()) { | ||
// TODO: make it per adapter rather than one-for-all | ||
if(isUnsupportedForDistinct(node.getJdbcType())) { | ||
context.setDistinctSuppression(true); | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
static boolean hasAggregate(TranslatorContext context) { | ||
if(context.getQuery().getHavingQualifier() != null) { | ||
return true; | ||
} | ||
|
||
for(ResultNodeDescriptor resultNode : context.getResultNodeList()) { | ||
if(resultNode.isAggregate()) { | ||
return true; | ||
} | ||
} | ||
|
||
if(context.getQuery().getOrderings() != null) { | ||
for(Ordering ordering : context.getQuery().getOrderings()) { | ||
if(ordering.getSortSpec() instanceof ASTAggregateFunctionCall) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters