jvanzyl 01/10/27 12:04:39 Modified: src/java/org/apache/torque/task TorqueCreateDatabase.java TorqueDataDTDTask.java TorqueDataDumpTask.java TorqueDataModelTask.java TorqueDataSQLTask.java TorqueJDBCTransformTask.java TorqueObjectModelTask.java TorqueSQLTask.java TorqueSQLTransformTask.java Log: - all the changes in the tasks that have occured in the 2.x branch and in the decoupled torque have now been merged together and placed in the decoupled torque. once i am finished checking in all the changes i will attempt to get turbine 2.x to work with the decoupled torque as it will become impossible to maintain both trees. i have tested all the changes i have made with scarab who is the primary consumer of the decoupled torque so their build shouldn't be affected by the changes i've made. i used the a newly created torque.zip file and the a build of velocity from CVS which includes fixes to correct contextProperties attribute processing. Revision Changes Path 1.4 +14 -58 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueCreateDatabase.java Index: TorqueCreateDatabase.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueCreateDatabase.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TorqueCreateDatabase.java 2001/09/25 20:57:48 1.3 +++ TorqueCreateDatabase.java 2001/10/27 19:04:37 1.4 @@ -25,13 +25,13 @@ * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Turbine" must not be used to endorse or promote products - * derived from this software without prior written permission. For + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Turbine" must not be used to endorse or promote products + * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", - * "Apache Turbine", nor may "Apache" appear in their name, without + * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED @@ -56,33 +56,18 @@ import org.apache.velocity.context.Context; import org.apache.velocity.VelocityContext; -import org.apache.velocity.texen.ant.TexenTask; -import org.apache.torque.engine.database.model.AppData; -import org.apache.torque.engine.database.transform.XmlToAppData; - /** * An extended Texen task used for generating simple scripts * for creating databases on various platforms. * - * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> - * @version $Id: TorqueCreateDatabase.java,v 1.3 2001/09/25 20:57:48 jvanzyl Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> + * @version $Id: TorqueCreateDatabase.java,v 1.4 2001/10/27 19:04:37 jvanzyl Exp $ */ -public class TorqueCreateDatabase - extends TexenTask +public class TorqueCreateDatabase + extends TorqueDataModelTask { /** - * Application model. In this case a database model. - */ - private AppData app; - - /** - * XML that describes the database model, this is transformed - * into the application model object. - */ - private String xmlFile; - - /** * The target database vendor: MySQL, Oracle. */ private String targetDatabase; @@ -98,40 +83,18 @@ * Database user. */ private String databaseUser; - + /** * Password for specified database user. */ private String databasePassword; - + /** * Host on which specified database resides. */ private String databaseHost; /** - * Get the xml schema describing the application - * model. - * - * @return String xml schema file. - */ - public String getXmlFile () - { - return xmlFile; - } - - /** - * Set the xml schema describing the application - * model. - * - * @param String xml schema file. - */ - public void setXmlFile(String v) - { - xmlFile = v; - } - - /** * Get the target database. * * @return String target database. @@ -237,23 +200,16 @@ * templates. */ public Context initControlContext() - { - // Create a new Velocity context. - Context context = new VelocityContext(); + throws Exception + { + super.initControlContext(); - // Transform the XML database schema into an object that - // represents our model. - XmlToAppData xmlParser = new XmlToAppData(); - app = xmlParser.parseFile(xmlFile); - - // Place our model in the context. - context.put("appData", app); - context.put("targetDatabase", targetDatabase); context.put("targetPlatform", targetPlatform); context.put("databaseUser", databaseUser); context.put("databasePassword", databasePassword); context.put("databaseHost", databaseHost); + return context; } } 1.3 +7 -76 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataDTDTask.java Index: TorqueDataDTDTask.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataDTDTask.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TorqueDataDTDTask.java 2001/08/10 12:23:03 1.2 +++ TorqueDataDTDTask.java 2001/10/27 19:04:38 1.3 @@ -54,85 +54,16 @@ * <http://www.apache.org/>. */ -import java.util.Date; -import org.apache.velocity.context.Context; -import org.apache.velocity.VelocityContext; -import org.apache.velocity.texen.ant.TexenTask; -import org.apache.torque.engine.database.model.AppData; -import org.apache.torque.engine.database.transform.XmlToAppData; - /** - * An extended Texen task used for generating data DTD from - * an XML schema describing a database structure. + * An extended Texen task used for generating data DTD from + * an XML schema describing a database structure. * - * @author <a href="mailto:[EMAIL PROTECTED]"> Fedor Karpelevitch </a> - * @version $Id: TorqueDataDTDTask.java,v 1.2 2001/08/10 12:23:03 knielsen Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]"> Fedor Karpelevitch </a> + * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> + * @version $Id: TorqueDataDTDTask.java,v 1.3 2001/10/27 19:04:38 jvanzyl Exp $ */ -public class TorqueDataDTDTask - extends TexenTask +public class TorqueDataDTDTask + extends TorqueDataModelTask { - /** - * Application model. In this case a database model. - */ - private AppData app; - - /** - * XML that describes the database model, this is transformed - * into the application model object. - */ - private String xmlFile; - - - /** - * Get the xml schema describing the application - * model. - * - * @return String xml schema file. - */ - public String getXmlFile() - { - return xmlFile; - } - - - /** - * Set the xml schema describing the application - * model. - * - * @param v The new XmlFile value - */ - public void setXmlFile(String v) - { - xmlFile = v; - } - - - /** - * Set up the initialial context for generating the - * SQL from the XML schema. - * - * @return Description of the Returned Value - */ - public Context initControlContext() - { - /* - * Create a new Velocity context. - */ - Context context = new VelocityContext(); - - /* - * Transform the XML database schema into an - * object that represents our model. - */ - XmlToAppData xmlParser = new XmlToAppData(); - app = xmlParser.parseFile(xmlFile); - - /* - * Place our model in the context. - */ - context.put("appData", app); - - return context; - } } 1.3 +8 -70 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataDumpTask.java Index: TorqueDataDumpTask.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/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 2001/08/10 12:23:03 1.2 +++ TorqueDataDumpTask.java 2001/10/27 19:04:38 1.3 @@ -72,26 +72,19 @@ /** * An extended Texen task used for dumping data from db into XML * - * @author <a href="mailto:[EMAIL PROTECTED]"> Fedor Karpelevitch </a> - * @version $Id: TorqueDataDumpTask.java,v 1.2 2001/08/10 12:23:03 knielsen Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]"> Fedor Karpelevitch </a> + * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a> + * @version $Id: TorqueDataDumpTask.java,v 1.3 2001/10/27 19:04:38 jvanzyl Exp $ */ public class TorqueDataDumpTask - extends TexenTask + extends TorqueDataModelTask { /** - * Application model. In this case a database model. + * Database name. */ - private AppData app; - private String databaseName; /** - * XML that describes the database model, this is transformed - * into the application model object. - */ - private String xmlFile; - - /** * Database URL used for JDBC connection. */ private String databaseUrl; @@ -111,32 +104,7 @@ */ private String databasePassword; - /** - * Get the xml schema describing the application - * model. - * - * @return String xml schema file. - */ - public String getXmlFile() - { - return xmlFile; - } - - - /** - * Set the xml schema describing the application - * model. - * - * @param v The new XmlFile value - */ - public void setXmlFile(String v) - { - xmlFile = v; - } - - - /** * Get the database name to dump * * @return The DatabaseName value @@ -146,7 +114,6 @@ return databaseName; } - /** * Set the database name * @@ -157,7 +124,6 @@ databaseName = v; } - /** * Get the database url * @@ -168,7 +134,6 @@ return databaseUrl; } - /** * Set the database url * @@ -179,7 +144,6 @@ databaseUrl = v; } - /** * Get the database driver name * @@ -190,7 +154,6 @@ return databaseDriver; } - /** * Set the database driver name * @@ -201,7 +164,6 @@ databaseDriver = v; } - /** * Get the database user * @@ -212,7 +174,6 @@ return databaseUser; } - /** * Set the database user * @@ -223,7 +184,6 @@ databaseUser = v; } - /** * Get the database password * @@ -234,7 +194,6 @@ return databasePassword; } - /** * Set the database password * @@ -245,36 +204,16 @@ databasePassword = v; } - /** * Initializes initial context * * @return Description of the Returned Value */ public Context initControlContext() + throws Exception { - /* - * Create a new Velocity context. - */ - Context context = new VelocityContext(); - - /* - * Transform the XML database schema into an - * object that represents our model. - */ - XmlToAppData xmlParser = new XmlToAppData(); - app = xmlParser.parseFile(xmlFile); - - /* - * Place our model in the context. - */ - Database dbm = app.getDatabase(databaseName); - if (dbm == null) - { - dbm = app.getDatabases()[0]; - } - context.put("databaseModel", dbm); - + super.initControlContext(); + context.put("dataset", "all"); System.err.println("Your DB settings are:"); @@ -309,7 +248,6 @@ return context; } - /** * A nasty do-it-all tool class. It serves as: 1.4 +10 -8 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataModelTask.java Index: TorqueDataModelTask.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataModelTask.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- TorqueDataModelTask.java 2001/10/25 00:19:52 1.3 +++ TorqueDataModelTask.java 2001/10/27 19:04:38 1.4 @@ -1,4 +1,4 @@ -package org.apache.torque; +package org.apache.torque.task; /* ==================================================================== * The Apache Software License, Version 1.1 @@ -180,9 +180,9 @@ * * @param v The new XmlFile value */ - public void setXmlFile(String v) + public void setXmlFile(String xmlFile) { - xmlFile = v; + this.xmlFile = project.resolveFile(xmlFile).toString(); } /** @@ -217,7 +217,10 @@ xmlParser = new XmlToAppData(); AppData ad = xmlParser.parseFile(xmlFile); xmlParser.parseFile(xmlFile); - //FIXME: ad.setName(xmlFile.substring(0,xmlFile.indexOf("."))); + String name = xmlFile.substring( + xmlFile.lastIndexOf(System.getProperty("file.separator"))+1, + xmlFile.indexOf(".")); + ad.setName(name); dataModels.addElement(ad); } else @@ -240,7 +243,7 @@ xmlParser.parseFile( new File(srcDir, dataModelFiles[j]).toString()); - //FIXME: ad.setName(dataModelFiles[j].substring(0,dataModelFiles[j].indexOf("."))); + ad.setName(dataModelFiles[j].substring(0,dataModelFiles[j].indexOf("."))); dataModels.addElement(ad); } } @@ -255,10 +258,9 @@ while (i.hasNext()) { AppData ad = (AppData) i.next(); - //FIXME: Database database = ad.getDatabase(); - Database database = null; + Database database = ad.getDatabase(); databaseNames.put(database.getName(), database.getName()); - //FIXME: dataModelDbMap.put(ad.getName(), database.getName()); + dataModelDbMap.put(ad.getName(), database.getName()); } // Create a new Velocity context. 1.3 +27 -99 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataSQLTask.java Index: TorqueDataSQLTask.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueDataSQLTask.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TorqueDataSQLTask.java 2001/08/10 12:23:03 1.2 +++ TorqueDataSQLTask.java 2001/10/27 19:04:38 1.3 @@ -54,41 +54,31 @@ * <http://www.apache.org/>. */ -import java.util.Date; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.util.List; +import java.util.Properties; import org.apache.velocity.context.Context; import org.apache.velocity.VelocityContext; -import org.apache.velocity.texen.ant.TexenTask; 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.torque.engine.database.transform.XmlToData; /** * An extended Texen task used for generating SQL source from * an XML data file * - * @author <a href="mailto:[EMAIL PROTECTED]"> Jason van Zyl </a> + * @author <a href="mailto:[EMAIL PROTECTED]"> Jason van Zyl </a> * @author <a href="mailto:[EMAIL PROTECTED]"> John McNally </a> * @author <a href="mailto:[EMAIL PROTECTED]"> Fedor Karpelevitch </a> - * @version $Id: TorqueDataSQLTask.java,v 1.2 2001/08/10 12:23:03 knielsen Exp $ + * @version $Id: TorqueDataSQLTask.java,v 1.3 2001/10/27 19:04:38 jvanzyl Exp $ */ public class TorqueDataSQLTask - extends TexenTask + extends TorqueDataModelTask { - /** - * Application model. In this case a database model. - */ - private AppData app; - - /** - * XML that describes the database model, this is transformed - * into the application model object. - */ - private String xmlFile; private String dataXmlFile; private String dataDTD; - + /** * The target database(s) we are generating SQL * for. Right now we can only deal with a single @@ -97,33 +87,6 @@ */ private String targetDatabase; - private String databaseName; - - - /** - * Get the xml schema describing the application - * model. - * - * @return String xml schema file. - */ - public String getXmlFile() - { - return xmlFile; - } - - - /** - * Set the xml schema describing the application - * model. - * - * @param v The new XmlFile value - */ - public void setXmlFile(String v) - { - xmlFile = v; - } - - /** * Sets the DataXmlFile attribute of the TorqueDataSQLTask object * @@ -134,7 +97,6 @@ dataXmlFile = v; } - /** * Gets the DataXmlFile attribute of the TorqueDataSQLTask object * @@ -145,7 +107,6 @@ return dataXmlFile; } - /** * Get the current target database. * @@ -156,7 +117,6 @@ return targetDatabase; } - /** * Set the current target database. This is where * generated java classes will live. @@ -168,30 +128,7 @@ targetDatabase = v; } - - /** - * Gets the DatabaseName attribute of the TorqueDataSQLTask object - * - * @return The DatabaseName value - */ - public String getDatabaseName() - { - return databaseName; - } - - /** - * Sets the DatabaseName attribute of the TorqueDataSQLTask object - * - * @param v The new DatabaseName value - */ - public void setDatabaseName(String v) - { - databaseName = v; - } - - - /** * Gets the DataDTD attribute of the TorqueDataSQLTask object * * @return The DataDTD value @@ -201,7 +138,6 @@ return dataDTD; } - /** * Sets the DataDTD attribute of the TorqueDataSQLTask object * @@ -211,8 +147,7 @@ { dataDTD = v; } - - + /** * Set up the initialial context for generating the * SQL from the XML schema. @@ -220,24 +155,13 @@ * @return Description of the Returned Value */ public Context initControlContext() + throws Exception { - /* - * Create a new Velocity context. - */ - Context context = new VelocityContext(); - - /* - * Transform the XML database schema into an - * object that represents our model. - */ - XmlToAppData xmlParser = new XmlToAppData(); - app = xmlParser.parseFile(xmlFile); - - Database db = app.getDatabase(databaseName); - if (db == null) - { - db = app.getDatabases()[0]; - } + super.initControlContext(); + + AppData app = (AppData) getDataModels().elementAt(0); + Database db = app.getDatabase(); + try { XmlToData dataXmlParser = new XmlToData(db, dataDTD); @@ -246,19 +170,23 @@ } catch (Exception e) { - System.err.println("Exception parsing data XML:"); - e.printStackTrace(); + throw new Exception("Exception parsing data XML:"); } - /* - * Place our model in the context. - */ + + // Place our model in the context. context.put("appData", app); - /* - * Place the target database in the context. - */ + // Place the target database in the context. context.put("targetDatabase", targetDatabase); - + + 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"); + return context; } } 1.2 +23 -2 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueJDBCTransformTask.java Index: TorqueJDBCTransformTask.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueJDBCTransformTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TorqueJDBCTransformTask.java 2001/08/02 05:08:37 1.1 +++ TorqueJDBCTransformTask.java 2001/10/27 19:04:38 1.2 @@ -90,9 +90,9 @@ * This class generates an XML schema of an existing database from * JDBC metadata. * - * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @author <a href="mailto:[EMAIL PROTECTED]">Fedor Karpelevitch</a> - * @version $Id: TorqueJDBCTransformTask.java,v 1.1 2001/08/02 05:08:37 jvanzyl Exp $ + * @version $Id: TorqueJDBCTransformTask.java,v 1.2 2001/10/27 19:04:38 jvanzyl Exp $ */ public class TorqueJDBCTransformTask extends Task { @@ -288,6 +288,7 @@ /* int columnNullableUnknown = 2; */ Integer nullType = (Integer) v.elementAt(3); + String defValue = (String)v.elementAt(4); Element column = doc.createElement("column"); column.setAttribute("name", name); @@ -316,6 +317,24 @@ column.setAttribute("primaryKey", "true"); } + if (defValue!=null) + { + // trim out parens & quotes out of def value. + // makes sense for MSSQL. not sure about others. + + if (defValue.startsWith("(") && defValue.endsWith(")")) + { + defValue = defValue.substring(1, defValue.length()-1); + } + + if (defValue.startsWith("'") && defValue.endsWith("'")) + { + defValue = defValue.substring(1, defValue.length()-1); + } + + column.setAttribute("default", defValue); + } + table.appendChild(column); } @@ -397,12 +416,14 @@ Integer sqlType = new Integer(columnSet.getString(5)); Integer size = new Integer(columnSet.getInt(7)); Integer nullType = new Integer(columnSet.getInt(11)); + String defValue = columnSet.getString(13); Vector v = new Vector(); v.addElement (name); v.addElement (sqlType); v.addElement (size); v.addElement (nullType); + v.addElement (defValue); columns.addElement (v); } return columns; 1.3 +5 -107 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueObjectModelTask.java Index: TorqueObjectModelTask.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueObjectModelTask.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TorqueObjectModelTask.java 2001/08/22 20:11:08 1.2 +++ TorqueObjectModelTask.java 2001/10/27 19:04:38 1.3 @@ -54,67 +54,26 @@ * <http://www.apache.org/>. */ -import java.util.Date; - import org.apache.velocity.context.Context; -import org.apache.velocity.texen.ant.TexenTask; -import org.apache.torque.engine.database.model.AppData; -import org.apache.torque.engine.database.transform.XmlToAppData; +import org.apache.velocity.VelocityContext; /** * An ant task for generating output by using Velocity * - * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @author <a href="mailto:[EMAIL PROTECTED]>John McNally</a> - * @version $Id: TorqueObjectModelTask.java,v 1.2 2001/08/22 20:11:08 dlr Exp $ + * @version $Id: TorqueObjectModelTask.java,v 1.3 2001/10/27 19:04:38 jvanzyl Exp $ */ -public class TorqueObjectModelTask extends TexenTask +public class TorqueObjectModelTask + extends TorqueDataModelTask { /** - * Application model. - */ - private AppData app; - - /** - * XML schema file. - */ - private String xmlFile; - - /** * Target Java package to place the generated * files in. */ private String targetPackage; /** - * The target database(s) we are generating SQL - * for. Right now we can only deal with a single - * target, but we will support multiple targets - * soon. - */ - private String targetDatabase; - - /** - * Get the current xml file. - * - * @return String xml schema file. - */ - public String getXmlFile () - { - return xmlFile; - } - - /** - * Set the xml file. - * - * @param String xml schema file. - */ - public void setXmlFile(String v) - { - xmlFile = v; - } - - /** * Get the current target package. * * @return return target java package. @@ -133,66 +92,5 @@ public void setTargetPackage (String v) { targetPackage = v; - } - - /** - * Get the current target database. - * - * @return String target database(s) - */ - public String getTargetDatabase () - { - return targetDatabase; - } - - /** - * Set the current target database. - * - * @param String target database(s) - */ - public void setTargetDatabase (String v) - { - targetDatabase = v; - } - - /** - * Populates the initialial context with the model used to - * generate SQL from a XML schema. - * - * @param context The initial context, ripe for population. - * @exception Exception None expected. - */ - protected void populateInitialContext(Context context) - throws Exception - { - super.populateInitialContext(context); - - /* - * Build our application model from the - * XML schema. Can someone document the - * double pass here? - */ - XmlToAppData xmlParser = new XmlToAppData(); - - app = xmlParser.parseFile(xmlFile); - xmlParser.parseFile(xmlFile); - - /* - * Place some initial values in the context. - * most of these could be automatically fed - * into the context with the contextProperties - * option. - */ - context.put("appData", app); - - /* - * Place the target database in the context. - */ - context.put("targetDatabase", targetDatabase); - - /* - * Place the target package in the context. - */ - context.put("targetPackage", targetPackage); } } 1.7 +92 -65 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueSQLTask.java Index: TorqueSQLTask.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueSQLTask.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- TorqueSQLTask.java 2001/09/25 20:57:48 1.6 +++ TorqueSQLTask.java 2001/10/27 19:04:38 1.7 @@ -25,13 +25,13 @@ * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * - * 4. The names "Apache" and "Apache Software Foundation" and - * "Apache Turbine" must not be used to endorse or promote products - * derived from this software without prior written permission. For + * 4. The names "Apache" and "Apache Software Foundation" and + * "Apache Turbine" must not be used to endorse or promote products + * derived from this software without prior written permission. For * written permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache", - * "Apache Turbine", nor may "Apache" appear in their name, without + * "Apache Turbine", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED @@ -54,39 +54,26 @@ * <http://www.apache.org/>. */ -import org.apache.commons.util.StringUtils; - +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.Properties; +import java.util.Iterator; import org.apache.velocity.context.Context; -import org.apache.velocity.texen.ant.TexenTask; - -import org.apache.torque.Torque; -import org.apache.torque.engine.database.model.AppData; -import org.apache.torque.engine.database.transform.XmlToAppData; +import org.apache.velocity.VelocityContext; /** * An extended Texen task used for generating SQL source from * an XML schema describing a database structure. * - * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a> * @author <a href="mailto:[EMAIL PROTECTED]>John McNally</a> - * @author <a href="mailto:[EMAIL PROTECTED]>Daniel Rall</a> - * @version $Id: TorqueSQLTask.java,v 1.6 2001/09/25 20:57:48 jvanzyl Exp $ + * @version $Id: TorqueSQLTask.java,v 1.7 2001/10/27 19:04:38 jvanzyl Exp $ */ -public class TorqueSQLTask - extends TexenTask +public class TorqueSQLTask + extends TorqueDataModelTask { /** - * Application model. In this case a database model. - */ - private AppData app; - - /** - * XML that describes the database model, this is transformed - * into the application model object. - */ - private String xmlFile; - - /** * The target database(s) we are generating SQL * for. Right now we can only deal with a single * target, but we will support multiple targets @@ -94,34 +81,41 @@ */ private String targetDatabase; - /** - * Get the xml schema describing the application - * model. - * - * @return String xml schema file. - */ - public String getXmlFile () + // if the database is set than all generated sql files + // will be placed in the specified database, the database + // will not be taken from the data model schema file. + + private String database; + private String suffix = ""; + + public void setDatabase(String database) { - return xmlFile; + this.database = database; } + + public String getDatabase() + { + return database; + } - /** - * Set the xml schema describing the application - * model. - * - * @param String xml schema file. - */ - public void setXmlFile(String v) + public void setSuffix(String suffix) { - xmlFile = v; + this.suffix = suffix; } + + public String getSuffix() + { + return suffix; + } + + /** * Get the current target package. * * @return String target database(s) */ - public String getTargetDatabase() + public String getTargetDatabase () { return targetDatabase; } @@ -132,34 +126,67 @@ * * @param String target database(s) */ - public void setTargetDatabase(String v) + public void setTargetDatabase (String v) { targetDatabase = v; } - /** - * Populates the initialial context with the model used to - * generate SQL from a XML schema. - * - * @param context The initial context, ripe for population. - * @exception Exception None expected. - */ - protected void populateInitialContext(Context context) + private void createSqlDbMap() throws Exception { - // Adds $now. - super.populateInitialContext(context); - - // Transform the XML database schema into an object that - // represents our model. - XmlToAppData xmlParser = new XmlToAppData - (getTargetDatabase(), getTemplatePath() + "/sql/base/"); - app = xmlParser.parseFile(xmlFile); - - // Place our model in the context. - context.put("appData", app); + if (getSqlDbMap() == null) + { + return; + } + + // Produce the sql -> database map + Properties sqldbmap = new Properties(); + + // Check to see if the sqldbmap has already been created. + File file = new File(getSqlDbMap()); + + if (file.exists()) + { + FileInputStream fis = new FileInputStream(file); + sqldbmap.load(fis); + fis.close(); + } + + Iterator i = getDataModelDbMap().keySet().iterator(); + + while (i.hasNext()) + { + String dataModelName = (String) i.next(); + String sqlFile = dataModelName + suffix + ".sql"; + + String databaseName; + + if (getDatabase() == null) + { + databaseName = (String) getDataModelDbMap().get(dataModelName); + } + else + { + databaseName = getDatabase(); + } + + sqldbmap.setProperty(sqlFile,databaseName); + } + + sqldbmap.store(new FileOutputStream(getSqlDbMap()),"Sqlfile -> Database map"); + } - // Place the target database in the context. + /** + * Place our target database and target platform + * values into the context for use in the + * templates. + */ + public Context initControlContext() + throws Exception + { + super.initControlContext(); context.put("targetDatabase", targetDatabase); + createSqlDbMap(); + return context; } } 1.3 +21 -6 jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueSQLTransformTask.java Index: TorqueSQLTransformTask.java =================================================================== RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/task/TorqueSQLTransformTask.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TorqueSQLTransformTask.java 2001/08/10 12:23:03 1.2 +++ TorqueSQLTransformTask.java 2001/10/27 19:04:38 1.3 @@ -66,14 +66,21 @@ /** * An ant task for creating an xml schema from an sql schema * - * @author <a href="mailto:[EMAIL PROTECTED]>Leon Messerschmidt</a> - * @version $Id: TorqueSQLTransformTask.java,v 1.2 2001/08/10 12:23:03 knielsen Exp $ + * @author <a href="mailto:[EMAIL PROTECTED]">Leon Messerschmidt</a> + * @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a> + * @version $Id: TorqueSQLTransformTask.java,v 1.3 2001/10/27 19:04:38 jvanzyl Exp $ */ public class TorqueSQLTransformTask extends Task { - + /** + * SQL input file. + */ private String inputFile; + + /** + * XML descriptor output file. + */ private String outputFile; /** @@ -92,7 +99,6 @@ inputFile = v; } - /** * Get the current output file. */ @@ -111,7 +117,13 @@ outputFile = v; } - public void execute () throws BuildException + /** + * Execute the task. + * + * @throws BuildException + */ + public void execute() + throws BuildException { try { @@ -133,7 +145,10 @@ } catch (Throwable e) { - e.printStackTrace (); + // 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]