⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadertask.java

📁 数据仓库工具
💻 JAVA
字号:
/*

	 Loader - tool for transfering data from one JDBC source to another and 
	 doing transformations during copy.

    Copyright (C) 2002  Together

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

 LoaderTask.java
 Date: 15.06.2002.
 @version 1.0 
 @author: 
 Milosevic Sinisa sinisami@eunet.yu
 Radeka Dusan diradeka@neobee.net
 */

package org.webdocwf.util.loader.task;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
* <p>
* Loader Task class extends jakarta-ant Task class and uses to start Loader 
* application as a jakarta-ant task in build.xml file.
* </p>
* <p>
* Attributes of LoaderTask represents Loader parameters:<br>
* <br>
* loadJobFileName attribute - defines loader job<br>
* mode attribute - defines mode <br>
* restartIndicator attribute - defines restart <br>
* userID attribute - defines user ID <br>
* logDirName attribute - defines log directory <br>
* logFileName attribute - defines log file <br>
* vendorFileName attribute - defines vendor file <br>
* onErrorContinue attribute - defines continue or not on error<br>
* commitCount attribute - defines commit count<br>
* additionalPaths tag - defines single or group of additionalPath tags<br>
* additionalPath tag - defines tag with path attribute <br>
* pathToConfFile attribute - defines path to conf file in jar<br>
* variables tag - defines single or group of variable tags<br>
* variable tag - defines tag with path attribute <br>
* name attribute - defines variable name<br>
* value attribute - defines variable value<br>
* <br>
* </p>
**/
public class LoaderTask extends Task {
    private String loadJobFileName;
    private String mode;
    private String restartIndicator;
    private String userID;
    private String logDirName;
    private String logFileName;
    private String vendorFileName;
    private String onErrorContinue;
    private String commitCount;
    private String tableNames;
    private String additionalPaths;
    private String additionalPath;

    private String variables;

    private String strLoaderExec = "";

    private String returnCode;
    private String pathToConfFile;

