001: /*
002:
003: Loader - tool for transfering data from one JDBC source to another and
004: doing transformations during copy.
005:
006: Copyright (C) 2002 Together
007:
008: This library is free software; you can redistribute it and/or
009: modify it under the terms of the GNU Lesser General Public
010: License as published by the Free Software Foundation; either
011: version 2.1 of the License, or (at your option) any later version.
012:
013: This library is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: Lesser General Public License for more details.
017:
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021:
022: LoaderTask.java
023: Date: 15.06.2002.
024: @version 1.0
025: @author:
026: Milosevic Sinisa sinisami@eunet.yu
027: Radeka Dusan diradeka@neobee.net
028: */
029:
030: package org.webdocwf.util.loader.task;
031:
032: import java.io.BufferedReader;
033: import java.io.InputStreamReader;
034:
035: import org.apache.tools.ant.BuildException;
036: import org.apache.tools.ant.Task;
037:
038: /**
039: * <p>
040: * Loader Task class extends jakarta-ant Task class and uses to start Loader
041: * application as a jakarta-ant task in build.xml file.
042: * </p>
043: * <p>
044: * Attributes of LoaderTask represents Loader parameters:<br>
045: * <br>
046: * loadJobFileName attribute - defines loader job<br>
047: * mode attribute - defines mode <br>
048: * restartIndicator attribute - defines restart <br>
049: * userID attribute - defines user ID <br>
050: * logDirName attribute - defines log directory <br>
051: * logFileName attribute - defines log file <br>
052: * vendorFileName attribute - defines vendor file <br>
053: * onErrorContinue attribute - defines continue or not on error<br>
054: * commitCount attribute - defines commit count<br>
055: * additionalPaths tag - defines single or group of additionalPath tags<br>
056: * additionalPath tag - defines tag with path attribute <br>
057: * pathToConfFile attribute - defines path to conf file in jar<br>
058: * variables tag - defines single or group of variable tags<br>
059: * variable tag - defines tag with path attribute <br>
060: * name attribute - defines variable name<br>
061: * value attribute - defines variable value<br>
062: * <br>
063: * </p>
064: **/
065: public class LoaderTask extends Task {
066: private String loadJobFileName;
067: private String mode;
068: private String restartIndicator;
069: private String userID;
070: private String logDirName;
071: private String logFileName;
072: private String vendorFileName;
073: private String onErrorContinue;
074: private String commitCount;
075: private String tableNames;
076: private String additionalPaths;
077: private String additionalPath;
078:
079: private String variables;
080:
081: private String strLoaderExec = "";
082:
083: private String returnCode;
084: private String pathToConfFile;
085:
086: private String JAVAEXE = "java";
087: private final String LOADER = "org.webdocwf.util.loader.Loader";
088:
089: /**
090: * The method executing the task
091: **/
092: public void execute() throws BuildException {
093:
094: try {
095: //find java.exe
096: String sep = System.getProperty("file.separator");
097: JAVAEXE = System.getProperty("java.home") + sep + "bin"
098: + sep + "java";
099:
100: if (this .loadJobFileName == null) {
101: throw (new BuildException(
102: "loadJobFileName attribute must be set! ",
103: location));
104: } else {
105:
106: if (this .additionalPath != null) {
107: this .strLoaderExec += "-classpath "
108: + this .additionalPath.substring(0,
109: this .additionalPath.length() - 1)
110: + " ";
111: }
112:
113: this .strLoaderExec += LOADER + " ";
114:
115: if (this .mode != null) {
116: if (this .mode.equalsIgnoreCase("none")) {
117: this .strLoaderExec += "-m none ";
118: } else if (this .mode.equalsIgnoreCase("normal")) {
119: this .strLoaderExec += "-m normal ";
120: } else if (this .mode.equalsIgnoreCase("full")) {
121: this .strLoaderExec += "-m full ";
122: }
123: }
124: if (this .restartIndicator != null
125: && this .restartIndicator
126: .equalsIgnoreCase("yes")) {
127: this .strLoaderExec += "-r ";
128: }
129:
130: if (this .userID != null) {
131: this .strLoaderExec += "-u " + this .userID + " ";
132: }
133:
134: if (this .variables != null) {
135: if (this .variables.endsWith(";"))
136: this .variables = this .variables.substring(0,
137: this .variables.length() - 1);
138: this .strLoaderExec += "-v " + this .variables + " ";
139: }
140:
141: if (this .logDirName != null) {
142: this .strLoaderExec += "-l " + this .logDirName + " ";
143: }
144:
145: if (this .logFileName != null) {
146: this .strLoaderExec += "-f " + this .logFileName
147: + " ";
148: }
149:
150: if (this .vendorFileName != null) {
151: this .strLoaderExec += "-d " + this .vendorFileName
152: + " ";
153: }
154:
155: if (this .onErrorContinue != null
156: && this .onErrorContinue
157: .equalsIgnoreCase("true")) {
158: this .strLoaderExec += "-e ";
159: }
160:
161: if (this .commitCount != null) {
162: this .strLoaderExec += "-c " + this .commitCount
163: + " ";
164: }
165: if (this .returnCode != null) {
166: this .strLoaderExec += "-rc " + this .returnCode
167: + " ";
168: }
169: if (this .pathToConfFile != null) {
170: this .strLoaderExec += "-cjs " + this .pathToConfFile
171: + " ";
172: }
173: if (this .tableNames != null) {
174: if (this .tableNames.endsWith(";"))
175: this .tableNames = this .tableNames.substring(0,
176: this .tableNames.length() - 1);
177: this .strLoaderExec += "-it " + this .tableNames
178: + " ";
179: }
180:
181: this .strLoaderExec += this .loadJobFileName;
182:
183: String command = JAVAEXE + " " + this .strLoaderExec;
184: Process process = Runtime.getRuntime().exec(command);
185: java.io.InputStream inputstream = process
186: .getInputStream();
187: BufferedReader bufferedreader = new BufferedReader(
188: new InputStreamReader(inputstream));
189: java.io.InputStream inputstream1 = process
190: .getErrorStream();
191: BufferedReader bufferedreader1 = new BufferedReader(
192: new InputStreamReader(inputstream1));
193: (new ErrorReader(bufferedreader1)).start();
194: String s1;
195: while ((s1 = bufferedreader.readLine()) != null) {
196: System.out.println(s1);
197:
198: }
199: int k = process.waitFor();
200: if (k != 0)
201: throw (new BuildException("Loader: Error occured!",
202: location));
203: }
204: } catch (Throwable le) {
205: System.out.println(le);
206: }
207:
208: }
209:
210: /**
211: * The setter for the "loadJob" attribute
212: **/
213: public void setLoadJob(String msg) {
214: this .loadJobFileName = msg;
215: }
216:
217: /**
218: * The setter for the "mode" attribute
219: **/
220: public void setMode(String msg) {
221: this .mode = msg;
222: }
223:
224: /**
225: * The setter for the "userID" attribute
226: **/
227: public void setUserID(String msg) {
228: this .userID = msg;
229: }
230:
231: /**
232: * The setter for the "logDir" attribute
233: **/
234: public void setLogDir(String msg) {
235: this .logDirName = msg;
236: }
237:
238: /**
239: * The setter for the "logFile" attribute
240: **/
241: public void setLogFile(String msg) {
242: this .logFileName = msg;
243: }
244:
245: /**
246: * The setter for the "restartIndicator" attribute
247: **/
248: public void setRestartIndicator(String msg) {
249: this .restartIndicator = msg;
250: }
251:
252: /**
253: * The setter for the "vendorFile" attribute
254: **/
255: public void setVendorFile(String msg) {
256: this .vendorFileName = msg;
257: }
258:
259: /**
260: * The setter for the "onErrorContinue" attribute
261: **/
262: public void setOnErrorContinue(String msg) {
263: this .onErrorContinue = msg;
264: }
265:
266: /**
267: * The setter for the "commitCount" attribute
268: **/
269: public void setCommitCount(String msg) {
270: this .commitCount = msg;
271: }
272:
273: /**
274: * The setter for the "returnCode" attribute
275: **/
276: public void setReturnCode(String rc) {
277: this .returnCode = rc;
278: }
279:
280: /**
281: * The setter for the "AdditionalPaths" tag
282: **/
283: public void addConfiguredAdditionalPaths(AdditionalPaths anInner) {
284: this .additionalPath = anInner.additionalPaths.substring(0,
285: anInner.additionalPaths.indexOf("null"))
286: + anInner.additionalPaths.substring(
287: anInner.additionalPaths.indexOf("null") + 4,
288: anInner.additionalPaths.length());
289: }
290:
291: /**
292: * The setter for the "Variables" tag
293: **/
294: public void addConfiguredVariables(Variables anInner) {
295: this .variables = anInner.variables.substring(0,
296: anInner.variables.indexOf("null"))
297: + anInner.variables.substring(anInner.variables
298: .indexOf("null") + 4, anInner.variables
299: .length());
300: }
301:
302: /**
303: * The setter for the "pathToConfFile" attribute
304: */
305: public void setPathToConfFile(String string) {
306: this .pathToConfFile = string;
307: }
308:
309: /**
310: * The setter for the "tableNames" attribute
311: */
312: public void setTableNames(String string) {
313: this.tableNames = string;
314: }
315:
316: }
|