KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > dbscript > Command


1 /*
2  * This software is released under a licence similar to the Apache Software Licence.
3  * See org.logicalcobwebs.proxool.package.html for details.
4  * The latest version is available at http://proxool.sourceforge.net
5  */

6 package org.logicalcobwebs.dbscript;
7
8 import org.apache.commons.logging.Log;
9 import org.apache.commons.logging.LogFactory;
10
11 /**
12  * An SQL command that isrun by a {@link Script}. If {@link #getLoad load}
13  * or {@link #getLoops loops} are configured then it might run more than
14  * once.
15  *
16  * @version $Revision: 1.9 $, $Date: 2006/01/18 14:40:04 $
17  * @author Bill Horsman (bill@logicalcobwebs.co.uk)
18  * @author $Author: billhorsman $ (current maintainer)
19  * @since Proxool 0.5
20  */

21 class Command implements CommandIF {
22
23     private static final Log LOG = LogFactory.getLog(Command.class);
24
25     private String JavaDoc name;
26
27     private String JavaDoc sql;
28
29     private int load = 1;
30
31     private int loops = 1;
32
33     private String JavaDoc exception;
34
35     /**
36      * If this command encounters an exception it will stop executing (and if
37      * it is in a loop it will break out of the loop)
38      */

39     protected static final String JavaDoc EXCEPTION_STOP = "stop";
40
41     /**
42      * If this command encounters an exception it will log it at DEBUG
43      * level and continue
44      */

45     protected static final String JavaDoc EXCEPTION_LOG = "log";
46
47     /**
48      * If this command encounters an exception it will silently ignore the
49      * exception and continue. But it still calls the
50      */

51     protected static final String JavaDoc EXCEPTION_IGNORE = "ignore";
52
53     /**
54      * @see CommandIF#getSql
55      */

56     public String JavaDoc getSql() {
57         return sql;
58     }
59
60     /**
61      * @see #getSql
62      */

63     protected void setSql(String JavaDoc sql) {
64         this.sql = sql;
65     }
66
67     /**
68      * @see CommandIF#getLoad
69      */

70     public int getLoad() {
71         return load;
72     }
73
74     /**
75      * @see #getLoad
76      */

77     protected void setLoad(int load) {
78         this.load = load;
79     }
80
81     /**
82      * @see CommandIF#getLoops
83      */

84     public int getLoops() {
85         return loops;
86     }
87
88     /**
89      * @see #getLoops
90      */

91     protected void setLoops(int loops) {
92         this.loops = loops;
93     }
94
95     /**
96      * @see CommandIF#isIgnoreException
97      */

98     public boolean isIgnoreException() {
99         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 JavaDoc 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 JavaDoc("Unknown exception value: " + exception);
123         }
124     }
125
126     /**
127      * @see CommandIF#getName
128      */

129     public String JavaDoc getName() {
130         return name;
131     }
132
133     /**
134      * @see #getName
135      */

136     public void setName(String JavaDoc name) {
137         this.name = name;
138     }
139
140 }
141
142 /*
143  Revision history:
144  $Log: Command.java,v $
145  Revision 1.9 2006/01/18 14:40:04 billhorsman
146  Unbundled Jakarta's Commons Logging.
147
148  Revision 1.8 2003/03/03 11:12:02 billhorsman
149  fixed licence
150
151  Revision 1.7 2003/02/19 15:14:18 billhorsman
152  fixed copyright (copy and paste error,
153  not copyright change)
154
155  Revision 1.6 2003/02/06 17:41:01 billhorsman
156  now uses imported logging
157
158  Revision 1.5 2002/11/09 15:58:12 billhorsman
159  fix doc
160
161  Revision 1.4 2002/11/09 14:45:07 billhorsman
162  now threaded and better exception handling
163
164  Revision 1.3 2002/11/06 21:07:03 billhorsman
165  Now supports the CommandIF interface
166
167  Revision 1.2 2002/11/02 14:22:16 billhorsman
168  Documentation
169
170  Revision 1.1 2002/11/02 11:29:53 billhorsman
171  new script runner for testing
172
173 */

174
Popular Tags