    private String JAVAEXE = "java";
    private final String LOADER = "org.webdocwf.util.loader.Loader";
    /**
    * The method executing the task
    **/
    public void execute() throws BuildException {

        try {
            //find java.exe
            String sep = System.getProperty("file.separator");
            JAVAEXE = System.getProperty("java.home") + sep + "bin" + sep + "java";

            if (this.loadJobFileName == null) {
                throw (new BuildException("loadJobFileName attribute must be set! ", location));
            } else {

                if (this.additionalPath != null) {
                    this.strLoaderExec += "-classpath " + this.additionalPath.substring(0, this.additionalPath.length() - 1) + " ";
                }

                this.strLoaderExec += LOADER + " ";

                if (this.mode != null) {
                    if (this.mode.equalsIgnoreCase("none")) {
                        this.strLoaderExec += "-m none ";
                    } else if (this.mode.equalsIgnoreCase("normal")) {
                        this.strLoaderExec += "-m normal ";
                    } else if (this.mode.equalsIgnoreCase("full")) {
                        this.strLoaderExec += "-m full ";
                    }
                }
                if (this.restartIndicator != null && this.restartIndicator.equalsIgnoreCase("yes")) {
                    this.strLoaderExec += "-r ";
                }

                if (this.userID != null) {
                    this.strLoaderExec += "-u " + this.userID + " ";
                }

                if (this.variables != null) {
                    if (this.variables.endsWith(";"))
                        this.variables = this.variables.substring(0, this.variables.length() - 1);
                    this.strLoaderExec += "-v " + this.variables + " ";
                }

                if (this.logDirName != null) {
                    this.strLoaderExec += "-l " + this.logDirName + " ";
                }

                if (this.logFileName != null) {
                    this.strLoaderExec += "-f " + this.logFileName + " ";
                }

                if (this.vendorFileName != null) {
                    this.strLoaderExec += "-d " + this.vendorFileName + " ";
                }

                if (this.onErrorContinue != null && this.onErrorContinue.equalsIgnoreCase("true")) {
                    this.strLoaderExec += "-e ";
                }

                if (this.commitCount != null) {
                    this.strLoaderExec += "-c " + this.commitCount + " ";
                }
                if (this.returnCode != null) {
                    this.strLoaderExec += "-rc " + this.returnCode + " ";
                }
                if (this.pathToConfFile != null) {
                    this.strLoaderExec += "-cjs " + this.pathToConfFile + " ";
                }
                if (this.tableNames != null) {
                    if (this.tableNames.endsWith(";"))
                        this.tableNames = this.tableNames.substring(0, this.tableNames.length() - 1);
                    this.strLoaderExec += "-it " + this.tableNames + " ";
                }
								

                this.strLoaderExec += this.loadJobFileName;

                String command = JAVAEXE + " " + this.strLoaderExec;
                Process process = Runtime.getRuntime().exec(command);
                java.io.InputStream inputstream = process.getInputStream();
                BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(inputstream));
                java.io.InputStream inputstream1 = process.getErrorStream();
                BufferedReader bufferedreader1 = new BufferedReader(new InputStreamReader(inputstream1));
                (new ErrorReader(bufferedreader1)).start();
                String s1;
                while ((s1 = bufferedreader.readLine()) != null) {
                    System.out.println(s1);

                }
                int k = process.waitFor();
                if (k != 0)
                    throw (new BuildException("Loader: Error occured!", location));
            }
        } catch (Throwable le) {
            System.out.println(le);
        }

    }

    /**
    *  The setter for the "loadJob" attribute
    **/
    public void setLoadJob(String msg) {
        this.loadJobFileName = msg;
    }

    /**
    * The setter for the "mode" attribute
    **/
    public void setMode(String msg) {
        this.mode = msg;
    }

    /**
    * The setter for the "userID" attribute
    **/
    public void setUserID(String msg) {
        this.userID = msg;
    }

    /**
    * The setter for the "logDir" attribute
    **/
    public void setLogDir(String msg) {
        this.logDirName = msg;
    }

    /**
    * The setter for the "logFile" attribute
    **/
    public void setLogFile(String msg) {
        this.logFileName = msg;
    }

    /**
    * The setter for the "restartIndicator" attribute
    **/
    public void setRestartIndicator(String msg) {
        this.restartIndicator = msg;
    }

    /**
    * The setter for the "vendorFile" attribute
    **/
    public void setVendorFile(String msg) {
        this.vendorFileName = msg;
    }

    /**
    * The setter for the "onErrorContinue" attribute
    **/
    public void setOnErrorContinue(String msg) {
        this.onErrorContinue = msg;
    }

    /**
    * The setter for the "commitCount" attribute
    **/
    public void setCommitCount(String msg) {
        this.commitCount = msg;
    }

    /**
    * The setter for the "returnCode" attribute
    **/
    public void setReturnCode(String rc) {
        this.returnCode = rc;
    }

    /**
    * The setter for the "AdditionalPaths" tag
    **/
    public void addConfiguredAdditionalPaths(AdditionalPaths anInner) {
        this.additionalPath = anInner.additionalPaths.substring(0, anInner.additionalPaths.indexOf("null")) + anInner.additionalPaths.substring(anInner.additionalPaths.indexOf("null") + 4, anInner.additionalPaths.length());
    }

    /**
    * The setter for the "Variables" tag
    **/
    public void addConfiguredVariables(Variables anInner) {
        this.variables = anInner.variables.substring(0, anInner.variables.indexOf("null")) + anInner.variables.substring(anInner.variables.indexOf("null") + 4, anInner.variables.length());
    }

    /**
     * The setter for the "pathToConfFile" attribute
     */
    public void setPathToConfFile(String string) {
        this.pathToConfFile = string;
    }

    /**
    * The setter for the "tableNames" attribute
     */
    public void setTableNames(String string) {
        this.tableNames = string;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -