001    package liquibase.statement.core;
002    
003    import liquibase.statement.AbstractSqlStatement;
004    
005    public class AddForeignKeyConstraintStatement extends AbstractSqlStatement {
006    
007        private String baseTableSchemaName;
008        private String baseTableName;
009        private String baseColumnNames;
010    
011        private String referencedTableSchemaName;
012        private String referencedTableName;
013        private String referencedColumnNames;
014    
015        private String constraintName;
016    
017        private boolean deferrable;
018        private boolean initiallyDeferred;
019    
020        private String onDelete;
021        private String onUpdate;
022    
023        // Some databases supports creation of FK with referention to column marked as unique, not primary
024        // If FK referenced to such unique column this option should be set to false
025        private boolean referencesUniqueColumn = false;
026    
027        public AddForeignKeyConstraintStatement(String constraintName, String baseTableSchemaName, String baseTableName,
028                String baseColumnNames, String referencedTableSchemaName, String referencedTableName,
029                String referencedColumnNames) {
030            this.baseTableSchemaName = baseTableSchemaName;
031            this.baseTableName = baseTableName;
032            this.baseColumnNames = baseColumnNames;
033            this.referencedTableSchemaName = referencedTableSchemaName;
034            this.referencedTableName = referencedTableName;
035            this.referencedColumnNames = referencedColumnNames;
036            this.constraintName = constraintName;
037        }
038    
039        public String getBaseTableSchemaName() {
040            return baseTableSchemaName;
041        }
042    
043        public String getBaseTableName() {
044            return baseTableName;
045        }
046    
047        public String getBaseColumnNames() {
048            return baseColumnNames;
049        }
050    
051        public String getReferencedTableSchemaName() {
052            return referencedTableSchemaName;
053        }
054    
055        public String getReferencedTableName() {
056            return referencedTableName;
057        }
058    
059        public String getReferencedColumnNames() {
060            return referencedColumnNames;
061        }
062    
063        public String getConstraintName() {
064            return constraintName;
065        }
066    
067        public boolean isDeferrable() {
068            return deferrable;
069        }
070    
071        public String getOnDelete() {
072            return onDelete;
073        }
074    
075        public String getOnUpdate() {
076            return onUpdate;
077        }
078    
079        public AddForeignKeyConstraintStatement setDeferrable(boolean deferrable) {
080            this.deferrable = deferrable;
081            return this;
082        }
083    
084        public boolean isInitiallyDeferred() {
085            return initiallyDeferred;
086        }
087    
088        public AddForeignKeyConstraintStatement setInitiallyDeferred(boolean initiallyDeferred) {
089            this.initiallyDeferred = initiallyDeferred;
090            return this;
091        }
092    
093        public AddForeignKeyConstraintStatement setOnUpdate(String updateRule) {
094            this.onUpdate = updateRule;
095            return this;
096        }
097    
098        public AddForeignKeyConstraintStatement setOnDelete(String deleteRule) {
099            this.onDelete = deleteRule;
100            return this;
101        }
102    
103        public boolean getReferencesUniqueColumn() {
104            return referencesUniqueColumn;
105        }
106    
107        public AddForeignKeyConstraintStatement setReferencesUniqueColumn(Boolean referencesUniqueColumn) {
108            if (referencesUniqueColumn != null) {
109                this.referencesUniqueColumn = referencesUniqueColumn;
110            }
111            return this;
112        }
113    }