2121import net .sf .jsqlparser .statement .ReferentialAction ;
2222import net .sf .jsqlparser .statement .ReferentialAction .Action ;
2323import net .sf .jsqlparser .statement .ReferentialAction .Type ;
24- import net .sf .jsqlparser .statement .select .PlainSelect ;
2524
2625/** The target and actions of a column- or table-level foreign-key reference. */
2726public class ForeignKeyReference implements Serializable {
@@ -33,8 +32,35 @@ public enum MatchType {
3332 private Table table ;
3433 private List <String > referencedColumnNames ;
3534 private MatchType matchType ;
35+ private boolean usingPeriod ;
36+ private ConstraintAttributes constraintAttributes ;
3637 private final Set <ReferentialAction > referentialActions = new LinkedHashSet <>(2 );
3738
39+ /**
40+ * Attributes of a column REFERENCES clause; table constraints own their attributes on Index.
41+ */
42+ public ConstraintAttributes getConstraintAttributes () {
43+ return constraintAttributes ;
44+ }
45+
46+ public void setConstraintAttributes (ConstraintAttributes constraintAttributes ) {
47+ this .constraintAttributes = constraintAttributes ;
48+ }
49+
50+ /** Whether the final explicitly referenced column is prefixed with PERIOD. */
51+ public boolean isUsingPeriod () {
52+ return usingPeriod ;
53+ }
54+
55+ public void setUsingPeriod (boolean usingPeriod ) {
56+ this .usingPeriod = usingPeriod ;
57+ }
58+
59+ public ForeignKeyReference withUsingPeriod (boolean usingPeriod ) {
60+ setUsingPeriod (usingPeriod );
61+ return this ;
62+ }
63+
3864 public Table getTable () {
3965 return table ;
4066 }
@@ -124,12 +150,25 @@ public ForeignKeyReference addReferencedColumnNames(
124150 public String toString () {
125151 StringBuilder builder = new StringBuilder ("REFERENCES " ).append (table );
126152 if (referencedColumnNames != null ) {
127- builder .append (PlainSelect .getStringList (referencedColumnNames , true , true ));
153+ builder .append ('(' );
154+ for (int i = 0 ; i < referencedColumnNames .size (); i ++) {
155+ if (i > 0 ) {
156+ builder .append (", " );
157+ }
158+ if (usingPeriod && i == referencedColumnNames .size () - 1 ) {
159+ builder .append ("PERIOD " );
160+ }
161+ builder .append (referencedColumnNames .get (i ));
162+ }
163+ builder .append (')' );
128164 }
129165 if (matchType != null ) {
130166 builder .append (" MATCH " ).append (matchType );
131167 }
132168 referentialActions .forEach (builder ::append );
169+ if (constraintAttributes != null ) {
170+ constraintAttributes .appendTo (builder );
171+ }
133172 return builder .toString ();
134173 }
135174}
0 commit comments