db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpoes...@apache.org
Subject cvs commit: jakarta-turbine-torque/xdocs changes.xml
Date Fri, 20 Dec 2002 16:39:22 GMT
mpoeschl    2002/12/20 08:39:21

  Modified:    src/java/org/apache/torque/engine/database/transform
                        XmlToAppData.java
               src/rttest test-schema.xml
               xdocs    changes.xml
  Added:       src/rttest ext-schema.xml extext-schema.xml
  Log:
  TRQ19: recursive external schemas fail
  i also added a testcase to the rttests
  
  Revision  Changes    Path
  1.18      +99 -5     jakarta-turbine-torque/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java
  
  Index: XmlToAppData.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XmlToAppData.java	18 Dec 2002 13:56:04 -0000	1.17
  +++ XmlToAppData.java	20 Dec 2002 16:39:21 -0000	1.18
  @@ -58,6 +58,8 @@
   import java.io.FileReader;
   import java.io.FileNotFoundException;
   import java.io.File;
  +import java.util.Vector;
  +import java.util.Stack;
   
   import org.apache.torque.engine.database.model.AppData;
   import org.apache.torque.engine.database.model.Column;
  @@ -107,6 +109,12 @@
   
       private static SAXParserFactory saxFactory;
   
  +    /** remember all files we have already parsed to detect looping. */
  +    private Vector alreadyReadFiles;
  +
  +    /** this is the stack to store parsing data */
  +    private Stack parsingStack = new Stack();
  +
       static
       {
           saxFactory = SAXParserFactory.newInstance();
  @@ -146,6 +154,20 @@
               {
                   throw new Error("No more double pass");
               }
  +            // check to see if we alread have parsed the file
  +            if ((alreadyReadFiles != null)
  +                    && alreadyReadFiles.contains(xmlFile))
  +            {
  +                return app;
  +            }
  +            else if (alreadyReadFiles == null)
  +            {
  +                alreadyReadFiles = new Vector(3, 1);
  +            }
  +
  +            // remember the file to avoid looping
  +            alreadyReadFiles.add(xmlFile);
  +
               currentXmlFile = xmlFile;
   
               SAXParser parser = saxFactory.newSAXParser();
  @@ -163,6 +185,7 @@
               BufferedReader br = new BufferedReader(fr);
               try
               {
  +                System.err.println("Parsing file: '" + (new File(xmlFile)).getName() +
"'");
                   InputSource is = new InputSource(br);
                   parser.parse(is, this);
               }
  @@ -235,7 +258,6 @@
                   }
                   else if (rawName.equals("external-schema"))
                   {
  -                    isExternalSchema = true;
                       String xmlFile = attributes.getValue("filename");
                       if (xmlFile.charAt(0) != '/')
                       {
  @@ -243,8 +265,14 @@
                           xmlFile = new File(f.getParent(), xmlFile).getPath();
                       }
   
  +                    // put current state onto the stack
  +                    ParseStackElement.pushState(this);
  +
  +                    isExternalSchema = true;
  +
                       parseFile(xmlFile);
  -                    isExternalSchema = false;
  +                    // get the last state from the stack
  +                    ParseStackElement.popState(this);
                   }
                   else if (rawName.equals("table"))
                   {
  @@ -346,9 +374,75 @@
           printParseError("Fatal Error", spe);
       }
   
  +    /**
  +     * Write an error to System.err.
  +     *
  +     * @param type error type
  +     * @param spe The parse exception that caused the callback to be invoked.
  +     */
       private final void printParseError(String type, SAXParseException spe)
       {
  -        System.err.println(type + " [line " + spe.getLineNumber()
  -                + ", row " + spe.getColumnNumber() + "]: " + spe.getMessage());
  +        System.err.println(type + "[file '"
  +                + (new File(currentXmlFile)).getName() + "', line "
  +                + spe.getLineNumber() + ", row " + spe.getColumnNumber()
  +                + "]: " + spe.getMessage());
  +    }
  +
  +    /**
  +     * When parsing multiple files that use nested <external-schema> tags we
  +     * need to use a stack to remember some values.
  +     */
  +    private static class ParseStackElement
  +    {
  +        private boolean isExternalSchema;
  +        private String currentPackage;
  +        private String currentXmlFile;
  +        private boolean firstPass;
  +
  +        /**
  +         *
  +         * @param parser
  +         */
  +        public ParseStackElement(XmlToAppData parser)
  +        {
  +            // remember current state of parent object
  +            isExternalSchema = parser.isExternalSchema;
  +            currentPackage = parser.currentPackage;
  +            currentXmlFile = parser.currentXmlFile;
  +            firstPass = parser.firstPass;
  +
  +            // push the state onto the stack
  +            parser.parsingStack.push(this);
  +        }
  +
  +        /**
  +         * Removes the top element from the stack and activates the stored state
  +         *
  +         * @param parser
  +         */
  +        public static void popState(XmlToAppData parser)
  +        {
  +            if (!parser.parsingStack.isEmpty())
  +            {
  +                ParseStackElement elem = (ParseStackElement)
  +                        parser.parsingStack.pop();
  +
  +                // activate stored state
  +                parser.isExternalSchema = elem.isExternalSchema;
  +                parser.currentPackage = elem.currentPackage;
  +                parser.currentXmlFile = elem.currentXmlFile;
  +                parser.firstPass = elem.firstPass;
  +            }
  +        }
  +
  +        /**
  +         * Stores the current state on the top of the stack.
  +         *
  +         * @param parser
  +         */
  +        public static void pushState(XmlToAppData parser)
  +        {
  +            new ParseStackElement(parser);
  +        }
       }
   }
  
  
  
  1.8       +23 -0     jakarta-turbine-torque/src/rttest/test-schema.xml
  
  Index: test-schema.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/src/rttest/test-schema.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- test-schema.xml	18 Dec 2002 13:56:04 -0000	1.7
  +++ test-schema.xml	20 Dec 2002 16:39:21 -0000	1.8
  @@ -3,6 +3,9 @@
   <!-- this schema is used to test problems users reported -->
   
   <database name="@DATABASE_DEFAULT@" defaultIdMethod="idbroker" package="org.apache.torque.test">
  +
  +  <external-schema filename="ext-schema.xml" />
  +
     <!-- TRQS15 -->
     <table name="varchar_pk">
       <column name="test_key" required="true" primaryKey="true" type="VARCHAR" size="30"
