db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henn...@apache.org
Subject cvs commit: db-torque/src/generator/src/java/org/apache/torque/task TorqueDataDumpTask.java TorqueDataModelTask.java TorqueDataSQLTask.java TorqueJDBCTransformTask.java TorqueSQLTask.java TorqueSQLTransformTask.java
Date Fri, 25 Jul 2003 16:47:43 GMT
henning     2003/07/25 09:47:43

  Modified:    src/generator/src/java/org/apache/torque/task
                        TorqueDataDumpTask.java TorqueDataModelTask.java
                        TorqueDataSQLTask.java TorqueJDBCTransformTask.java
                        TorqueSQLTask.java TorqueSQLTransformTask.java
  Log:
  Clean up the error handling in the torque tasks. This changes the
  behaviour from
  
  null:189:48: <attainGoal> null:227:49: <torque-data-model> Generation failed.
For more information consult the velocity log, or invoke ant with the -debug flag.
  
  to
  
  null:189:48: <attainGoal> null:227:49: <torque-data-model> org.apache.torque.engine.EngineException:
Attempt to set foreign key to nonexistent column: table=TABLE1, foreign column=FOO_ID
  
  or
  
  null:189:48: <attainGoal> null:227:49: <torque-data-model> org.apache.torque.engine.EngineException:
