@Override public void render(FunctionRenderContext context) { context.addChunk("concat("); context.addArgument(0); for (int i = 1; i < context.getArgumentsSize(); i++) { context.addChunk(","); context.addArgument(i); } context.addChunk(")"); }
@Override public void render(FunctionRenderContext context) { if (context.getArgumentsSize() > 1) { throw new IllegalArgumentException("The EMBEDDING_VIEW macro allows maximally one argument: <expression>!"); } context.addChunk("NULL"); } }
/** * Binds the values to the underlying {@link FunctionRenderContext}. */ public void build() { String[] chunks = template.chunks; Integer[] parameterIndices = template.parameterIndices; for (int i = 0; i < chunks.length; i++) { context.addChunk(chunks[i]); if (i < parameterIndices.length) { int parameterIndex = parameterIndices[i]; Object boundValue = boundValues[parameterIndex]; if (boundValue instanceof Integer) { context.addArgument((Integer) boundValue); } else { context.addChunk(boundValue.toString()); } } } } }
@Override public void render(FunctionRenderContext context) { if (context.getArgumentsSize() > 1) { throw new IllegalArgumentException("The VIEW_ROOT macro allows maximally one argument: <expression>!"); if (context.getArgumentsSize() > 0) { if (viewRootExpression != null) { String firstArgument = context.getArgument(0); if (viewRootIdPath.startsWith(firstArgument) && (viewRootIdPath.length() == firstArgument.length() || firstArgument.charAt(viewRootIdPath.length()) == '.')) { context.addChunk(viewRootExpression); context.addChunk("."); context.addChunk(getViewRootIdPath()); } else { String alias; context.addChunk(alias); context.addChunk("."); context.addArgument(0); if (viewRootIdPath.equals(context.getArgument(0))) { context.addChunk(":"); context.addChunk(getIdParamName()); } else { String alias = addViewRootNode(); this.nonIdUsed = true; context.addChunk(alias); context.addChunk("."); context.addArgument(0);
@Override public void render(FunctionRenderContext functionRenderContext) { if (functionRenderContext.getArgumentsSize() == 0) { throw new RuntimeException("The " + type + " function needs at least one argument <sub_query>! args=" + functionRenderContext); List<String> operands = new ArrayList<String>(functionRenderContext.getArgumentsSize()); List<OrderByElement> orderByElements = new ArrayList<OrderByElement>(0); String limit = null; String offset = null; for (int i = 0; i < functionRenderContext.getArgumentsSize(); i++) { String argument = functionRenderContext.getArgument(i); StringBuilder sqlSb = new StringBuilder(size + functionRenderContext.getArgumentsSize() * 12); dbmsDialect.appendSet(sqlSb, type, true, operands, orderByElements, limit, offset); functionRenderContext.addChunk(sqlSb.toString());
protected Count getCount(FunctionRenderContext context) { if (context.getArgumentsSize() == 0) { throw new RuntimeException("The " + FUNCTION_NAME + " function needs at least one argument!"); } boolean distinct = false; int startIndex = 0; String maybeDistinct = context.getArgument(0); if (("'" + DISTINCT_QUALIFIER + "'").equalsIgnoreCase(maybeDistinct)) { distinct = true; startIndex++; } // Hibernate puts the columns for embeddables into a single string, so we have to count items List<String> expressions = new ArrayList<>(context.getArgumentsSize()); for (int i = startIndex; i < context.getArgumentsSize(); i++) { expressions.addAll(SqlUtils.getExpressionItems(context.getArgument(i))); } if (expressions.isEmpty()) { throw new RuntimeException("The " + AbstractCountFunction.FUNCTION_NAME + " function needs at least one expression to count! args=" + context); } return new Count(distinct, expressions); }
@Override public void render(FunctionRenderContext context) { if (context.getArgumentsSize() != 1) { throw new RuntimeException("The second function needs exactly one argument <datetime>! args=" + context); } renderDiff(context); }
protected void renderLimitOnly(FunctionRenderContext functionRenderContext) { StringBuilder sqlSb = getSql(functionRenderContext); dbmsDialect.appendExtendedSql(sqlSb, DbmsStatementType.SELECT, true, false, null, functionRenderContext.getArgument(1), null, null, null); functionRenderContext.addChunk(sqlSb.toString()); }
private static StringBuilder getSql(FunctionRenderContext functionRenderContext) { String subquery = functionRenderContext.getArgument(0); if (startsWithIgnoreCase(subquery, "(select")) { int endIndex = subquery.length() - (subquery.charAt(subquery.length() - 1) == ')' ? 1 : 0); return new StringBuilder(subquery.length() - 2).append(subquery, 1, endIndex); } return new StringBuilder(subquery); }
@Override public void render(FunctionRenderContext context) { context.addArgument(0); } }
@Override public void render(FunctionRenderContext context) { String operator = context.getArgument(0); context.addChunk(getLeftmostChunk()); List<String> elements = new ArrayList<>(context.getArgumentsSize() - 1); for (int argIdx = 1; argIdx < context.getArgumentsSize(); argIdx++) { String caseWhenExpression = context.getArgument(argIdx); int end = rowValueArity * 2; context.addChunk(parts[0]); for (int i = 2; i < end; i += 2) { context.addChunk(", "); context.addChunk(parts[i]); context.addChunk(") " + operator + " ("); context.addChunk(parts[1]); for (int i = 3; i < end; i += 2) { context.addChunk(", "); context.addChunk(parts[i]); context.addChunk(getRightmostChunk());
@Override public void render(FunctionRenderContext context) { context.addChunk("COUNT(*)"); }
/** * Binds the values to the underlying {@link FunctionRenderContext}. */ public void build() { String[] chunks = template.chunks; Integer[] parameterIndices = template.parameterIndices; for (int i = 0; i < chunks.length; i++) { context.addChunk(chunks[i]); if (i < parameterIndices.length) { int parameterIndex = parameterIndices[i]; Object boundValue = boundValues[parameterIndex]; if (boundValue instanceof Integer) { context.addArgument((Integer) boundValue); } else { context.addChunk(boundValue.toString()); } } } } }
@Override public void render(FunctionRenderContext context) { if (context.getArgumentsSize() > 1) { throw new IllegalArgumentException("The VIEW_ROOT macro allows maximally one argument: <expression>!"); } context.addChunk("NULL"); } }
@Override public void render(FunctionRenderContext context) { if (context.getArgumentsSize() != 2) { throw new RuntimeException("The page position function needs exactly two arguments <base_query> and <entity_id>! args=" + context); } String subquery = context.getArgument(0); String subqueryStart = "(select "; int fromIndex; if (!startsWithIgnoreCase(subquery, subqueryStart)) { throw new IllegalArgumentException("Expected a subquery as the second parameter but was: " + subquery); } else if ((fromIndex = subquery.toLowerCase().indexOf(" from ")) < 1) { throw new IllegalArgumentException("Expected a subquery as the second parameter but was: " + subquery); } String id = subquery.substring(subqueryStart.length(), fromIndex); if (id.indexOf(',') > -1) { throw new IllegalArgumentException("Expected a subquery with a simple id but it was composite: " + subquery); } int dotIndex = id.indexOf('.'); if (dotIndex < 0) { throw new IllegalArgumentException("Expected that the id is fully qualified but it isn't: " + id); } String idName = id.substring(dotIndex + 1); renderPagePosition(context, idName); }
@Override public void render(FunctionRenderContext context) { if (context.getArgumentsSize() != 2) { throw new RuntimeException("The " + functionName + " function needs exactly two arguments <start_datetime> and <end_datetime>! args=" + context); } renderDiff(context); }
protected void renderLimitOffset(FunctionRenderContext functionRenderContext) { StringBuilder sqlSb = getSql(functionRenderContext); if (limitIncludesOffset) { // Careful, parameters are not supported in this case as that would require parameter rewriting or something like that String limit = functionRenderContext.getArgument(1); String offset = functionRenderContext.getArgument(2); if (limit.contains("?") || offset.contains("?")) { throw new IllegalArgumentException("Limit and offset in subquery can not be a parameter!"); } Integer limitValue = Integer.parseInt(limit); Integer offsetValue = Integer.parseInt(offset); dbmsDialect.appendExtendedSql(sqlSb, DbmsStatementType.SELECT, true, false, null, Integer.toString(limitValue + offsetValue), offset, null, null); } else { dbmsDialect.appendExtendedSql(sqlSb, DbmsStatementType.SELECT, true, false, null, functionRenderContext.getArgument(1), functionRenderContext.getArgument(2), null, null); } functionRenderContext.addChunk(sqlSb.toString()); }
@Override protected void renderDiff(FunctionRenderContext context) { boolean firstContains = context.getArgument(0).contains("?"); if (firstContains && context.getArgument(0).length() != 1) { throw new IllegalArgumentException("Only simple parameters or expressions are allowed because of a needed reordering in SQL which is otherwise not possible! Expressions ['" + context.getArgument(0) + "', '" + context.getArgument(1) + "'] do not comply!"); } if (firstContains) { paramRenderer.start(context).addArgument(0).build(); } else { // Reuse the expression multiple times renderer.start(context).addArgument(0).build(); } } }
@Override public void render(FunctionRenderContext context) { context.addArgument(0); }