001package gudusoft.gsqlparser.pp2; 002 003import gudusoft.gsqlparser.EDbVendor; 004import gudusoft.gsqlparser.pp2.engine.Pp2Engine; 005 006/** 007 * Internal facade for the pp2 fault-tolerant SQL formatter. 008 * 009 * <p>This class is the integration target for every slice's tests. It is 010 * deliberately not exposed to callers — the public entry point is 011 * {@code FormatterFactory.pp2(...)}, added in slice S17 once the MVP is 012 * shippable (plan §4.2, §7.3/S17). 013 * 014 * <p><b>On parseable SQL this formatter is pp.</b> When the whole input 015 * parses, {@link Pp2Engine} calls {@code FormatterFactory.pp} on the whole 016 * document with these same options and returns pp's output byte for byte; 017 * pp2's own renderers run only over input pp could not format. The three-rung 018 * ladder (whole-document pp → per-region pp → pp2's renderers) is 019 * documented on {@code FormatterFactory.pp2(TGSqlParser, Pp2FormatOptions)} 020 * and in the {@code gudusoft.gsqlparser.pp2} package documentation. 021 * 022 * <p>Since slice S16, {@code format(...)} delegates to {@link Pp2Engine}. 023 * Before S16 it was an identity pass (Phase-0 contract, slice S4). 024 * 025 * <p>Lifecycle: {@code Pp2Formatter} carries no caller-visible state. Each 026 * {@code format(...)} call is independent. Callers may share an instance 027 * across threads (subject to their own {@code Pp2FormatOptions} discipline). 028 */ 029public final class Pp2Formatter { 030 031 private final Pp2Engine engine = new Pp2Engine(); 032 033 /** 034 * Format the given SQL using the default vendor ({@link EDbVendor#dbvoracle}) 035 * and default options ({@link Pp2FormatOptions#defaults()}). 036 * 037 * @throws NullPointerException if {@code sql} is null 038 */ 039 public Pp2FormatResult format(String sql) { 040 return format(sql, EDbVendor.dbvoracle, Pp2FormatOptions.defaults()); 041 } 042 043 /** 044 * Format the given SQL using the default vendor ({@link EDbVendor#dbvoracle}) 045 * and the supplied options. 046 * 047 * @throws NullPointerException if {@code sql} or {@code opts} is null 048 */ 049 public Pp2FormatResult format(String sql, Pp2FormatOptions opts) { 050 return format(sql, EDbVendor.dbvoracle, opts); 051 } 052 053 /** 054 * Format the given SQL using the supplied vendor and options. 055 * Delegates to {@link Pp2Engine#format(String, EDbVendor, Pp2FormatOptions)}. 056 * 057 * <p>{@code sql} need not parse. If it does parse as a whole, the returned 058 * text is {@code FormatterFactory.pp}'s output for it, unchanged; see the 059 * class documentation. 060 * 061 * @throws NullPointerException if any argument is null 062 */ 063 public Pp2FormatResult format(String sql, EDbVendor vendor, 064 Pp2FormatOptions opts) { 065 if (sql == null) throw new NullPointerException("sql"); 066 if (vendor == null) throw new NullPointerException("vendor"); 067 if (opts == null) throw new NullPointerException("opts"); 068 return engine.format(sql, vendor, opts); 069 } 070}