001package gudusoft.gsqlparser.nodes.snowflake;
002
003
004import gudusoft.gsqlparser.EDbObjectType;
005import gudusoft.gsqlparser.TSourceToken;
006import gudusoft.gsqlparser.nodes.*;
007
008import java.util.ArrayList;
009import java.util.List;
010import java.util.Map;
011
012public class TTaskOption extends TParseTreeNode {
013
014    private String name;
015    private boolean orReplace;
016    private boolean ifNotExists;
017    private String warehouse;
018    private String userTaskManagedInitialWarehouseSize;
019    private TSchedule schedule;
020    private String scheduleString;
021
022    public String getScheduleString() {
023        return scheduleString;
024    }
025
026    private String config;
027    private Boolean allowOverlappingExecution;
028    private ArrayList<TNameValuePair> sessionParameters;
029    private Integer userTaskTimeoutMs;
030    private Integer suspendTaskAfterNumFailures;
031    private String errorIntegration;
032    private String comment;
033    private String finalize;
034    private Integer taskAutoRetryAttempts;
035    private Map<String, String> tags;
036    private TObjectNameList after;
037//    private String when;
038    private String sql;
039
040    private ETaskOptionType taskOptionType;
041
042    private TExpression whenCondition;
043
044    public TExpression getWhenCondition() {
045        return whenCondition;
046    }
047
048    public void init(Object arg1) {
049        taskOptionType = (ETaskOptionType) arg1;
050    }
051
052    public void init(Object arg1, Object arg2){
053        init(arg1);
054        switch (taskOptionType){
055            case WAREHOUSE:
056            {
057                if (arg2 instanceof TSourceToken){
058                    warehouse = ((TSourceToken) arg2).toString();
059                } else if (arg2 instanceof TConstant) {
060                    warehouse = ((TConstant) arg2).toString();
061                }else{
062                    warehouse = (String) arg2;
063                }
064                    break;
065                }
066            case USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE:
067                userTaskManagedInitialWarehouseSize = ((TConstant) arg2).toString();
068                break;
069            case SCHEDULE:{
070                if (arg2 instanceof TConstant){
071                    scheduleString = ((TConstant) arg2).toString();
072                }else if (arg2 instanceof TSourceToken){
073                    scheduleString = ((TSourceToken) arg2).toString();
074                }
075                break;
076            }
077            case CONFIG:
078                config = (String) arg2;
079                break;
080            case ALLOW_OVERLAPPING_EXECUTION:
081                allowOverlappingExecution = (Boolean) arg2;
082                break;
083            case SESSION_PARAMETER:
084                sessionParameters = (ArrayList<TNameValuePair>) arg2;
085                break;
086            case USER_TASK_TIMEOUT_MS:
087                userTaskTimeoutMs = (Integer) arg2;
088                break;
089            case SUSPEND_TASK_AFTER_NUM_FAILURES:
090                suspendTaskAfterNumFailures = (Integer) arg2;
091                break;
092            case ERROR_INTEGRATION:
093                errorIntegration = (String) arg2;
094                break;
095            case COMMENT:
096                comment = (String) arg2;
097                break;
098            case FINALIZE:
099                finalize = (String) arg2;
100                break;
101            case TASK_AUTO_RETRY_ATTEMPTS:
102                taskAutoRetryAttempts = (Integer) arg2;
103                break;
104            case TAG:
105                tags = (Map<String, String>) arg2;
106                break;
107            case AFTER:
108                after = (TObjectNameList) arg2;
109                for(TObjectName objectName: after){
110                    objectName.setDbObjectType(EDbObjectType.task);
111                }
112                break;
113            case WHEN:
114                whenCondition = (TExpression) arg2;
115                break;
116            default:
117                throw new IllegalArgumentException("Unknown TaskOptionType: " + taskOptionType);
118        }
119    }
120
121    public ETaskOptionType getTaskOptionType() {
122        return taskOptionType;
123    }
124    // Getters and Setters
125
126
127
128    // Getters and Setters for all fields
129
130    public String getName() {
131        return name;
132    }
133
134    public void setName(String name) {
135        this.name = name;
136    }
137
138    public boolean isOrReplace() {
139        return orReplace;
140    }
141
142    public void setOrReplace(boolean orReplace) {
143        this.orReplace = orReplace;
144    }
145
146    public boolean isIfNotExists() {
147        return ifNotExists;
148    }
149
150    public void setIfNotExists(boolean ifNotExists) {
151        this.ifNotExists = ifNotExists;
152    }
153
154    public String getWarehouse() {
155        return warehouse;
156    }
157
158    public void setWarehouse(String warehouse) {
159        this.warehouse = warehouse;
160    }
161
162    public String getUserTaskManagedInitialWarehouseSize() {
163        return userTaskManagedInitialWarehouseSize;
164    }
165
166    public void setUserTaskManagedInitialWarehouseSize(String userTaskManagedInitialWarehouseSize) {
167        this.userTaskManagedInitialWarehouseSize = userTaskManagedInitialWarehouseSize;
168    }
169
170    public TSchedule getSchedule() {
171        return schedule;
172    }
173
174    public void setSchedule(TSchedule schedule) {
175        this.schedule = schedule;
176    }
177
178    public String getConfig() {
179        return config;
180    }
181
182    public void setConfig(String config) {
183        this.config = config;
184    }
185
186    public Boolean getAllowOverlappingExecution() {
187        return allowOverlappingExecution;
188    }
189
190    public void setAllowOverlappingExecution(Boolean allowOverlappingExecution) {
191        this.allowOverlappingExecution = allowOverlappingExecution;
192    }
193
194    public ArrayList<TNameValuePair> getSessionParameters() {
195        return sessionParameters;
196    }
197
198
199
200    public Integer getUserTaskTimeoutMs() {
201        return userTaskTimeoutMs;
202    }
203
204    public void setUserTaskTimeoutMs(Integer userTaskTimeoutMs) {
205        this.userTaskTimeoutMs = userTaskTimeoutMs;
206    }
207
208    public Integer getSuspendTaskAfterNumFailures() {
209        return suspendTaskAfterNumFailures;
210    }
211
212    public void setSuspendTaskAfterNumFailures(Integer suspendTaskAfterNumFailures) {
213        this.suspendTaskAfterNumFailures = suspendTaskAfterNumFailures;
214    }
215
216    public String getErrorIntegration() {
217        return errorIntegration;
218    }
219
220    public void setErrorIntegration(String errorIntegration) {
221        this.errorIntegration = errorIntegration;
222    }
223
224    public String getComment() {
225        return comment;
226    }
227
228    public void setComment(String comment) {
229        this.comment = comment;
230    }
231
232    public String getFinalize() {
233        return finalize;
234    }
235
236    public void setFinalize(String finalize) {
237        this.finalize = finalize;
238    }
239
240    public Integer getTaskAutoRetryAttempts() {
241        return taskAutoRetryAttempts;
242    }
243
244    public void setTaskAutoRetryAttempts(Integer taskAutoRetryAttempts) {
245        this.taskAutoRetryAttempts = taskAutoRetryAttempts;
246    }
247
248    public Map<String, String> getTags() {
249        return tags;
250    }
251
252    public void setTags(Map<String, String> tags) {
253        this.tags = tags;
254    }
255
256    public TObjectNameList getAfter() {
257        return after;
258    }
259
260    public void setAfter(TObjectNameList after) {
261        this.after = after;
262    }
263
264//    public String getWhen() {
265//        return when;
266//    }
267//
268//    public void setWhen(String when) {
269//        this.when = when;
270//    }
271
272    public String getSql() {
273        return sql;
274    }
275
276    public void setSql(String sql) {
277        this.sql = sql;
278    }
279
280
281    public void accept(TParseTreeVisitor v)
282    {
283        v.preVisit(this);
284        v.postVisit(this);
285    }
286
287    public void acceptChildren(TParseTreeVisitor v) {
288        v.preVisit(this);
289        v.postVisit(this);
290    }
291    // Inner class for Schedule
292    public static class TSchedule {
293        private Integer minutes;
294        private String cronExpression;
295        private String timeZone;
296
297        public Integer getMinutes() {
298            return minutes;
299        }
300
301        public void setMinutes(Integer minutes) {
302            this.minutes = minutes;
303        }
304
305        public String getCronExpression() {
306            return cronExpression;
307        }
308
309        public void setCronExpression(String cronExpression) {
310            this.cronExpression = cronExpression;
311        }
312
313        public String getTimeZone() {
314            return timeZone;
315        }
316
317        public void setTimeZone(String timeZone) {
318            this.timeZone = timeZone;
319        }
320    }
321
322
323
324}