001: /*
002: * This software is released under a licence similar to the Apache Software Licence.
003: * See org.logicalcobwebs.proxool.package.html for details.
004: * The latest version is available at http://proxool.sourceforge.net
005: */
006: package org.logicalcobwebs.dbscript;
007:
008: import org.apache.commons.logging.Log;
009: import org.apache.commons.logging.LogFactory;
010:
011: /**
012: * An SQL command that isrun by a {@link Script}. If {@link #getLoad load}
013: * or {@link #getLoops loops} are configured then it might run more than
014: * once.
015: *
016: * @version $Revision: 1.9 $, $Date: 2006/01/18 14:40:04 $
017: * @author Bill Horsman (bill@logicalcobwebs.co.uk)
018: * @author $Author: billhorsman $ (current maintainer)
019: * @since Proxool 0.5
020: */
021: class Command implements CommandIF {
022:
023: private static final Log LOG = LogFactory.getLog(Command.class);
024:
025: private String name;
026:
027: private String sql;
028:
029: private int load = 1;
030:
031: private int loops = 1;
032:
033: private String exception;
034:
035: /**
036: * If this command encounters an exception it will stop executing (and if
037: * it is in a loop it will break out of the loop)
038: */
039: protected static final String EXCEPTION_STOP = "stop";
040:
041: /**
042: * If this command encounters an exception it will log it at DEBUG
043: * level and continue
044: */
045: protected static final String EXCEPTION_LOG = "log";
046:
047: /**
048: * If this command encounters an exception it will silently ignore the
049: * exception and continue. But it still calls the
050: */
051: protected static final String EXCEPTION_IGNORE = "ignore";
052:
053: /**
054: * @see CommandIF#getSql
055: */
056: public String getSql() {
057: return sql;
058: }
059:
060: /**
061: * @see #getSql
062: */
063: protected void setSql(String sql) {
064: this .sql = sql;
065: }
066:
067: /**
068: * @see CommandIF#getLoad
069: */
070: public int getLoad() {
071: return load;
072: }
073:
074: /**
075: * @see #getLoad
076: */
077: protected void setLoad(int load) {
078: this .load = load;
079: }
080:
081: /**
082: * @see CommandIF#getLoops
083: */
084: public int getLoops() {
085: return loops;
086: }
087:
088: /**
089: * @see #getLoops
090: */
091: protected void setLoops(int loops) {
092: this .loops = loops;
093: }
094:
095: /**
096: * @see CommandIF#isIgnoreException
097: */
098: public boolean isIgnoreException() {
099: return exception != null && exception.equals(EXCEPTION_IGNORE);
100: }
101:
102: /**
103: * @see CommandIF#isIgnoreException
104: */
105: public boolean isLogException() {
106: return exception != null && exception.equals(EXCEPTION_LOG);
107: }
108:
109: /**
110: * @see #isIgnoreException
111: */
112: public void setException(String exception) {
113: if (exception == null) {
114: this .exception = EXCEPTION_STOP;
115: LOG.debug("Setting exception to default " + EXCEPTION_STOP);
116: } else if (exception.equals(EXCEPTION_IGNORE)
117: || exception.equals(EXCEPTION_LOG)
118: || exception.equals(EXCEPTION_STOP)) {
119: this .exception = exception;
120: LOG.debug("Setting exception to " + exception);
121: } else {
122: throw new RuntimeException("Unknown exception value: "
123: + exception);
124: }
125: }
126:
127: /**
128: * @see CommandIF#getName
129: */
130: public String getName() {
131: return name;
132: }
133:
134: /**
135: * @see #getName
136: */
137: public void setName(String name) {
138: this .name = name;
139: }
140:
141: }
142:
143: /*
144: Revision history:
145: $Log: Command.java,v $
146: Revision 1.9 2006/01/18 14:40:04 billhorsman
147: Unbundled Jakarta's Commons Logging.
148:
149: Revision 1.8 2003/03/03 11:12:02 billhorsman
150: fixed licence
151:
152: Revision 1.7 2003/02/19 15:14:18 billhorsman
153: fixed copyright (copy and paste error,
154: not copyright change)
155:
156: Revision 1.6 2003/02/06 17:41:01 billhorsman
157: now uses imported logging
158:
159: Revision 1.5 2002/11/09 15:58:12 billhorsman
160: fix doc
161:
162: Revision 1.4 2002/11/09 14:45:07 billhorsman
163: now threaded and better exception handling
164:
165: Revision 1.3 2002/11/06 21:07:03 billhorsman
166: Now supports the CommandIF interface
167:
168: Revision 1.2 2002/11/02 14:22:16 billhorsman
169: Documentation
170:
171: Revision 1.1 2002/11/02 11:29:53 billhorsman
172: new script runner for testing
173:
174: */
|