Coverage Report - net.sourceforge.addam.ddlgen.GenerateTask
 
Classes in this File Line Coverage Branch Coverage Complexity
GenerateTask
0%
0/62
0%
0/20
0
 
 1  
 /*
 2  
  * Copyright (c) 2004 International Decision Systems, Inc.  All Rights Reserved.
 3  
  *
 4  
  * By using this Software, You acknowledge that the Software is a valuable asset
 5  
  * and trade secret of either International Decision Systems, Inc. ("IDSI") or a
 6  
  * third party supplier of IDSI and constitutes confidential and proprietary
 7  
  * information.
 8  
  *
 9  
  * NEITHER IDSI NOR ANY AGENT OR PERSON ACTING FOR OR WITH IDSI HAS MADE OR DOES
 10  
  * MAKE ANY STATEMENTS, AFFIRMATIONS, REPRESENTATIONS OR WARRANTIES WHATSOEVER
 11  
  * TO YOU, WHETHER EXPRESS OR IMPLIED, AS TO THE SOFTWARE, THE QUALITY OR
 12  
  * CONDITION OF THE SOFTWARE, OR THE OPERATING CHARACTERISTICS OR RELIABILITY OF
 13  
  * THE SOFTWARE, OR ITS SUITABILITY FOR ANY GENERAL OR PARTICULAR PURPOSE, OR AS
 14  
  * TO ANY OTHER MATTER WHATSOEVER; ANY AND ALL OTHER WARRANTIES INCLUDING
 15  
  * WITHOUT LIMITATION ANY WARRANTIES IMPLIED BY LAW, SUCH AS THE IMPLIED
 16  
  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND TITLE,
 17  
  * USE AND NON-INFRINGEMENT; ARE HEREBY EXPRESSLY DISCLAIMED AND EXCLUDED.
 18  
 */
 19  
 package net.sourceforge.addam.ddlgen;
 20  
 
 21  
 import org.apache.tools.ant.BuildException;
 22  
 import org.apache.tools.ant.taskdefs.JDBCTask;
 23  
 
 24  
 import java.io.*;
 25  
 import java.sql.Connection;
 26  
 import java.sql.DatabaseMetaData;
 27  
 import java.sql.ResultSet;
 28  
 import java.sql.SQLException;
 29  
 import java.util.ArrayList;
 30  
 import java.util.List;
 31  
 
 32  
 /**
 33  
  * User: mkrishna
 34  
  * Date: Nov 10, 2004
 35  
  */
 36  
 
 37  0
 public class GenerateTask extends JDBCTask {
 38  
 
 39  0
     private String schema = null;
 40  0
     private String catalog = null;
 41  0
     private final List<GeneratorSpec> generatorSpecs = new ArrayList<GeneratorSpec>();
 42  
 
 43  
     public void setSchema(String schema) {
 44  0
         this.schema = schema;
 45  0
     }
 46  
 
 47  
     public void setCatalog(String catalog) {
 48  0
         this.catalog = catalog;
 49  0
     }
 50  
 
 51  
     public void addGenerator(GeneratorSpec spec) {
 52  0
         generatorSpecs.add(spec);
 53  0
     }
 54  
 
 55  
     public void execute() throws BuildException {
 56  0
         Exception exception = null;
 57  0
         ResultSet tablesRS = null;
 58  0
         Connection connection = null;
 59  
         try {
 60  0
             connection = getConnection();
 61  0
             DatabaseMetaData dbmd = connection.getMetaData();
 62  0
             if (dbmd.storesUpperCaseIdentifiers()) {
 63  0
                 catalog = (catalog == null) ? null : catalog.toUpperCase();
 64  0
                 schema = (schema == null) ? null : schema.toUpperCase();
 65  0
             } else if (dbmd.storesLowerCaseIdentifiers()) {
 66  0
                 catalog = (catalog == null) ? null : catalog.toLowerCase();
 67  0
                 schema = (schema == null) ? null : schema.toLowerCase();
 68  
             }
 69  0
             for (GeneratorSpec spec : generatorSpecs) {
 70  0
                 Generator generator = spec.getGenerator();
 71  0
                 List<String> objects = generator.getObjects(catalog,schema,spec,connection,dbmd);
 72  0
                 for (String dbObject: objects) {
 73  0
                     if (spec.includes(dbObject)) {
 74  0
                         String vendor = spec.getVendor();
 75  0
                         log("generating " + dbObject + " with " + generator.getClass().getName());
 76  0
                         BufferedWriter writer = null;
 77  0
                         Writer masterScriptWriter = spec.getMasterScriptWriter();
 78  0
                         BufferedWriter bufferedMSW = null;
 79  0
                         if (masterScriptWriter != null) {
 80  0
                             bufferedMSW = new BufferedWriter(masterScriptWriter);
 81  
                         }
 82  
                         try {
 83  0
                             writer = new BufferedWriter(spec.getFileWriter(dbObject));
 84  0
                             generator.generate(catalog, schema, dbObject, vendor, connection, dbmd, writer);
 85  0
                             if (bufferedMSW != null) {
 86  0
                                 bufferedMSW.write(spec.getFileName(dbObject));
 87  0
                                 bufferedMSW.newLine();
 88  0
                                 bufferedMSW.flush();
 89  
                             }
 90  0
                         } finally {
 91  0
                             if (writer != null) writer.close();
 92  0
                         }
 93  
                     }
 94  0
                 }
 95  0
             }
 96  0
         } catch (Exception e) {
 97  0
             exception = e;
 98  0
         } finally {
 99  0
             try {
 100  0
                 for (GeneratorSpec spec : generatorSpecs) {
 101  0
                     Writer writer = spec.getMasterScriptWriter();
 102  0
                     if (writer != null) writer.close();
 103  0
                 }
 104  0
                 if (tablesRS != null) tablesRS.close();
 105  0
                 if (connection != null) connection.close();
 106  0
             } catch (SQLException e) {
 107  0
                 exception = e;
 108  0
             } catch (IOException e) {
 109  0
                 exception = e;
 110  0
             }
 111  0
         }
 112  0
         if (exception != null) throw new BuildException(exception);
 113  0
     }
 114  
 
 115  
 }