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>Since slice S16, {@code format(...)} delegates to {@link Pp2Engine}. 015 * Before S16 it was an identity pass (Phase-0 contract, slice S4). 016 * 017 * <p>Lifecycle: {@code Pp2Formatter} carries no caller-visible state. Each 018 * {@code format(...)} call is independent. Callers may share an instance 019 * across threads (subject to their own {@code Pp2FormatOptions} discipline). 020 */ 021public final class Pp2Formatter { 022 023 private final Pp2Engine engine = new Pp2Engine(); 024 025 /** 026 * Format the given SQL using the default vendor ({@link EDbVendor#dbvoracle}) 027 * and default options ({@link Pp2FormatOptions#defaults()}). 028 * 029 * @throws NullPointerException if {@code sql} is null 030 */ 031 public Pp2FormatResult format(String sql) { 032 return format(sql, EDbVendor.dbvoracle, Pp2FormatOptions.defaults()); 033 } 034 035 /** 036 * Format the given SQL using the default vendor ({@link EDbVendor#dbvoracle}) 037 * and the supplied options. 038 * 039 * @throws NullPointerException if {@code sql} or {@code opts} is null 040 */ 041 public Pp2FormatResult format(String sql, Pp2FormatOptions opts) { 042 return format(sql, EDbVendor.dbvoracle, opts); 043 } 044 045 /** 046 * Format the given SQL using the supplied vendor and options. 047 * Delegates to {@link Pp2Engine#format(String, EDbVendor, Pp2FormatOptions)}. 048 * 049 * @throws NullPointerException if any argument is null 050 */ 051 public Pp2FormatResult format(String sql, EDbVendor vendor, 052 Pp2FormatOptions opts) { 053 if (sql == null) throw new NullPointerException("sql"); 054 if (vendor == null) throw new NullPointerException("vendor"); 055 if (opts == null) throw new NullPointerException("opts"); 056 return engine.format(sql, vendor, opts); 057 } 058}