/** * INTERNAL: */ protected static void initializeFunctionOperators() { addOperator(notOperator()); addOperator(ascending()); addOperator(descending()); addOperator(as()); addOperator(nullsFirst()); addOperator(nullsLast()); addOperator(any()); addOperator(some()); addOperator(all()); addOperator(in()); addOperator(inSubQuery()); addOperator(notIn()); addOperator(notInSubQuery()); addOperator(coalesce()); addOperator(caseStatement()); addOperator(caseConditionStatement()); }
/** * INTERNAL: * Return if the operator is equal to the other. */ public boolean equals(Object object) { if (this == object) { return true; } if ((object == null) || (getClass() != object.getClass())) { return false; } ExpressionOperator operator = (ExpressionOperator) object; if (getSelector() == 0) { return Arrays.equals(getDatabaseStrings(), operator.getDatabaseStrings()); } else { return getSelector() == operator.getSelector(); } }
/** * INTERNAL: */ protected static void initializeAggregateFunctionOperators() { addOperator(count()); addOperator(sum()); addOperator(average()); addOperator(minimum()); addOperator(maximum()); addOperator(distinct()); }
/** * INTERNAL: */ protected static void initializeLogicalOperators() { addOperator(and()); addOperator(or()); addOperator(isNull()); addOperator(notNull()); }
/** * Print a debug representation of this operator. */ public String toString() { if ((getDatabaseStrings() == null) || (getDatabaseStrings().length == 0)) { //CR#... Print a useful name for the missing plaftorm operator. return "platform operator - " + getPlatformOperatorName(getSelector()); } else { return "operator " + getDatabaseStrings()[0]; } }
/** * INTERNAL: */ protected static void initializeFunctionOperators() { addOperator(notOperator()); addOperator(ascending()); addOperator(descending()); addOperator(any()); addOperator(some()); addOperator(all()); addOperator(in()); addOperator(inSubQuery()); addOperator(notIn()); addOperator(notInSubQuery()); addOperator(coalesce()); addOperator(caseStatement()); }
String name = (String) ExpressionOperator.getPlatformOperatorNames().get(op.getSelector()); functions.put(name.toLowerCase(), ((JpqlFunctionExpressionOperator) op).unwrap()); } else { int selector = op.getSelector(); functions.put("count", new ExpressionOperatorJpqlFunction(ExpressionOperator.count())); functions.put("sum", new ExpressionOperatorJpqlFunction(ExpressionOperator.sum())); functions.put("avg", new ExpressionOperatorJpqlFunction(ExpressionOperator.average())); functions.put("max", new ExpressionOperatorJpqlFunction(ExpressionOperator.maximum())); functions.put("min", new ExpressionOperatorJpqlFunction(ExpressionOperator.minimum())); functions.put("stddev", new ExpressionOperatorJpqlFunction(ExpressionOperator.standardDeviation())); functions.put("var", new ExpressionOperatorJpqlFunction(ExpressionOperator.variance()));
/** * INTERNAL: */ protected static void initializeRelationOperators() { addOperator(simpleRelation(Equal, "=", "equal")); addOperator(simpleRelation(NotEqual, "<>", "notEqual")); addOperator(simpleRelation(LessThan, "<", "lessThan")); addOperator(simpleRelation(LessThanEqual, "<=", "lessThanEqual")); addOperator(simpleRelation(GreaterThan, ">", "greaterThan")); addOperator(simpleRelation(GreaterThanEqual, ">=", "greaterThanEqual")); addOperator(like()); addOperator(likeEscape()); addOperator(notLike()); addOperator(notLikeEscape()); addOperator(between()); addOperator(exists()); addOperator(notExists()); }
/** * INTERNAL: * Return the hash-code based on the unique selector. */ public int hashCode() { return getSelector(); }
/** * INTERNAL: */ public void initializePlatformOperator(DatabasePlatform platform) { if (this.operator.isComplete()) { platformOperator = this.operator; return; } platformOperator = platform.getOperator(this.operator.getSelector()); if (platformOperator == null) { throw QueryException.invalidOperator(this.operator.toString()); } }
/** * INTERNAL: * For performance, special case printing two children, since it's by far the most common */ public void printDuo(Expression first, Expression second, ExpressionSQLPrinter printer) { // Certain functions don't allow binding on some platforms. if (printer.getPlatform().isDynamicSQLRequiredForFunctions() && !isBindingSupported()) { printer.getCall().setUsesBinding(false); } int dbStringIndex; if (isPrefix()) { printer.printString(getDatabaseStrings()[0]); dbStringIndex = 1; } else { dbStringIndex = 0; } first.printSQL(printer); if (dbStringIndex < getDatabaseStrings().length) { printer.printString(getDatabaseStrings()[dbStringIndex++]); } if (second != null) { second.printSQL(printer); if (dbStringIndex < getDatabaseStrings().length) { printer.printString(getDatabaseStrings()[dbStringIndex++]); } } }
if (printer.getPlatform().isDynamicSQLRequiredForFunctions() && !isBindingSupported()) { printer.getCall().setUsesBinding(false); if (isPrefix()) { printer.getWriter().write(getDatabaseStrings()[0]); dbStringIndex = 1; } else { if ((getSelector() == Ref) || ((getSelector() == Deref) && (item.isObjectExpression()))) { DatabaseTable alias = ((ObjectExpression)item).aliasForTable(((ObjectExpression)item).getDescriptor().getTables().firstElement()); printer.printString(alias.getNameDelimited(printer.getPlatform())); } else if ((getSelector() == Count) && (item.isExpressionBuilder())) { printer.printString("*"); } else if (getType() == FunctionOperator) { item.printSQLWithoutConversion(printer); } else { item.printSQL(printer); if (dbStringIndex < getDatabaseStrings().length) { printer.printString(getDatabaseStrings()[dbStringIndex++]);
private void addFunction(Map<Integer, ExpressionOperator> platformOperators, String name, JpqlFunction function, AbstractSession session, Map<Class<?>, String> classTypes) { ExpressionOperator operator = createOperator(name, function, session, classTypes); ExpressionOperator.registerOperator(operator.getSelector(), operator.getName()); ExpressionOperator.addOperator(operator); platformOperators.put(Integer.valueOf(operator.getSelector()), operator); }
if (mapping == null && this.attributeExpression.isFunctionExpression() && this.getResultType() == null){ FunctionExpression expression = ((FunctionExpression)this.attributeExpression); if (expression.getOperator().equals(ExpressionOperator.maximum()) || expression.getOperator().equals(ExpressionOperator.minimum())){ mapping = expression.getBaseExpression().getLeafMapping(query, query.getDescriptor(), query.getSession());
/** * ADVANCED: * Set the strings for this operator. */ public void printsAs(Vector dbStrings) { this.databaseStrings = new String[dbStrings.size()]; for (int i = 0; i < dbStrings.size(); i++) { getDatabaseStrings()[i] = (String)dbStrings.elementAt(i); } }
/** * INTERNAL: * Create a new expression. Optimized for the single argument case. */ public Expression newExpressionForArgument(Expression base, Object singleArgument) { if (singleArgument == null) { if (getSelector() == Equal) { return base.isNull(); } else if (getSelector() == NotEqual) { return base.notNull(); } } Expression node = createNode(); node.create(base, singleArgument, this); return node; }
/** * Print a debug representation of this operator. */ public String toString() { if ((getDatabaseStrings() == null) || (getDatabaseStrings().length == 0)) { //CR#... Print a useful name for the missing platform operator. return "platform operator - " + getPlatformOperatorName(this.selector); } else { return "operator " + Arrays.asList(getDatabaseStrings()); } }
@Override public void printCollection(Vector items, ExpressionSQLPrinter printer) { if (items.size() == 1 && items.get(0) instanceof QueryKeyExpression && "deleteTs".equals(((QueryKeyExpression) items.get(0)).getName())) { if (!CubaUtil.isSoftDeletion()) { try { printer.getWriter().write("(0=0)"); return; } catch (IOException e) { throw new RuntimeException(e); } } } super.printCollection(items, printer); } }
String attributeName = ((FunctionExpression) expression).getBaseExpression().getName(); SortDirection direction = SortDirection.ASCENDING; if (expression.getOperator().isOrderOperator()) { if (StringUtils .containsIgnoreCase(expression.getOperator().getDatabaseStrings()[0], "DESC")) { direction = SortDirection.DESCENDING;
/** * INTERNAL: * Initialize a mapping to the platform operator names for usage with exceptions. */ public static String getPlatformOperatorName(int operator) { String name = (String)getPlatformOperatorNames().get(Integer.valueOf(operator)); if (name == null) { name = String.valueOf(operator); } return name; }