Bug 446174:DBWS DDLParser does not properly resolve TYPEs on 12c

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
diff --git a/oracleddlparser/pom.xml b/oracleddlparser/pom.xml
index 304c7dd..b2e8691 100644
--- a/oracleddlparser/pom.xml
+++ b/oracleddlparser/pom.xml
@@ -27,8 +27,6 @@
       <db.ddl.create>false</db.ddl.create>
       <db.ddl.drop>false</db.ddl.drop>
       <db.ddl.debug>false</db.ddl.debug>
-      <!-- enable debugger on port 5005 -->
-      <test.debug>false</test.debug>
     </properties>
 
     <dependencies>
@@ -102,7 +100,8 @@
                   <includes>
                       <include>**/AllTests.java</include>
                   </includes>
-                  <debugForkedProcess>${test.debug}</debugForkedProcess>
+                  <!-- enable debugger on port 5005 -->
+                  <!--<debugForkedProcess>true</debugForkedProcess>-->
               </configuration>
               <goals>
                 <goal>test</goal>
diff --git a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/util/DatabaseTypeBuilder.java b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/util/DatabaseTypeBuilder.java
index 8938904..283c24b 100644
--- a/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/util/DatabaseTypeBuilder.java
+++ b/oracleddlparser/src/main/java/org/eclipse/persistence/tools/oracleddl/util/DatabaseTypeBuilder.java
@@ -1,5 +1,5 @@
 /*******************************************************************************

- * Copyright (c) 2011 Oracle. All rights reserved.

+ * Copyright (c) 2011, 2014 Oracle. All rights reserved.

  * This program and the accompanying materials are made available under the

  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0

  * which accompanies this distribution.

@@ -509,14 +509,29 @@
     /**

      * Attempt to resolve any types that the DDLParser could not resolve.

      *  

+     * @param conn Database connection

+     * @param schemaPattern Database schemas where to resolve types

+     * @param parser Parser to get types repository from

+     * @param unresolvedTypes List of types to be resolved

+     * @param databaseType Type possibly containing or referring type to be resolved

+     *

+     * @throws org.eclipse.persistence.tools.oracleddl.parser.ParseException if parsing error appears

      */

     protected void resolvedTypes(Connection conn, String schemaPattern, DDLParser parser, List<UnresolvedType> unresolvedTypes, DatabaseType databaseType) throws ParseException {

         resolvedTypes(conn, schemaPattern, parser, unresolvedTypes, databaseType, null);

     }

-    

