public String escapeForLike(String str) {
        final StringBuilder rv = new StringBuilder(str.length() + 3);
        for (int i = 0; i < str.length(); i++) {
            final char ch = str.charAt(i);
            if (ch == escape || ch == '%' || ch == '_') {
                rv.append(escape);
            }
            rv.append(ch);
        }
        return rv.toString();
    }
{@code TemplateFactory} is a factory for {@link Template} instances

@author tiwe
querydsl-core/src/main/java/com/querydsl/core/types/TemplateFactory.java