/>
  @@ -54,6 +57,26 @@
       </foreign-key>
     </table>
   
  +  <!-- reference to external schema -->
  +  <table name="ext_schema">
  +    <column name="ext_schema_id" required="true" primaryKey="true" type="INTEGER"/>
  +    <column name="ext_id" type="INTEGER"/>
  +    <column name="test" required="true" type="INTEGER"/>
  +
  +    <foreign-key foreignTable="ext">
  +      <reference local="ext_id" foreign="ext_id"/>
  +    </foreign-key>
  +  </table>
  +
  +  <table name="extext_schema">
  +    <column name="extext_schema_id" required="true" primaryKey="true" type="INTEGER"/>
  +    <column name="extext_id" type="INTEGER"/>
  +    <column name="test" required="true" type="INTEGER"/>
  +
  +    <foreign-key foreignTable="extext">
  +      <reference local="extext_id" foreign="extext_id"/>
  +    </foreign-key>
  +  </table>
   
   </database>
   
  
  
  
  1.1                  jakarta-turbine-torque/src/rttest/ext-schema.xml
  
  Index: ext-schema.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
  <!DOCTYPE database SYSTEM "http://jakarta.apache.org/turbine/dtd/database.dtd">
  
  <database
    name="@DATABASE_DEFAULT@"
    defaultIdMethod="@DATABASE_ID_METHOD@">
  
    <external-schema filename="extext-schema.xml" />
  
    <table name="ext">
      <column
        name="ext_id"
        required="true"
        primaryKey="true"
        type="INTEGER"
      />
      <column
        name="test"
        required="true"
        type="VARCHAR"
        size="15"
      />
    </table>
  </database>
  
  
  
  1.1                  jakarta-turbine-torque/src/rttest/extext-schema.xml
  
  Index: extext-schema.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
  <!DOCTYPE database SYSTEM "http://jakarta.apache.org/turbine/dtd/database.dtd">
  
  <database
    name="@DATABASE_DEFAULT@"
    defaultIdMethod="@DATABASE_ID_METHOD@">
  
    <table name="extext">
      <column
        name="extext_id"
        required="true"
        primaryKey="true"
        type="INTEGER"
      />
      <column
        name="test"
        required="true"
        type="VARCHAR"
        size="15"
      />
    </table>
  </database>
  
  
  
  1.60      +3 -0      jakarta-turbine-torque/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-torque/xdocs/changes.xml,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- changes.xml	18 Dec 2002 14:24:37 -0000	1.59
  +++ changes.xml	20 Dec 2002 16:39:21 -0000	1.60
  @@ -44,6 +44,9 @@
   <p>
     <ul>
       <li>
  +      TRQ19: recursive external schemas fail
  +    </li>
  +    <li>
         TRQ47: limit and offset patch for Oracle
       </li>
       <li>
  
  
  

Mime
View raw message