/** * Alters the supplied SQL to add paging, such as OFFSET-FETCH. * <p> * The default implementation calls {@link #getPaging(int, int)}. * <p> * The returned SQL must be end in a space if non-empty. * * @param selectToPage the SELECT statement to page, not null * @param offset the OFFSET amount, zero to start from the beginning * @param fetchLimit the FETCH/LIMIT amount, zero to fetch all * @return the updated SELECT, not null */ public String addPaging(String selectToPage, int offset, int fetchLimit) { return selectToPage + (selectToPage.endsWith(" ") ? "" : " ") + getPaging(offset, fetchLimit); }
@Override void toSQL(StringBuilder buf, SqlFragments fragments, SqlParams params, int[] loopIndex) { String var = applyLoopIndex(_variable, loopIndex); Object val = params.get(var); if (val == null) { buf.append("IS NULL "); } else { if (fragments.getConfig().isLikeWildcard(val.toString())) { buf.append("LIKE "); super.toSQL(buf, fragments, params, loopIndex); buf.append(fragments.getConfig().getLikeSuffix()); } else { buf.append("= "); super.toSQL(buf, fragments, params, loopIndex); } } }
ClassPathResource configResource = new ClassPathResource(type.getSimpleName() + "-" + config.getName() + ".elsql", type); return parse(config, baseResource, configResource);
/** * Applies the paging. * * @param selectToPage the contents of the enclosed block, not null * @param fragments the SQL fragments for context, not null * @param params the SQL arguments, not null */ String applyPaging(String selectToPage, SqlFragments fragments, SqlParams params) { int offset = extractVariableOrLiteral(params, _offsetVariable); int fetchLimit = extractVariableOrLiteral(params, _fetchVariable); return fragments.getConfig().addPaging(selectToPage, offset, fetchLimit == Integer.MAX_VALUE ? 0 : fetchLimit); }
URL configResource = type.getResource(type.getSimpleName() + "-" + config.getName() + ".elsql"); return parse(config, baseResource, configResource);
@Override void toSQL(StringBuilder buf, SqlFragments fragments, SqlParams params, int[] loopIndex) { int offset = extractVariableOrLiteral(params, _offsetVariable); int fetchLimit = extractVariableOrLiteral(params, _fetchVariable); buf.append(fragments.getConfig().getPaging(offset, fetchLimit == Integer.MAX_VALUE ? 0 : fetchLimit)); }