/** * Parses the top-level named sections. */ private void parseNamedSections() { ContainerSqlFragment containerFragment = new ContainerSqlFragment(); parseContainerSection(containerFragment, _lines.listIterator(), -1); }
@Override public String toString() { return getFragments().toString(); }
@Override void toSQL(StringBuilder buf, SqlFragments fragments, SqlParams params, int[] loopIndex) { int oldLen = buf.length(); buf.append("WHERE "); int newLen = buf.length(); super.toSQL(buf, fragments, params, loopIndex); if (buf.length() == newLen) { buf.setLength(oldLen); } }
/** * Parse VALUE tag. * <p> * This tag can appear anywhere in a line. * The text before is treated as simple text. * The text after is parsed. * * @param container the container to add to, not null * @param line the line to parse, not null */ private void parseValueTag(ContainerSqlFragment container, Line line) { Line[] split = line.split(line.lineTrimmed().indexOf("@VALUE")); parseLine(container, split[0]); Line lineStartingAtTag = split[1]; Matcher matcher = VALUE_PATTERN.matcher(lineStartingAtTag.lineTrimmed()); if (matcher.matches() == false) { throw new IllegalArgumentException("@VALUE found with invalid format: " + line); } String followingSpaces = matcher.group(2); Line subLine = lineStartingAtTag.splitRemainder(matcher.start(3)); boolean followWithSpace = (followingSpaces != null && followingSpaces.length() > 0) || subLine.lineTrimmed().isEmpty(); ValueSqlFragment valueFragment = new ValueSqlFragment(matcher.group(1), followWithSpace); container.addFragment(valueFragment); parseLine(container, subLine); }
container.addFragment(pagingFragment);
/** * Parse INCLUDE tag. * <p> * This tag can appear anywhere in a line. * It substitutes the entire content of the named section in at this point. * The text before is treated as simple text. * The text after is parsed. * * @param container the container to add to, not null * @param line the line to parse, not null */ private void parseIncludeTag(ContainerSqlFragment container, Line line) { Line[] split = line.split(line.lineTrimmed().indexOf("@INCLUDE")); parseLine(container, split[0]); String trimmed = split[1].lineTrimmed(); Matcher matcher = INCLUDE_PATTERN.matcher(trimmed); if (matcher.matches() == false) { throw new IllegalArgumentException("@INCLUDE found with invalid format: " + line); } IncludeSqlFragment includeFragment = new IncludeSqlFragment(matcher.group(1)); container.addFragment(includeFragment); Line subLine = split[1].splitRemainder(matcher.start(2)); parseLine(container, subLine); }
@Override void toSQL(StringBuilder buf, SqlFragments fragments, SqlParams params, int[] loopIndex) { int oldLen = buf.length(); super.toSQL(buf, fragments, params, loopIndex); int newLen = buf.length(); String select = buf.substring(oldLen, newLen); if (select.startsWith("SELECT ")) { buf.setLength(oldLen); buf.append(applyPaging(select, fragments, params)); } }
container.addFragment(pagingFragment);
@Override void toSQL(StringBuilder buf, SqlFragments fragments, SqlParams params, int[] loopIndex) { // find loop size int size = extractSize(params); // loop int[] childLoopIndex = Arrays.copyOf(loopIndex, loopIndex.length + 1); for (int i = 0; i < size; i++) { StringBuilder part = new StringBuilder(); childLoopIndex[childLoopIndex.length - 1] = i; super.toSQL(part, fragments, params, childLoopIndex); int joinIndex = part.indexOf("@LOOPJOIN "); if (joinIndex >= 0) { if (i >= (size - 1)) { part.setLength(joinIndex); } else { part.delete(joinIndex, joinIndex + 10); } } buf.append(part); } }
container.addFragment(textFragment); container.addFragment(textFragment);
: new EqualsSqlFragment(variable); container.addFragment(operatorFragment); operatorFragment.addFragment(contentTextFragment);
throw new IllegalArgumentException("@NAME found with no subsequent indented lines: " + line); container.addFragment(nameFragment); _namedFragments.put(nameFragment.getName(), nameFragment); throw new IllegalArgumentException("@PAGING found with no subsequent indented lines: " + line); container.addFragment(whereFragment); throw new IllegalArgumentException("@WHERE found with no subsequent indented lines: " + line); container.addFragment(whereFragment); throw new IllegalArgumentException("@AND found with no subsequent indented lines: " + line); container.addFragment(andFragment); throw new IllegalArgumentException("@OR found with no subsequent indented lines: " + line); container.addFragment(orFragment); throw new IllegalArgumentException("@IF found with no subsequent indented lines: " + line); container.addFragment(ifFragment); throw new IllegalArgumentException("@LOOP found with no subsequent indented lines: " + line); container.addFragment(loopFragment);