99 */
1010package net .sf .jsqlparser .statement .select ;
1111
12- import java .util .Locale ;
1312import net .sf .jsqlparser .parser .ASTNodeAccessImpl ;
1413
1514import static net .sf .jsqlparser .statement .select .KSQLWindow .TimeUnit ;
@@ -23,9 +22,37 @@ public class KSQLJoinWindow extends ASTNodeAccessImpl {
2322 private TimeUnit beforeTimeUnit ;
2423 private long afterDuration ;
2524 private TimeUnit afterTimeUnit ;
25+ private boolean usingBrackets = true ;
26+ private KSQLWindow .Duration gracePeriod ;
27+
28+ public boolean isUsingBrackets () {
29+ return usingBrackets || beforeAfter ;
30+ }
31+
32+ public void setUsingBrackets (boolean usingBrackets ) {
33+ this .usingBrackets = usingBrackets ;
34+ }
35+
36+ public KSQLJoinWindow withUsingBrackets (boolean usingBrackets ) {
37+ setUsingBrackets (usingBrackets );
38+ return this ;
39+ }
40+
41+ public KSQLWindow .Duration getGracePeriod () {
42+ return gracePeriod ;
43+ }
44+
45+ public void setGracePeriod (KSQLWindow .Duration gracePeriod ) {
46+ this .gracePeriod = gracePeriod ;
47+ }
48+
49+ public KSQLJoinWindow withGracePeriod (KSQLWindow .Duration gracePeriod ) {
50+ setGracePeriod (gracePeriod );
51+ return this ;
52+ }
2653
2754 public final static TimeUnit from (String timeUnitStr ) {
28- return Enum . valueOf ( TimeUnit .class , timeUnitStr . toUpperCase ( Locale . ROOT ) );
55+ return TimeUnit .from ( timeUnitStr );
2956 }
3057
3158 public boolean isBeforeAfterWindow () {
@@ -86,11 +113,23 @@ public void setAfterTimeUnit(TimeUnit afterTimeUnit) {
86113
87114 @ Override
88115 public String toString () {
116+ StringBuilder builder = new StringBuilder ();
117+ if (isUsingBrackets ()) {
118+ builder .append ('(' );
119+ }
89120 if (isBeforeAfterWindow ()) {
90- return "(" + beforeDuration + " " + beforeTimeUnit + ", " + afterDuration + " "
91- + afterTimeUnit + ")" ;
121+ builder .append (beforeDuration ).append (' ' ).append (beforeTimeUnit )
122+ .append (", " ).append (afterDuration ).append (' ' ).append (afterTimeUnit );
123+ } else {
124+ builder .append (duration ).append (' ' ).append (timeUnit );
125+ }
126+ if (isUsingBrackets ()) {
127+ builder .append (')' );
128+ }
129+ if (gracePeriod != null ) {
130+ builder .append (" GRACE PERIOD " ).append (gracePeriod );
92131 }
93- return "(" + duration + " " + timeUnit + ")" ;
132+ return builder . toString () ;
94133 }
95134
96135 public KSQLJoinWindow withDuration (long duration ) {
0 commit comments