|
| 1 | +/*- |
| 2 | + * #%L |
| 3 | + * JSQLParser library |
| 4 | + * %% |
| 5 | + * Copyright (C) 2004 - 2026 JSQLParser |
| 6 | + * %% |
| 7 | + * Dual licensed under GNU LGPL 2.1 or Apache License 2.0 |
| 8 | + * #L% |
| 9 | + */ |
| 10 | +package net.sf.jsqlparser.statement.create.event; |
| 11 | + |
| 12 | +import java.io.Serializable; |
| 13 | +import net.sf.jsqlparser.expression.Expression; |
| 14 | + |
| 15 | +/** Structured {@code ON SCHEDULE} clause of a MySQL event. */ |
| 16 | +public class EventSchedule implements Serializable { |
| 17 | + |
| 18 | + public enum Type { |
| 19 | + AT, EVERY |
| 20 | + } |
| 21 | + |
| 22 | + private Type type; |
| 23 | + private Expression executeAt; |
| 24 | + private Expression interval; |
| 25 | + private String intervalUnit; |
| 26 | + private Expression starts; |
| 27 | + private Expression ends; |
| 28 | + |
| 29 | + public Type getType() { |
| 30 | + return type; |
| 31 | + } |
| 32 | + |
| 33 | + public void setType(Type type) { |
| 34 | + this.type = type; |
| 35 | + } |
| 36 | + |
| 37 | + public Expression getExecuteAt() { |
| 38 | + return executeAt; |
| 39 | + } |
| 40 | + |
| 41 | + public void setExecuteAt(Expression executeAt) { |
| 42 | + this.executeAt = executeAt; |
| 43 | + } |
| 44 | + |
| 45 | + public Expression getInterval() { |
| 46 | + return interval; |
| 47 | + } |
| 48 | + |
| 49 | + public void setInterval(Expression interval) { |
| 50 | + this.interval = interval; |
| 51 | + } |
| 52 | + |
| 53 | + public String getIntervalUnit() { |
| 54 | + return intervalUnit; |
| 55 | + } |
| 56 | + |
| 57 | + public void setIntervalUnit(String intervalUnit) { |
| 58 | + this.intervalUnit = intervalUnit; |
| 59 | + } |
| 60 | + |
| 61 | + public Expression getStarts() { |
| 62 | + return starts; |
| 63 | + } |
| 64 | + |
| 65 | + public void setStarts(Expression starts) { |
| 66 | + this.starts = starts; |
| 67 | + } |
| 68 | + |
| 69 | + public Expression getEnds() { |
| 70 | + return ends; |
| 71 | + } |
| 72 | + |
| 73 | + public void setEnds(Expression ends) { |
| 74 | + this.ends = ends; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public String toString() { |
| 79 | + StringBuilder builder = new StringBuilder(); |
| 80 | + if (type == Type.AT) { |
| 81 | + builder.append("AT ").append(executeAt); |
| 82 | + } else if (type == Type.EVERY) { |
| 83 | + builder.append("EVERY ").append(interval).append(" ").append(intervalUnit); |
| 84 | + if (starts != null) { |
| 85 | + builder.append(" STARTS ").append(starts); |
| 86 | + } |
| 87 | + if (ends != null) { |
| 88 | + builder.append(" ENDS ").append(ends); |
| 89 | + } |
| 90 | + } |
| 91 | + return builder.toString(); |
| 92 | + } |
| 93 | + |
| 94 | + public EventSchedule withType(Type type) { |
| 95 | + setType(type); |
| 96 | + return this; |
| 97 | + } |
| 98 | + |
| 99 | + public EventSchedule withExecuteAt(Expression executeAt) { |
| 100 | + setExecuteAt(executeAt); |
| 101 | + return this; |
| 102 | + } |
| 103 | + |
| 104 | + public EventSchedule withInterval(Expression interval) { |
| 105 | + setInterval(interval); |
| 106 | + return this; |
| 107 | + } |
| 108 | + |
| 109 | + public EventSchedule withIntervalUnit(String intervalUnit) { |
| 110 | + setIntervalUnit(intervalUnit); |
| 111 | + return this; |
| 112 | + } |
| 113 | + |
| 114 | + public EventSchedule withStarts(Expression starts) { |
| 115 | + setStarts(starts); |
| 116 | + return this; |
| 117 | + } |
| 118 | + |
| 119 | + public EventSchedule withEnds(Expression ends) { |
| 120 | + setEnds(ends); |
| 121 | + return this; |
| 122 | + } |
| 123 | +} |
0 commit comments