/** * 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); }
/** * Returns a copy of this bundle with a different configuration. * <p> * This does not reload the underlying resources. * * @param config the new config, not null * @return a bundle with the config updated, not null */ public ElSqlBundle withConfig(ElSqlConfig config) { return new ElSqlBundle(_fragments.withConfig(config)); }
@Override void toSQL(StringBuilder buf, SqlFragments fragments, SqlParams params, int[] loopIndex) { String key = _includeKey; if (key.startsWith(":")) { String var = extractVariableName(key); if (params.contains(var)) { key = params.get(var).toString(); } } NameSqlFragment unit = fragments.getFragment(key); unit.toSQL(buf, fragments, params, loopIndex); }
@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)); }
@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 { buf.append("= "); super.toSQL(buf, fragments, params, loopIndex); } }
/** * Returns a copy of this bundle with a different configuration. * <p> * This does not reload the underlying resources. * * @param config the new config, not null * @return a bundle with the config updated, not null */ public ElSql withConfig(ElSqlConfig config) { return new ElSql(_fragments.withConfig(config)); }
/** * Parse the input returning the named sections. * * @return the map of named sections, keyed by name, not null */ Map<String, NameSqlFragment> parse() { rejectTabs(); parseNamedSections(); return _namedFragments; }
/** * Parses the top-level named sections. */ private void parseNamedSections() { ContainerSqlFragment containerFragment = new ContainerSqlFragment(); parseContainerSection(containerFragment, _lines.listIterator(), -1); }
@Override void toSQL(StringBuilder buf, SqlFragments fragments, SqlParams params, int[] loopIndex) { String var = applyLoopIndex(_valueVariable, loopIndex); Object value = params.get(var); if (value != null) { buf.append(value); if (_followWithSpace) { buf.append(' '); } } }
/** * Gets the configuration object. * * @return the config, not null */ public ElSqlConfig getConfig() { return _fragments.getConfig(); }
/** * Creates an instance. * * @param variable the variable to base the Operator on, not null */ OperatorSqlFragment(String variable) { _variable = extractVariableName(variable); }
@Override public String toString() { return "Line " + lineNumber(); } }
/** * Creates an instance. * * @param valueVariable the value variable, not null * @param followWithSpace whether to follow by a space */ ValueSqlFragment(String valueVariable, boolean followWithSpace) { _valueVariable = extractVariableName(valueVariable); _followWithSpace = followWithSpace; }
@Override void toSQL(StringBuilder buf, SqlFragments fragments, SqlParams params, int[] loopIndex) { for (SqlFragment fragment : _fragments) { fragment.toSQL(buf, fragments, params, loopIndex); } }
/** * Returns a copy of this bundle with a different configuration. * <p> * This does not reload the underlying resources. * * @param config the new config, not null * @return a bundle with the config updated, not null */ SqlFragments withConfig(ElSqlConfig config) { return new SqlFragments(_map, config); }
/** * Creates an instance. * * @param variable the variable to determine whether to include the AND on, not null * @param matchValue the value to match, null to match on existence */ ConditionalSqlFragment(String variable, String matchValue) { _variable = extractVariableName(variable); _matchValue = matchValue; }
/** * Gets the configuration object. * * @return the config, not null */ public ElSqlConfig getConfig() { return _fragments.getConfig(); }