Attempt to set foreign key to nonexistent table, TABLE_XXX
  
  which at least to me is a 'little bit more helpful'. Mainly because
  you won't get any help from maven -X or the velocity.log
  
  Revision  Changes    Path
  1.3       +8 -8      db-torque/src/generator/src/java/org/apache/torque/task/TorqueDataDumpTask.java
  
  Index: TorqueDataDumpTask.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/task/TorqueDataDumpTask.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TorqueDataDumpTask.java	18 Feb 2003 08:05:51 -0000	1.2
  +++ TorqueDataDumpTask.java	25 Jul 2003 16:47:42 -0000	1.3
  @@ -223,17 +223,17 @@
   
           context.put("dataset", "all");
   
  -        StringBuffer buf = new StringBuffer("Database settings:\n")
  -            .append(" driver: ").append(databaseDriver).append('\n')
  -            .append(" URL: ").append(databaseUrl).append('\n')
  -            .append(" user: ").append(databaseUser).append('\n')
  -            .append(" password: ").append(databasePassword).append('\n');
  -        log(buf.toString(), Project.MSG_DEBUG);
  +        log("Torque - TorqueDataDump starting");
  +        log("Your DB settings are:");
  +        log("driver: " + databaseDriver);
  +        log("URL: " + databaseUrl);
  +        log("user: " + databaseUser);
  +        // log("password: " + databasePassword);
   
           try
           {
               Class.forName(databaseDriver);
  -            log("DB driver instantiated sucessfuly", Project.MSG_DEBUG);
  +            log("DB driver instantiated sucessfully", Project.MSG_DEBUG);
   
               conn = DriverManager.getConnection(
                       databaseUrl, databaseUser, databasePassword);
  
  
  
  1.2       +52 -40    db-torque/src/generator/src/java/org/apache/torque/task/TorqueDataModelTask.java
  
  Index: TorqueDataModelTask.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/task/TorqueDataModelTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TorqueDataModelTask.java	10 Feb 2003 13:20:59 -0000	1.1
  +++ TorqueDataModelTask.java	25 Jul 2003 16:47:42 -0000	1.2
  @@ -55,18 +55,23 @@
    */
   
   import java.io.File;
  +
   import java.util.ArrayList;
   import java.util.Hashtable;
   import java.util.Iterator;
   import java.util.List;
   
   import org.apache.commons.lang.StringUtils;
  +
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.types.FileSet;
  +
  +import org.apache.torque.engine.EngineException;
   import org.apache.torque.engine.database.model.AppData;
   import org.apache.torque.engine.database.model.Database;
   import org.apache.torque.engine.database.transform.XmlToAppData;
  +
   import org.apache.velocity.VelocityContext;
   import org.apache.velocity.context.Context;
   import org.apache.velocity.texen.ant.TexenTask;
  @@ -303,53 +308,60 @@
                       + "fileset of XML schemas!");
           }
   
  -        if (xmlFile != null)
  +        try
           {
  -            // Transform the XML database schema into
  -            // data model object.
  -            xmlParser = new XmlToAppData(getTargetDatabase(),
  -                    getTargetPackage(), getBasePathToDbProps());
  -            AppData ad = xmlParser.parseFile(xmlFile);
  -            ad.setName(grokName(xmlFile));
  -            dataModels.add(ad);
  -        }
  -        else
  -        {
  -            // Deal with the filesets.
  -            for (int i = 0; i < filesets.size(); i++)
  +            if (xmlFile != null)
               {
  -                FileSet fs = (FileSet) filesets.get(i);
  -                DirectoryScanner ds = fs.getDirectoryScanner(project);
  -                File srcDir = fs.getDir(project);
  -
  -                String[] dataModelFiles = ds.getIncludedFiles();
  -
  -                // Make a transaction for each file
  -                for (int j = 0; j < dataModelFiles.length; j++)
  +                // Transform the XML database schema into
  +                // data model object.
  +                xmlParser = new XmlToAppData(getTargetDatabase(),
  +                        getTargetPackage(), getBasePathToDbProps());
  +                AppData ad = xmlParser.parseFile(xmlFile);
  +                ad.setName(grokName(xmlFile));
  +                dataModels.add(ad);
  +            }
  +            else
  +            {
  +                // Deal with the filesets.
  +                for (int i = 0; i < filesets.size(); i++)
                   {
  -                    File f = new File(srcDir, dataModelFiles[j]);
  -                    xmlParser = new XmlToAppData(getTargetDatabase(),
  -                                                 getTargetPackage(),
  -                                                 getBasePathToDbProps());
  -                    AppData ad = xmlParser.parseFile(f.toString());
  -                    ad.setName(grokName(f.toString()));
  -                    dataModels.add(ad);
  +                    FileSet fs = (FileSet) filesets.get(i);
  +                    DirectoryScanner ds = fs.getDirectoryScanner(project);
  +                    File srcDir = fs.getDir(project);
  +                    
  +                    String[] dataModelFiles = ds.getIncludedFiles();
  +                    
  +                    // Make a transaction for each file
  +                    for (int j = 0; j < dataModelFiles.length; j++)
  +                    {
  +                        File f = new File(srcDir, dataModelFiles[j]);
  +                        xmlParser = new XmlToAppData(getTargetDatabase(),
  +                                getTargetPackage(),
  +                                getBasePathToDbProps());
  +                        AppData ad = xmlParser.parseFile(f.toString());
  +                        ad.setName(grokName(f.toString()));
  +                        dataModels.add(ad);
  +                    }
                   }
               }
  +            
  +            Iterator i = dataModels.iterator();
  +            databaseNames = new Hashtable();
  +            dataModelDbMap = new Hashtable();
  +            
  +            // Different datamodels may state the same database
  +            // names, we just want the unique names of databases.
  +            while (i.hasNext())
  +            {
  +                AppData ad = (AppData) i.next();
  +                Database database = ad.getDatabase();
  +                databaseNames.put(database.getName(), database.getName());
  +                dataModelDbMap.put(ad.getName(), database.getName());
  +            }
           }
  -
  -        Iterator i = dataModels.iterator();
  -        databaseNames = new Hashtable();
  -        dataModelDbMap = new Hashtable();
  -
  -        // Different datamodels may state the same database
  -        // names, we just want the unique names of databases.
  -        while (i.hasNext())
  +        catch (EngineException ee)
           {
  -            AppData ad = (AppData) i.next();
  -            Database database = ad.getDatabase();
  -            databaseNames.put(database.getName(), database.getName());
  -            dataModelDbMap.put(ad.getName(), database.getName());
  +            throw new BuildException(ee);
           }
   
           context = new VelocityContext();
  
  
  
  1.4       +27 -22    db-torque/src/generator/src/java/org/apache/torque/task/TorqueDataSQLTask.java
  
  Index: TorqueDataSQLTask.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/task/TorqueDataSQLTask.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TorqueDataSQLTask.java	26 Jun 2003 05:57:37 -0000	1.3
  +++ TorqueDataSQLTask.java	25 Jul 2003 16:47:42 -0000	1.4
  @@ -57,14 +57,19 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
  +
   import java.util.ArrayList;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Properties;
  +
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.DirectoryScanner;
   import org.apache.tools.ant.types.FileSet;
  +
   import org.apache.velocity.context.Context;
  +
  +import org.apache.torque.engine.EngineException;
   import org.apache.torque.engine.database.model.AppData;
   import org.apache.torque.engine.database.model.Database;
   import org.apache.torque.engine.database.transform.XmlToData;
  @@ -168,13 +173,13 @@
                       + "a fileset of XML data files!");
           }
   
  -        AppData app = (AppData) getDataModels().get(0);
  -        Database db = app.getDatabase();
  -                        
  -        List data;
  -
           try
           {
  +            AppData app = (AppData) getDataModels().get(0);
  +            Database db = app.getDatabase();
  +            
  +            List data;
  +            
               if (dataXmlFile != null)
               {
                   XmlToData dataXmlParser = new XmlToData(db, dataDTD);
  @@ -208,25 +213,25 @@
                   }
               }
               context.put("data", data);
  -        }
  -        catch (Exception e)
  -        {
  -            throw new Exception("Exception parsing data XML:");
  -        }
  -
  -        // Place our model in the context.
  -        context.put("appData", app);
   
  -        // Place the target database in the context.
  -        context.put("targetDatabase", targetDatabase);
  +            // Place our model in the context.
  +            context.put("appData", app);
   
  -        Properties p = new Properties();
  -        FileInputStream fis = new FileInputStream(getSqlDbMap());
  -        p.load(fis);
  -        fis.close();
  +            // Place the target database in the context.
  +            context.put("targetDatabase", targetDatabase);
   
  -        p.setProperty(getOutputFile(), db.getName());
  -        p.store(new FileOutputStream(getSqlDbMap()), "Sqlfile -> Database map");
  +            Properties p = new Properties();
  +            FileInputStream fis = new FileInputStream(getSqlDbMap());
  +            p.load(fis);
  +            fis.close();
  +            
  +            p.setProperty(getOutputFile(), db.getName());
  +            p.store(new FileOutputStream(getSqlDbMap()), "Sqlfile -> Database map");
  +        }
  +        catch (EngineException ee)
  +        {
  +            throw new BuildException(ee);
  +        }
   
           return context;
       }
  
  
  
  1.5       +7 -6      db-torque/src/generator/src/java/org/apache/torque/task/TorqueJDBCTransformTask.java
  
  Index: TorqueJDBCTransformTask.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/task/TorqueJDBCTransformTask.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TorqueJDBCTransformTask.java	29 Jun 2003 13:39:05 -0000	1.4
  +++ TorqueJDBCTransformTask.java	25 Jul 2003 16:47:42 -0000	1.5
  @@ -56,12 +56,14 @@
   
   import java.io.FileOutputStream;
   import java.io.PrintWriter;
  +
   import java.sql.Connection;
   import java.sql.DatabaseMetaData;
   import java.sql.DriverManager;
   import java.sql.ResultSet;
   import java.sql.SQLException;
   import java.sql.Types;
  +
   import java.util.ArrayList;
   import java.util.Collection;
   import java.util.Hashtable;
  @@ -180,12 +182,12 @@
        */
       public void execute() throws BuildException
       {
  -        log("Torque - JDBCToXMLSchema starting\n");
  +        log("Torque - JDBCToXMLSchema starting");
           log("Your DB settings are:");
           log("driver : " + dbDriver);
           log("URL : " + dbUrl);
           log("user : " + dbUser);
  -//        log("password : " + dbPassword);
  +        // log("password : " + dbPassword);
           log("schema : " + dbSchema);
   
           DocumentTypeImpl docType = new DocumentTypeImpl(null, "database", null,
  @@ -206,10 +208,9 @@
           }
           catch (Exception e)
           {
  -            log(e.toString());
  -            e.printStackTrace();
  +            throw new BuildException(e);
           }
  -        log("\nTorque - JDBCToXMLSchema finished");
  +        log("Torque - JDBCToXMLSchema finished");
       }
   
       /**
  
  
  
  1.2       +23 -9     db-torque/src/generator/src/java/org/apache/torque/task/TorqueSQLTask.java
  
  Index: TorqueSQLTask.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/task/TorqueSQLTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TorqueSQLTask.java	10 Feb 2003 13:20:59 -0000	1.1
  +++ TorqueSQLTask.java	25 Jul 2003 16:47:42 -0000	1.2
  @@ -57,9 +57,15 @@
   import java.io.File;
   import java.io.FileInputStream;
   import java.io.FileOutputStream;
  -import java.util.Properties;
  +
   import java.util.Iterator;
  +import java.util.Properties;
  +
  +import org.apache.tools.ant.BuildException;
  +
   import org.apache.velocity.context.Context;
  +
  +import org.apache.torque.engine.EngineException;
   import org.apache.torque.engine.database.transform.XmlToAppData;
   import org.apache.torque.engine.database.model.AppData;
   
  @@ -197,13 +203,14 @@
        * the model to the context under the name "idmodel".
        */
       public void loadIdBrokerModel()
  +            throws EngineException
       {
           // Transform the XML database schema into
           // data model object.
           XmlToAppData xmlParser = new XmlToAppData(getTargetDatabase(), null,
                                                     getBasePathToDbProps());
           AppData ad = xmlParser.parseFile(getIdTableXMLFile());
  -        xmlParser.parseFile(getIdTableXMLFile());
  +
           ad.setName("idmodel");
           context.put("idmodel", ad);
       }
  @@ -218,14 +225,21 @@
       public Context initControlContext() throws Exception
       {
           super.initControlContext();
  -        createSqlDbMap();
  +        try
  +        {
  +            createSqlDbMap();
   
  -        // If the load path for the id broker table xml schema is
  -        // defined then load it.
  -        String f = getIdTableXMLFile();
  -        if (f != null && f.length() > 0)
  +            // If the load path for the id broker table xml schema is
  +            // defined then load it.
  +            String f = getIdTableXMLFile();
  +            if (f != null && f.length() > 0)
  +            {
  +                loadIdBrokerModel();
  +            }
  +        }
  +        catch (EngineException ee)
           {
  -            loadIdBrokerModel();
  +            throw new BuildException(ee);
           }
   
           return context;
  
  
  
  1.2       +7 -8      db-torque/src/generator/src/java/org/apache/torque/task/TorqueSQLTransformTask.java
  
  Index: TorqueSQLTransformTask.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/task/TorqueSQLTransformTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TorqueSQLTransformTask.java	10 Feb 2003 13:20:59 -0000	1.1
  +++ TorqueSQLTransformTask.java	25 Jul 2003 16:47:42 -0000	1.2
  @@ -56,8 +56,10 @@
   
   import java.io.BufferedWriter;
   import java.io.FileWriter;
  +
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Task;
  +
   import org.apache.torque.engine.database.model.AppData;
   import org.apache.torque.engine.database.transform.SQLToAppData;
   
  @@ -128,27 +130,24 @@
       {
           try
           {
  -            System.out.println("Parsing SQL Schema");
  +            log("Parsing SQL Schema", project.MSG_INFO);
   
               SQLToAppData sqlParser = new SQLToAppData(inputFile);
               AppData app = sqlParser.execute();
   
  -            System.out.println("Preparing to write xml schema");
  +            log("Preparing to write xml schema", project.MSG_INFO);
               FileWriter fr = new FileWriter(outputFile);
               BufferedWriter br = new BufferedWriter (fr);
   
               br.write(app.toString());
   
  -            System.out.println("Writing xml schema");
  +            log("Writing xml schema", project.MSG_INFO);
   
               br.flush();
               br.close();
           }
  -        catch (Throwable e)
  +        catch (Exception e)
           {
  -            // Propagate the error up the stack so that
  -            // the stacktrace will appear in the standard
  -            // ant output.
               throw new BuildException(e);
           }
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message