+

     /**

      * Attempt to resolve any types that the DDLParser could not resolve.

-     *  

+     *

+     * @param conn Database connection

+     * @param schemaPattern Database schemas where to resolve types

+     * @param parser Parser to get types repository from

+     * @param unresolvedTypes List of types to be resolved

+     * @param databaseType Type possibly containing or referring type to be resolved

+     * @param processedPackages List of already processed packages, may be null

+     *

+     * @throws org.eclipse.persistence.tools.oracleddl.parser.ParseException if parsing error appears

      */

     protected void resolvedTypes(Connection conn, String schemaPattern, DDLParser parser,

         List<UnresolvedType> unresolvedTypes, DatabaseType databaseType, List<PLSQLPackageType> processedPackages) throws ParseException {

@@ -787,6 +802,11 @@
      * <li>TABLE = 4</li>

      * <li>TYPE = 5</li>

      * </ul>

+     *

+     * @param conn Database connection

+     * @param schema Database schema containing type definition

+     * @param typeName Name of the type to resolve database type for

+     * @return Integer value of resolved type

      */

     protected int getObjectType(Connection conn, String schema,  String typeName) {

         int objectType = -1;

@@ -800,8 +820,7 @@
             boolean worked = pStmt.execute();

             if (worked) {

                 rs = pStmt.getResultSet();

-                boolean b = rs.next();

-                if (b) {

+                while (objectType < 0 && rs.next()) {

                     objectType = rs.getInt(ALL_OBJECTS_OBJECT_TYPE_FIELD);

                 }

             }

diff --git a/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/TypeResolutionTestSuite.java b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/TypeResolutionTestSuite.java
index ff4c752..7f3d456 100644
--- a/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/TypeResolutionTestSuite.java
+++ b/oracleddlparser/src/test/java/org/eclipse/persistence/tools/oracleddl/test/databasetypebuilder/TypeResolutionTestSuite.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2011 Oracle. All rights reserved.
+ * Copyright (c) 2011, 2014 Oracle. All rights reserved.
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
  * which accompanies this distribution.
@@ -82,6 +82,25 @@
         ")";
     static final String CREATE_DDLRESOLVTEST_TYPE3 =
         "CREATE OR REPLACE TYPE DDLRESOLVTEST_TYPE3 AS VARRAY(2) OF DDLRESOLVTEST_TYPE2";
+    static final String CREATE_DDLRESOLVTEST_TYPE4 =
+        "CREATE OR REPLACE TYPE DDLRESOLVTEST_TYPE4 AS OBJECT (" +
+            "\n\tACCT\tNUMBER," +
+            "\n\tSTATE\tVARCHAR2(30)," +
+            "\nCONSTRUCTOR FUNCTION DDLRESOLVTEST_TYPE4(" +
+            "\n\tACCT\tNUMBER," +
+            "\n\tSTATE\tVARCHAR2) RETURN SELF AS RESULT" +
+        ")";
+    static final String CREATE_DDLRESOLVTEST_TYPE4_BODY =
+        "CREATE OR REPLACE TYPE BODY DDLRESOLVTEST_TYPE4 AS " +
+            "\nCONSTRUCTOR FUNCTION DDLRESOLVTEST_TYPE4(" +
+            "\n\tACCT\tNUMBER," +
+            "\n\tSTATE\tVARCHAR2) RETURN SELF AS RESULT IS" +
+            "\n\tBEGIN" +
+            "\n\t\tSELF.ACCT := ACCT;" +
+            "\n\t\tSELF.STATE   := STATE;" +
+            "\n\t\tRETURN;" +
+            "\n\tEND;" +
+            "\nEND;";
     static final String DDLRESOLVTEST_TABLE1 = "DDLRESOLVTEST_TABLE1";
     static final String CREATE_DDLRESOLVTEST_TABLE1 =
         "CREATE TABLE " + DDLRESOLVTEST_TABLE1 + " (" +
@@ -186,6 +205,7 @@
     static final String CREATE_OTHER_PACKAGE =
         "CREATE OR REPLACE PACKAGE " + OTHER_PACKAGE + " AS" +
             "\n\tPROCEDURE SOMEPROC(E1 IN " + DDLRESOLVTEST_PACKAGE + "." + "EMPREC);" +
+            "\n\tFUNCTION GET_JOB(p_job_id IN VARCHAR2) RETURN DDLRESOLVTEST_TYPE4;" +
         "\nEND " + OTHER_PACKAGE + ";";
     static final String CREATE_OTHER_PACKAGE_BODY =
         "CREATE OR REPLACE PACKAGE BODY " + OTHER_PACKAGE + " AS" +
@@ -193,6 +213,13 @@
             "\n\tBEGIN" +
                 "\n\tnull;" +
             "\n\tEND SOMEPROC;" +
+            "\n\tFUNCTION GET_JOB(p_job_id IN VARCHAR2) RETURN DDLRESOLVTEST_TYPE4 IS" +
+            "\n\tresult DDLRESOLVTEST_TYPE4;" +
+            "\n\tACCT\tNUMBER;" +
+            "\n\tSTATE\tVARCHAR2(30);" +
+            "\n\tBEGIN" +
+            "\n\t\tRETURN NULL;" +
+            "\n\tEND GET_JOB;" +
         "\nEND " + OTHER_PACKAGE + ";";
 
     static final String DROP_OTHER_PACKAGE =
@@ -206,6 +233,7 @@
     static final String DROP_DDLRESOLVTEST_TABLE2 = "DROP TABLE DDLRESOLVTEST_TABLE2";
     static final String DROP_DDLRESOLVTEST_TABLE1 = "DROP TABLE DDLRESOLVTEST_TABLE1";
     static final String DROP_DDLRESOLVTEST_EMP_TABLE = "DROP TABLE DDLRESOLVTEST_EMP";
+    static final String DROP_DDLRESOLVTEST_TYPE4 = "DROP TYPE DDLRESOLVTEST_TYPE4";
     static final String DROP_DDLRESOLVTEST_TYPE3 = "DROP TYPE DDLRESOLVTEST_TYPE3";
     static final String DROP_DDLRESOLVTEST_TYPE2 = "DROP TYPE DDLRESOLVTEST_TYPE2";
     static final String DROP_DDLRESOLVTEST_TYPE1 = "DROP TYPE DDLRESOLVTEST_TYPE1";
@@ -244,6 +272,8 @@
             runDdl(conn, CREATE_DDLRESOLVTEST_TYPE1, ddlDebug);
             runDdl(conn, CREATE_DDLRESOLVTEST_TYPE2, ddlDebug);
             runDdl(conn, CREATE_DDLRESOLVTEST_TYPE3, ddlDebug);
+            runDdl(conn, CREATE_DDLRESOLVTEST_TYPE4, ddlDebug);
+            runDdl(conn, CREATE_DDLRESOLVTEST_TYPE4_BODY, ddlDebug);
             runDdl(conn, CREATE_DDLRESOLVTEST_TABLE1, ddlDebug);
             runDdl(conn, CREATE_DDLRESOLVTEST_TABLE2, ddlDebug);
             runDdl(conn, CREATE_DDLRESOLVTEST_TABLE3, ddlDebug);
@@ -282,6 +312,7 @@
             runDdl(conn, DROP_DDLRESOLVTEST_TABLE2, ddlDebug);
             runDdl(conn, DROP_DDLRESOLVTEST_TABLE1, ddlDebug);
             runDdl(conn, DROP_DDLRESOLVTEST_EMP_TABLE, ddlDebug);
+            runDdl(conn, DROP_DDLRESOLVTEST_TYPE4, ddlDebug);
             runDdl(conn, DROP_DDLRESOLVTEST_TYPE3, ddlDebug);
             runDdl(conn, DROP_DDLRESOLVTEST_TYPE2, ddlDebug);
             runDdl(conn, DROP_DDLRESOLVTEST_TYPE1, ddlDebug);