1 2 22 23 package org.webdocwf.util.loader.generator; 24 25 import java.io.BufferedWriter ; 26 import java.io.File ; 27 import java.io.FileWriter ; 28 import java.io.Writer ; 29 import java.util.Vector ; 30 31 import org.webdocwf.util.loader.LoaderException; 32 import org.webdocwf.util.loader.logging.Logger; 33 import org.webdocwf.util.loader.logging.StandardLogger; 34 35 41 public class WriteSqlFiles { 42 private Logger logger; 43 44 53 54 public WriteSqlFiles(String tableName, int i, ImportDefinitionAttributes importDefinitionAttributes, RelationshipsAttributes relationshipsAttributes, InputParameters generatorParameters) throws LoaderException { 55 setLogger(); 56 this.logger.write("full", "WriteSqlFiles is started."); 57 Writer out; 58 SqlTagAttributes sqlTagAttributes = null; 59 String nameSQL; 60 Vector sqlStatement = generatorParameters.getSqlToGenerate(); 61 try { 62 File sqlFile = null; 63 if (generatorParameters.getGeneratorOutput().equalsIgnoreCase("")) { 64 sqlFile = new File ("sql"); 65 } else { 66 sqlFile = new File (generatorParameters.getGeneratorOutput() + "/sql"); 67 } 68 if (!sqlFile.exists()) 69 sqlFile.mkdirs(); 70 int x = 0; 71 while (x < 6) { 72 if (sqlStatement.get(x) != null) { 73 sqlTagAttributes = new SqlTagAttributes(x); 74 nameSQL = sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/") + 1, sqlTagAttributes.getHref().lastIndexOf(".")); 75 SqlStatements sqlStatements = new SqlStatements(nameSQL, tableName, importDefinitionAttributes, relationshipsAttributes, i, generatorParameters); 76 String lineSeparator = System.getProperty("line.separator"); 77 String [] lines = sqlStatements.getCreateStream(); 78 79 if (i == 0) { 80 out = new BufferedWriter (new FileWriter (sqlFile + sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/")), false)); 82 } else { 83 out = new BufferedWriter (new FileWriter (sqlFile + sqlTagAttributes.getHref().substring(sqlTagAttributes.getHref().lastIndexOf("/")), true)); 84 } 85 for (int k = 0; k < lines.length; k++) { 86 out.write(lines[k]); 87 out.write(lineSeparator); 88 } 89 out.close(); 90 } 91 x++; 92 93 } } catch (Exception e) { 95 String msg = "Exception in class WriteSqlFiles: Error has occurred when trying to write sql file!"; 96 LoaderException le = new LoaderException(msg + "\n" + e.getMessage(), (Throwable ) e); 97 this.logger.write("full","Exception:"+ msg + "\n" + le.getStackTraceAsString()); 98 throw le; 99 } 100 this.logger.write("full", "WriteSqlFiles is finished."); 101 102 } 103 107 private void setLogger() { 108 this.logger = StandardLogger.getCentralLogger(); 109 } 110 } | Popular Tags |