You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by jm...@apache.org on 2001/12/26 23:24:43 UTC

cvs commit: jakarta-turbine-torque/src/templates/sql/base Control.vm

jmcnally    01/12/26 14:24:43

  Modified:    src/conf build.xml
               src/java/org/apache/torque/adapter IDMethod.java
               src/java/org/apache/torque/engine/database/model
                        Database.java Table.java
               src/java/org/apache/torque/engine/database/transform
                        SQLToAppData.java
               src/java/org/apache/torque/task TorqueSQLTask.java
               src/templates/sql/base Control.vm
  Log:
  patch by Byron Foster
  
  > >>> Here is a patch that creates the necessary sql to create the idbroker
  > >>> tables in standalone torque.  if the  idXMLTablXMLFile property is
  > >>> defined in build.xml and the database contains at least one table that
  > >>> utilizes the idbroker method then the sql generated will contain the
  > >>> create for the ID_TABLE and the initialization.
  > >>
  > >> There are already tasks to do this.
  > >>
  > >
  > > This patch makes it simpler to use.  It is smart in that if you are
  > > using method idbroker the id table is generated into the
  > > project-schema.xml file. Otherwise, if the method is native, no such
  > > table is generated. One does not need to generate two sql files based on
  > > if they are using idbroker or not. I think it earns a point in the "it
  > > just works" category.  If the idXMLTableXMLFile property is not
  > > specified, functionality remains as is.
  
  Revision  Changes    Path
  1.23      +2 -0      jakarta-turbine-torque/src/conf/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/conf/build.xml,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- build.xml	2001/12/23 15:49:51	1.22
  +++ build.xml	2001/12/26 22:24:42	1.23
  @@ -69,6 +69,7 @@
         templatePath="${templatePath}"
         sqldbmap="${torque.home}/${outputDirectory}/sql/sqldb.map"
         outputFile="report.${project}.sql.generation"
  +      idTableXMLFile="${torque.home}/schema/id-table-schema.xml"
         targetDatabase="${database}">
         <fileset dir="${torque.home}/${schemaDirectory}">
           <include name="*-schema.xml"/>
  @@ -430,6 +431,7 @@
         outputFile="report.${project}.sql.generation"
         xmlFile="${torque.home}/${schemaDirectory}/${project}-schema.xml"
         targetDatabase="${database}"
  +      idTableXMLFile="${torque.home}/schema/id-table-schema.xml"
       />
   
     </target>
  
  
  
  1.3       +2 -2      jakarta-turbine-torque/src/java/org/apache/torque/adapter/IDMethod.java
  
  Index: IDMethod.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/adapter/IDMethod.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IDMethod.java	2001/10/15 16:53:10	1.2
  +++ IDMethod.java	2001/12/26 22:24:43	1.3
  @@ -59,7 +59,7 @@
    * (i.e. auto-increment, sequence, ID broker, etc.).
    *
    * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
  - * @version $Id: IDMethod.java,v 1.2 2001/10/15 16:53:10 jmcnally Exp $
  + * @version $Id: IDMethod.java,v 1.3 2001/12/26 22:24:43 jmcnally Exp $
    */
   public interface IDMethod
   {
  @@ -82,7 +82,7 @@
       /**
        * Key generation via the IDBroker table.
        */
  -    String ID_BROKER = "idbroker_table";
  +    String ID_BROKER = "idbroker";
   
       /**
        * No RDBMS key generation (keys may be generated by the
  
  
  
  1.9       +25 -1     jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Database.java
  
  Index: Database.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Database.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Database.java	2001/12/13 16:58:07	1.8
  +++ Database.java	2001/12/26 22:24:43	1.9
  @@ -67,7 +67,9 @@
   
   import org.apache.torque.engine.database.model.NameGenerator;
   
  +import org.apache.torque.adapter.IDMethod;
   
  +
   /**
    * A class for holding application data structures.
    *
  @@ -76,7 +78,7 @@
    * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
    * @author <a href="mailto:dlr@collab.net>Daniel Rall</a>
    * @author <a href="mailto:byron_foster@byron_foster@yahoo.com>Byron Foster</a>
  - * @version $Id: Database.java,v 1.8 2001/12/13 16:58:07 jmcnally Exp $
  + * @version $Id: Database.java,v 1.9 2001/12/26 22:24:43 jmcnally Exp $
    */
   public class Database
   {
  @@ -349,6 +351,28 @@
           return (p == null ? null : p.getProperty(name));
       }
   
  +    /**
  +     * Determines if this database will be using the
  +     * <code>IDMethod.ID_BROKER</code> to create ids for torque OM
  +     * objects.
  +     * @return true if there is at least one table in this database that
  +     * uses the <code>IDMethod.ID_BROKER</code> method of generating
  +     * ids. returns false otherwise.
  +     */
  +    public boolean requiresIdTable()
  +    {
  +        Table table[] = getTables();
  +        for (int i=0; i<table.length; i++)
  +        {
  +            if (table[i].getIdMethod().equals(IDMethod.ID_BROKER))
  +            {
  +                return true;
  +            }
  +        }
  +        return false;
  +    }
  +
  +  
       /**
        * Creats a string representation of this Database.
        * The representation is given in xml format.
  
  
  
  1.21      +2 -2      jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Table.java
  
  Index: Table.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/model/Table.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Table.java	2001/12/18 23:25:06	1.20
  +++ Table.java	2001/12/26 22:24:43	1.21
  @@ -75,7 +75,7 @@
    * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
    * @author <a href="mailto:dlr@collab.net>Daniel Rall</a>
    * @author <a href="mailto:byron_foster@byron_foster@yahoo.com>Byron Foster</a>
  - * @version $Id: Table.java,v 1.20 2001/12/18 23:25:06 mpoeschl Exp $
  + * @version $Id: Table.java,v 1.21 2001/12/26 22:24:43 jmcnally Exp $
    */
   public class Table implements IDMethod
   {
  @@ -645,7 +645,7 @@
       {
           if (idMethod == null)
           {
  -            return "none";
  +            return IDMethod.NO_ID_METHOD;
           }
           else
           {
  
  
  
  1.2       +4 -3      jakarta-turbine-torque/src/java/org/apache/torque/engine/database/transform/SQLToAppData.java
  
  Index: SQLToAppData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/transform/SQLToAppData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SQLToAppData.java	2001/08/02 05:08:33	1.1
  +++ SQLToAppData.java	2001/12/26 22:24:43	1.2
  @@ -69,6 +69,7 @@
   import org.apache.torque.engine.sql.ParseException;
   import org.apache.torque.engine.sql.SQLScanner;
   import org.apache.torque.engine.sql.Token;
  +import org.apache.torque.adapter.IDMethod;
   
   /**
    * A Class that converts an sql input file to an AppData
  @@ -79,7 +80,7 @@
    * 
    * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
    * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
  - * @version $Id: SQLToAppData.java,v 1.1 2001/08/02 05:08:33 jvanzyl Exp $
  + * @version $Id: SQLToAppData.java,v 1.2 2001/12/26 22:24:43 jmcnally Exp $
    */
   public class SQLToAppData
   {
  @@ -190,11 +191,11 @@
           
           if (tbl.getPrimaryKey().size() == 1)
           {
  -            tbl.setIdMethod("idbroker");
  +            tbl.setIdMethod(IDMethod.ID_BROKER);
           }
           else
           {
  -            tbl.setIdMethod("none");
  +            tbl.setIdMethod(IDMethod.NO_ID_METHOD);
           }
           	
           
  
  
  
  1.9       +50 -1     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TorqueSQLTask.java	2001/11/01 00:39:49	1.8
  +++ TorqueSQLTask.java	2001/12/26 22:24:43	1.9
  @@ -61,14 +61,17 @@
   import java.util.Iterator;
   import org.apache.velocity.context.Context;
   import org.apache.velocity.VelocityContext;
  +import org.apache.torque.engine.database.transform.XmlToAppData;
  +import org.apache.torque.engine.database.model.AppData;
   
  +
   /**
    * An extended Texen task used for generating SQL source from
    * an XML schema describing a database structure.
    *
    * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
    * @author <a href="mailto:jmcnally@collab.net>John McNally</a>
  - * @version $Id: TorqueSQLTask.java,v 1.8 2001/11/01 00:39:49 jvanzyl Exp $
  + * @version $Id: TorqueSQLTask.java,v 1.9 2001/12/26 22:24:43 jmcnally Exp $
    */
   public class TorqueSQLTask 
       extends TorqueDataModelTask
  @@ -88,6 +91,8 @@
       private String database;
       private String suffix = "";
       
  +    private String idTableXMLFile = null;
  +    
       public void setDatabase(String database)
       {
           this.database = database;
  @@ -109,6 +114,25 @@
       }        
   
       /**
  +     * Set the path to the xml schema file that defines the id-table, used
  +     * by the idbroker method.
  +     * @param xml path to file.
  +     */
  +    public void setIdTableXMLFile(String idXmlFile)
  +    {
  +        idTableXMLFile = idXmlFile;
  +    }
  +
  +    /**
  +     * Gets the id-table xml schema file path.
  +     * @return Path to file.
  +     */
  +    public String getIdTableXMLFile()
  +    {
  +        return idTableXMLFile;
  +    }
  +    
  +    /**
        * Get the current target package.
        *
        * @return String target database(s)
  @@ -175,6 +199,23 @@
       }
   
       /**
  +     * Create the database model necessary for the IDBroker tables.
  +     * We use the model to generate the necessary SQL to create
  +     * these tables.  This method adds an AppData object containing
  +     * the model to the context under the name "idmodel".
  +     */
  +    public void loadIdBrokerModel()
  +    {
  +        // Transform the XML database schema into
  +        // data model object.
  +        XmlToAppData xmlParser = new XmlToAppData();
  +        AppData ad = xmlParser.parseFile(getIdTableXMLFile());
  +        xmlParser.parseFile(getIdTableXMLFile());
  +        ad.setName("idmodel");
  +        context.put("idmodel", ad);
  +    }
  +
  +    /**
        * Place our target database and target platform
        * values into the context for use in the
        * templates.
  @@ -185,6 +226,14 @@
           super.initControlContext();
           context.put("targetDatabase", targetDatabase);
           createSqlDbMap();
  +
  +        // If the load path for the id broker table xml schema is
  +        // defined then load it.
  +        if (getIdTableXMLFile() != null)
  +        {
  +            loadIdBrokerModel();
  +        }
  +        
           return context;
       }
   }
  
  
  
  1.4       +16 -1     jakarta-turbine-torque/src/templates/sql/base/Control.vm
  
  Index: Control.vm
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/templates/sql/base/Control.vm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Control.vm	2001/11/15 00:37:52	1.3
  +++ Control.vm	2001/12/26 22:24:43	1.4
  @@ -2,11 +2,12 @@
   #set ( $dbprops = $properties.load("$generator.TemplatePath/sql/base/$targetDatabase/db.props") )
   #set ( $fname= "sql/base/$targetDatabase/table.vm" )
   #set ( $fnamekeys= "sql/base/$targetDatabase/tablefk.vm" )
  +#set ( $idname = "sql/id-table/idtable.$targetDatabase" )
   
   #foreach ($dataModel in $dataModels)
           
     #set ( $outFile = "${dataModel.name}.sql" )
  -        
  +
     File to be created: $outFile
     
     #set ( $database = $dataModel.database )
  @@ -22,4 +23,18 @@
         $generator.parse($fnamekeys,$outFile,"tablefk",$tbl)
       #end
     #end    
  +
  +  #if ($idmodel)
  +
  +    Creating id-table
  +
  +    #set ($tbl = $idmodel.database.getTable("ID_TABLE"))
  +    $generator.parse($fname,$outFile,"table",$tbl)
  + 
  +    ## Generate inserts into ID-TABLE for initial ids.
  +    #set ( $initialID = 1 )  
  +    $generator.parse($idname, $outFile, "tables", $database.tables)
  +
  +  #end
  +
   #end
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>