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

📄 writesqlfiles.java

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

/*
LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.


    Copyright (C) 2003  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
*/

package org.webdocwf.util.loader.generator;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.Writer;
import java.util.Vector;

import org.webdocwf.util.loader.LoaderException;
import org.webdocwf.util.loader.logging.Logger;
import org.webdocwf.util.loader.logging.StandardLogger;

/**
 *
 * WriteSqlFiles class creates sql files from input data.
 * @author Radoslav Dutina
 * @version 1.0
 */
public class WriteSqlFiles {
    private Logger logger;

    /**
     * Construct object WriteSqlFiles with associated parameters.
     * @param generatorParameters represents the references to InputParameter object.
     * @param tableName is name of the table form which we retrieve data.
     * @param i is the number of tables in generatorOutput directories.
     * @param importDefinitionAttributes is references to ImportDefinitionAttributes object.
     * @param relationshipsAttributes is references to RelationshipsAttributes object.
     * @throws LoaderException
     */

    public WriteSqlFiles(String tableName, int i, ImportDefinitionAttributes importDefinitionAttributes, RelationshipsAttributes relationshipsAttributes, InputParameters generatorParameters) throws LoaderException {
				setLogger();
				this.logger.write("full", "WriteSqlFiles is started.");
        Writer out;
        SqlTagAttributes sqlTagAttributes = null;
        String nameSQL;
        Vector sqlStatement = generatorParameters.getSqlToGenerate();
        try {
            File sqlFile = null;
            if (generatorParameters.getGeneratorOutput().equalsIgnoreCase("")) {
                sqlFile = new File("sql");
            } else {
                sqlFile = new File(generatorParameters.getGeneratorOutput() + "/sql");
            }
            if (!sqlFile.exists())
                sqlFile.mkdirs();
            int x = 0;
            while (x < 6) {
                if (sqlStatement.get(x) != null) {
                    sqlTagAttributes = new SqlTagAttributes(x);
                    nameSQL = sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/") + 1, sqlTagAttributes.getHref().lastIndexOf("."));
                    SqlStatements sqlStatements = new SqlStatements(nameSQL, tableName, importDefinitionAttributes, relationshipsAttributes, i, generatorParameters);
                    String lineSeparator = System.getProperty("line.separator");
                    String[] lines = sqlStatements.getCreateStream();

                    if (i == 0) {
                        //this is the first time, that we are write sql files.
                        out = new BufferedWriter(new FileWriter(sqlFile + sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/")), false));
                    } else {
                        out = new BufferedWriter(new FileWriter(sqlFile + sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/")), true));
                    }
                    for (int k = 0; k < lines.length; k++) {
                        out.write(lines[k]);
                        out.write(lineSeparator);
                    }
                    out.close();
                }
                x++;

            } //end while
        } catch (Exception e) {
            String msg = "Exception in class WriteSqlFiles: Error has occurred when trying to write sql file!";
            LoaderException le = new LoaderException(msg + "\n" + e.getMessage(), (Throwable) e);
						this.logger.write("full","Exception:"+ msg + "\n" + le.getStackTraceAsString());
            throw le;
        }
		this.logger.write("full", "WriteSqlFiles is finished.");

    }
    /**
     * This method will set logger object
   	 * @param logger
	   */
    private void setLogger() {
        this.logger = StandardLogger.getCentralLogger();
    }
}

⌨️ 快捷键说明

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