Program: 64166
Project: 64166
Buggy source:
/** 
 * Generate an XMLEntityMappings instance based on a given OR Project's Queries and Descriptors.
 * @param orProject the ORM Project instance containing Queries and Descriptors to be used to generate an XMLEntityMappings
 * @param complexTypes list of composite database types used to generate metadata for advanced Oracle and PL/SQL types
 */
@SuppressWarnings({"String_Node_Str","String_Node_Str"}) public static XMLEntityMappings generateXmlEntityMappings(Project orProject,List<CompositeDatabaseType> complexTypes){
  List<ClassDescriptor> descriptors=orProject.getOrderedDescriptors();
  List<DatabaseQuery> queries=orProject.getQueries();
  XMLEntityMappings xmlEntityMappings=new XMLEntityMappings();
  xmlEntityMappings.setEmbeddables(new ArrayList<EmbeddableAccessor>());
  xmlEntityMappings.setEntities(new ArrayList<EntityAccessor>());
  xmlEntityMappings.setPLSQLRecords(new ArrayList<PLSQLRecordMetadata>());
  xmlEntityMappings.setPLSQLTables(new ArrayList<PLSQLTableMetadata>());
  xmlEntityMappings.setOracleObjectTypes(new ArrayList<OracleObjectTypeMetadata>());
  xmlEntityMappings.setOracleArrayTypes(new ArrayList<OracleArrayTypeMetadata>());
  List<PLSQLRecordMetadata> plsqlRecords=new ArrayList<PLSQLRecordMetadata>();
  List<PLSQLTableMetadata> plsqlTables=new ArrayList<PLSQLTableMetadata>();
  List<OracleObjectTypeMetadata> objectTypes=new ArrayList<OracleObjectTypeMetadata>();
  List<OracleArrayTypeMetadata> arrayTypes=new ArrayList<OracleArrayTypeMetadata>();
  List<ComplexTypeMetadata> complexTypeMetadata=processCompositeTypes(complexTypes,orProject);
  for (  ComplexTypeMetadata cTypeMetadata : complexTypeMetadata) {
    if (cTypeMetadata.isOracleComplexTypeMetadata()) {
      OracleComplexTypeMetadata octMetadata=(OracleComplexTypeMetadata)cTypeMetadata;
      if (octMetadata.isOracleArrayTypeMetadata()) {
        arrayTypes.add((OracleArrayTypeMetadata)octMetadata);
      }
 else {
        objectTypes.add((OracleObjectTypeMetadata)octMetadata);
      }
    }
 else {
      PLSQLComplexTypeMetadata plsqlctMetadata=(PLSQLComplexTypeMetadata)cTypeMetadata;
      if (plsqlctMetadata.isPLSQLRecordMetadata()) {
        plsqlRecords.add((PLSQLRecordMetadata)plsqlctMetadata);
      }
 else {
        plsqlTables.add((PLSQLTableMetadata)plsqlctMetadata);
      }
    }
  }
  if (plsqlRecords.size() > 0) {
    xmlEntityMappings.setPLSQLRecords(plsqlRecords);
  }
  if (plsqlTables.size() > 0) {
    xmlEntityMappings.setPLSQLTables(plsqlTables);
  }
  if (objectTypes != null) {
    xmlEntityMappings.setOracleObjectTypes(objectTypes);
  }
  if (arrayTypes != null) {
    xmlEntityMappings.setOracleArrayTypes(arrayTypes);
  }
  List<NamedPLSQLStoredProcedureQueryMetadata> plsqlStoredProcs=null;
  List<NamedPLSQLStoredFunctionQueryMetadata> plsqlStoredFuncs=null;
  List<NamedStoredProcedureQueryMetadata> storedProcs=null;
  List<NamedStoredFunctionQueryMetadata> storedFuncs=null;
  List<NamedNativeQueryMetadata> namedNativeQueries=null;
  DatabaseQuery query;
  for (Iterator<DatabaseQuery> queryIt=queries.iterator(); queryIt.hasNext(); ) {
    query=queryIt.next();
    if (query.getCall().isStoredFunctionCall()) {
      if (query.getCall() instanceof PLSQLStoredFunctionCall) {
        PLSQLStoredFunctionCall call=(PLSQLStoredFunctionCall)query.getCall();
        NamedPLSQLStoredFunctionQueryMetadata metadata=new NamedPLSQLStoredFunctionQueryMetadata();
        metadata.setName(query.getName());
        metadata.setProcedureName(call.getProcedureName());
        List<PLSQLParameterMetadata> params=new ArrayList<PLSQLParameterMetadata>();
        if (plsqlStoredFuncs == null) {
          plsqlStoredFuncs=new ArrayList<NamedPLSQLStoredFunctionQueryMetadata>();
        }
        PLSQLargument arg;
        PLSQLParameterMetadata param;
        List<PLSQLargument> types=call.getArguments();
        for (int i=0; i < types.size(); i++) {
          arg=types.get(i);
          param=new PLSQLParameterMetadata();
          param.setName(arg.name);
          String dbType=arg.databaseType.getTypeName();
          if (arg.databaseType == XMLType) {
            dbType=XMLType.name();
          }
 else {
            if (!(getJDBCTypeFromTypeName(dbType) == Types.OTHER)) {
              if (!dbType.equals(BOOLEAN_STR)) {
                dbType=dbType.concat(_TYPE_STR);
              }
            }
          }
          param.setDatabaseType(dbType);
          if (i == 0) {
            metadata.setReturnParameter(param);
            if (arg.cursorOutput) {
              param.setDirection(CURSOR_STR);
            }
          }
 else {
            param.setDirection(getDirectionAsString(arg.direction));
            params.add(param);
          }
        }
        if (params.size() > 0) {
          metadata.setParameters(params);
        }
        plsqlStoredFuncs.add(metadata);
      }
 else {
        StoredFunctionCall call=(StoredFunctionCall)query.getCall();
        NamedStoredFunctionQueryMetadata metadata=new NamedStoredFunctionQueryMetadata();
        metadata.setName(query.getName());
        metadata.setProcedureName(call.getProcedureName());
        List<StoredProcedureParameterMetadata> params=new ArrayList<StoredProcedureParameterMetadata>();
        if (storedFuncs == null) {
          storedFuncs=new ArrayList<NamedStoredFunctionQueryMetadata>();
        }
        DatabaseField arg;
        StoredProcedureParameterMetadata param;
        List<DatabaseField> paramFields=call.getParameters();
        List types=call.getParameterTypes();
        for (int i=0; i < paramFields.size(); i++) {
          arg=paramFields.get(i);
          param=new StoredProcedureParameterMetadata();
          param.setTypeName(arg.getTypeName());
          param.setJdbcType(arg.getSqlType());
          if (arg.isObjectRelationalDatabaseField()) {
            param.setJdbcTypeName(((ObjectRelationalDatabaseField)arg).getSqlTypeName());
          }
          if (i == 0) {
            metadata.setReturnParameter(param);
          }
 else {
            param.setName(arg.getName());
            param.setDirection(getDirectionAsString((Integer)types.get(i)));
            params.add(param);
          }
        }
        if (params.size() > 0) {
          metadata.setParameters(params);
        }
        storedFuncs.add(metadata);
      }
    }
 else     if (query.getCall().isStoredProcedureCall()) {
      if (query.getCall() instanceof PLSQLStoredProcedureCall) {
        PLSQLStoredProcedureCall call=(PLSQLStoredProcedureCall)query.getCall();
        if (plsqlStoredProcs == null) {
          plsqlStoredProcs=new ArrayList<NamedPLSQLStoredProcedureQueryMetadata>();
        }
        NamedPLSQLStoredProcedureQueryMetadata metadata=new NamedPLSQLStoredProcedureQueryMetadata();
        metadata.setName(query.getName());
        metadata.setProcedureName(call.getProcedureName());
        PLSQLParameterMetadata param;
        List<PLSQLParameterMetadata> params=new ArrayList<PLSQLParameterMetadata>();
        List<PLSQLargument> types=call.getArguments();
        for (        PLSQLargument arg : types) {
          param=new PLSQLParameterMetadata();
          param.setName(arg.name);
          String dbType=processTypeName(arg.databaseType.getTypeName());
          if (arg.cursorOutput) {
            param.setDirection(CURSOR_STR);
          }
 else {
            param.setDirection(getDirectionAsString(arg.direction));
          }
          if (arg.databaseType == XMLType) {
            param.setDatabaseType(XMLType.name());
          }
 else {
            param.setDatabaseType(dbType);
          }
          params.add(param);
        }
        if (params.size() > 0) {
          metadata.setParameters(params);
        }
        plsqlStoredProcs.add(metadata);
      }
 else {
        StoredProcedureCall call=(StoredProcedureCall)query.getCall();
        NamedStoredProcedureQueryMetadata metadata=new NamedStoredProcedureQueryMetadata();
        metadata.setName(query.getName());
        metadata.setProcedureName(call.getProcedureName());
        List<StoredProcedureParameterMetadata> params=new ArrayList<StoredProcedureParameterMetadata>();
        DatabaseField arg;
        StoredProcedureParameterMetadata param;
        List<DatabaseField> paramFields=call.getParameters();
        List types=call.getParameterTypes();
        for (int i=0; i < paramFields.size(); i++) {
          arg=paramFields.get(i);
          param=new StoredProcedureParameterMetadata();
          param.setName(arg.getName());
          param.setTypeName(arg.getTypeName());
          param.setJdbcType(arg.getSqlType());
          if (arg.isObjectRelationalDatabaseField()) {
            param.setJdbcTypeName(((ObjectRelationalDatabaseField)arg).getSqlTypeName());
          }
          param.setDirection(getDirectionAsString((Integer)types.get(i)));
          params.add(param);
        }
        if (params.size() > 0) {
          metadata.setParameters(params);
        }
        if (storedProcs == null) {
          storedProcs=new ArrayList<NamedStoredProcedureQueryMetadata>();
        }
        storedProcs.add(metadata);
      }
    }
 else {
      NamedNativeQueryMetadata namedQuery=new NamedNativeQueryMetadata();
      namedQuery.setName(query.getName());
      namedQuery.setQuery(query.getSQLString());
      namedQuery.setResultClassName(query.getReferenceClassName());
      if (namedNativeQueries == null) {
        namedNativeQueries=new ArrayList<NamedNativeQueryMetadata>();
      }
      namedNativeQueries.add(namedQuery);
    }
  }
  if (plsqlStoredProcs != null) {
    xmlEntityMappings.setNamedPLSQLStoredProcedureQueries(plsqlStoredProcs);
  }
  if (plsqlStoredFuncs != null) {
    xmlEntityMappings.setNamedPLSQLStoredFunctionQueries(plsqlStoredFuncs);
  }
  if (storedProcs != null) {
    xmlEntityMappings.setNamedStoredProcedureQueries(storedProcs);
  }
  if (storedFuncs != null) {
    xmlEntityMappings.setNamedStoredFunctionQueries(storedFuncs);
  }
  if (namedNativeQueries != null) {
    xmlEntityMappings.setNamedNativeQueries(namedNativeQueries);
  }
  List<String> embeddables=new ArrayList<String>();
  Map<String,ClassAccessor> accessors=new HashMap<String,ClassAccessor>();
  for (  ClassDescriptor cdesc : descriptors) {
    boolean embeddable=false;
    ClassAccessor classAccessor;
    if (cdesc.isAggregateDescriptor()) {
      embeddable=true;
      classAccessor=new EmbeddableAccessor();
      ((EmbeddableAccessor)classAccessor).setName(cdesc.getAlias());
      embeddables.add(cdesc.getJavaClassName());
    }
 else {
      classAccessor=new EntityAccessor();
      ((EntityAccessor)classAccessor).setEntityName(cdesc.getAlias());
    }
    classAccessor.setClassName(cdesc.getJavaClassName());
    classAccessor.setAccess(EL_ACCESS_VIRTUAL);
    if (cdesc.isObjectRelationalDataTypeDescriptor()) {
      ObjectRelationalDataTypeDescriptor odesc=(ObjectRelationalDataTypeDescriptor)cdesc;
      if (odesc.getOrderedFields().size() > 0) {
        StructMetadata struct=new StructMetadata();
        struct.setName(odesc.getStructureName());
        struct.setFields(odesc.getOrderedFields());
        classAccessor.setStruct(struct);
      }
    }
    if (!embeddable && cdesc.getTableName() != null) {
      TableMetadata table=new TableMetadata();
      table.setName(cdesc.getTableName());
      ((EntityAccessor)classAccessor).setTable(table);
    }
    if (!embeddable) {
      List<NamedNativeQueryMetadata> namedNatQueries=new ArrayList<NamedNativeQueryMetadata>();
      NamedNativeQueryMetadata namedQuery;
      DatabaseQuery dbQuery;
      for (Iterator<DatabaseQuery> queryIt=cdesc.getQueryManager().getAllQueries().iterator(); queryIt.hasNext(); ) {
        dbQuery=queryIt.next();
        namedQuery=new NamedNativeQueryMetadata();
        namedQuery.setName(dbQuery.getName());
        namedQuery.setQuery(dbQuery.getSQLString());
        namedQuery.setResultClassName(dbQuery.getReferenceClassName());
        namedNatQueries.add(namedQuery);
      }
      if (namedNatQueries.size() > 0) {
        ((EntityAccessor)classAccessor).setNamedNativeQueries(namedNatQueries);
      }
    }
    classAccessor.setAttributes(new XMLAttributes());
    classAccessor.getAttributes().setIds(new ArrayList<IdAccessor>());
    classAccessor.getAttributes().setBasics(new ArrayList<BasicAccessor>());
    classAccessor.getAttributes().setArrays(new ArrayList<ArrayAccessor>());
    classAccessor.getAttributes().setStructures(new ArrayList<StructureAccessor>());
    classAccessor.getAttributes().setEmbeddeds(new ArrayList<EmbeddedAccessor>());
    if (embeddable) {
      xmlEntityMappings.getEmbeddables().add((EmbeddableAccessor)classAccessor);
    }
 else {
      xmlEntityMappings.getEntities().add((EntityAccessor)classAccessor);
    }
    accessors.put(cdesc.getJavaClassName(),classAccessor);
  }
  for (  ClassDescriptor cdesc : descriptors) {
    ClassAccessor classAccessor=accessors.get(cdesc.getJavaClassName());
    MappingAccessor mapAccessor;
    for (Iterator<DatabaseMapping> mapIt=cdesc.getMappings().iterator(); mapIt.hasNext(); ) {
      DatabaseMapping dbMapping=mapIt.next();
      mapAccessor=generateMappingAccessor(dbMapping,embeddables);
      if (mapAccessor == null) {
        continue;
      }
      if (mapAccessor.isId()) {
        classAccessor.getAttributes().getIds().add((IdAccessor)mapAccessor);
      }
 else       if (mapAccessor.isBasic()) {
        classAccessor.getAttributes().getBasics().add((BasicAccessor)mapAccessor);
      }
 else       if (mapAccessor instanceof ArrayAccessor) {
        classAccessor.getAttributes().getArrays().add((ArrayAccessor)mapAccessor);
      }
 else       if (mapAccessor instanceof StructureAccessor) {
        classAccessor.getAttributes().getStructures().add((StructureAccessor)mapAccessor);
      }
 else {
        classAccessor.getAttributes().getEmbeddeds().add((EmbeddedAccessor)mapAccessor);
      }
    }
  }
  EntityAccessor eAccessor=new EntityAccessor();
  eAccessor.setAttributes(new XMLAttributes());
  eAccessor.getAttributes().setEmbeddeds(new ArrayList<EmbeddedAccessor>());
  eAccessor.getAttributes().setIds(new ArrayList<IdAccessor>());
  eAccessor.setClassName(ENTITY_STR);
  eAccessor.setAccess(EL_ACCESS_VIRTUAL);
  xmlEntityMappings.getEntities().add(eAccessor);
  EmbeddedAccessor fakeAccessor;
  int i=0;
  for (  ClassDescriptor cdesc : descriptors) {
    if (cdesc.isAggregateDescriptor()) {
      fakeAccessor=new EmbeddedAccessor();
      fakeAccessor.setName(FAKE_STR + i++);
      fakeAccessor.setAttributeType(cdesc.getJavaClassName());
      eAccessor.getAttributes().getEmbeddeds().add(fakeAccessor);
    }
  }
  IdAccessor idAccessor=new IdAccessor();
  idAccessor.setName(FAKEPK_STR);
  idAccessor.setAttributeType(STRING_STR);
  ColumnMetadata column=new ColumnMetadata();
  column.setName(FAKE_PK_STR);
  idAccessor.setColumn(column);
  eAccessor.getAttributes().getIds().add(idAccessor);
  return xmlEntityMappings;
}

Fixed version (ground truth):
/** 
 * Generate an XMLEntityMappings instance based on a given OR Project's Queries and Descriptors.
 * @param orProject the ORM Project instance containing Queries and Descriptors to be used to generate an XMLEntityMappings
 * @param complexTypes list of composite database types used to generate metadata for advanced Oracle and PL/SQL types
 */
@SuppressWarnings({"String_Node_Str","String_Node_Str"}) public static XMLEntityMappings generateXmlEntityMappings(Project orProject,List<CompositeDatabaseType> complexTypes){
  List<ClassDescriptor> descriptors=orProject.getOrderedDescriptors();
  List<DatabaseQuery> queries=orProject.getQueries();
  XMLEntityMappings xmlEntityMappings=new XMLEntityMappings();
  xmlEntityMappings.setEmbeddables(new ArrayList<EmbeddableAccessor>());
  xmlEntityMappings.setEntities(new ArrayList<EntityAccessor>());
  xmlEntityMappings.setPLSQLRecords(new ArrayList<PLSQLRecordMetadata>());
  xmlEntityMappings.setPLSQLTables(new ArrayList<PLSQLTableMetadata>());
  xmlEntityMappings.setOracleObjectTypes(new ArrayList<OracleObjectTypeMetadata>());
  xmlEntityMappings.setOracleArrayTypes(new ArrayList<OracleArrayTypeMetadata>());
  List<PLSQLRecordMetadata> plsqlRecords=null;
  List<PLSQLTableMetadata> plsqlTables=null;
  List<OracleObjectTypeMetadata> objectTypes=null;
  List<OracleArrayTypeMetadata> arrayTypes=null;
  List<ComplexTypeMetadata> complexTypeMetadata=processCompositeTypes(complexTypes,orProject);
  for (  ComplexTypeMetadata cTypeMetadata : complexTypeMetadata) {
    if (cTypeMetadata.isOracleComplexTypeMetadata()) {
      OracleComplexTypeMetadata octMetadata=(OracleComplexTypeMetadata)cTypeMetadata;
      if (octMetadata.isOracleArrayTypeMetadata()) {
        if (arrayTypes == null) {
          arrayTypes=new ArrayList<OracleArrayTypeMetadata>();
        }
        arrayTypes.add((OracleArrayTypeMetadata)octMetadata);
      }
 else {
        if (objectTypes == null) {
          objectTypes=new ArrayList<OracleObjectTypeMetadata>();
        }
        objectTypes.add((OracleObjectTypeMetadata)octMetadata);
      }
    }
 else {
      PLSQLComplexTypeMetadata plsqlctMetadata=(PLSQLComplexTypeMetadata)cTypeMetadata;
      if (plsqlctMetadata.isPLSQLRecordMetadata()) {
        if (plsqlRecords == null) {
          plsqlRecords=new ArrayList<PLSQLRecordMetadata>();
        }
        plsqlRecords.add((PLSQLRecordMetadata)plsqlctMetadata);
      }
 else {
        if (plsqlTables == null) {
          plsqlTables=new ArrayList<PLSQLTableMetadata>();
        }
        plsqlTables.add((PLSQLTableMetadata)plsqlctMetadata);
      }
    }
  }
  xmlEntityMappings.setPLSQLRecords(plsqlRecords);
  xmlEntityMappings.setPLSQLTables(plsqlTables);
  xmlEntityMappings.setOracleObjectTypes(objectTypes);
  xmlEntityMappings.setOracleArrayTypes(arrayTypes);
  List<NamedPLSQLStoredProcedureQueryMetadata> plsqlStoredProcs=null;
  List<NamedPLSQLStoredFunctionQueryMetadata> plsqlStoredFuncs=null;
  List<NamedStoredProcedureQueryMetadata> storedProcs=null;
  List<NamedStoredFunctionQueryMetadata> storedFuncs=null;
  List<NamedNativeQueryMetadata> namedNativeQueries=null;
  for (  DatabaseQuery query : queries) {
    if (query.getCall().isStoredFunctionCall()) {
      if (query.getCall() instanceof PLSQLStoredFunctionCall) {
        PLSQLStoredFunctionCall call=(PLSQLStoredFunctionCall)query.getCall();
        NamedPLSQLStoredFunctionQueryMetadata metadata=new NamedPLSQLStoredFunctionQueryMetadata();
        metadata.setName(query.getName());
        metadata.setProcedureName(call.getProcedureName());
        List<PLSQLParameterMetadata> params=new ArrayList<PLSQLParameterMetadata>();
        if (plsqlStoredFuncs == null) {
          plsqlStoredFuncs=new ArrayList<NamedPLSQLStoredFunctionQueryMetadata>();
        }
        PLSQLargument arg;
        PLSQLParameterMetadata param;
        List<PLSQLargument> types=call.getArguments();
        for (int i=0; i < types.size(); i++) {
          arg=types.get(i);
          param=new PLSQLParameterMetadata();
          param.setName(arg.name);
          String dbType=arg.databaseType.getTypeName();
          if (arg.databaseType == XMLType) {
            dbType=XMLType.name();
          }
 else {
            if (!(getJDBCTypeFromTypeName(dbType) == Types.OTHER)) {
              if (!dbType.equals(BOOLEAN_STR)) {
                dbType=dbType.concat(_TYPE_STR);
              }
            }
          }
          param.setDatabaseType(dbType);
          if (i == 0) {
            metadata.setReturnParameter(param);
            if (arg.cursorOutput) {
              param.setDirection(CURSOR_STR);
            }
          }
 else {
            param.setDirection(getDirectionAsString(arg.direction));
            params.add(param);
          }
        }
        if (params.size() > 0) {
          metadata.setParameters(params);
        }
        plsqlStoredFuncs.add(metadata);
      }
 else {
        StoredFunctionCall call=(StoredFunctionCall)query.getCall();
        NamedStoredFunctionQueryMetadata metadata=new NamedStoredFunctionQueryMetadata();
        metadata.setName(query.getName());
        metadata.setProcedureName(call.getProcedureName());
        List<StoredProcedureParameterMetadata> params=new ArrayList<StoredProcedureParameterMetadata>();
        if (storedFuncs == null) {
          storedFuncs=new ArrayList<NamedStoredFunctionQueryMetadata>();
        }
        DatabaseField arg;
        StoredProcedureParameterMetadata param;
        List<DatabaseField> paramFields=call.getParameters();
        List types=call.getParameterTypes();
        for (int i=0; i < paramFields.size(); i++) {
          arg=paramFields.get(i);
          param=new StoredProcedureParameterMetadata();
          param.setTypeName(arg.getTypeName());
          param.setJdbcType(arg.getSqlType());
          if (arg.isObjectRelationalDatabaseField()) {
            param.setJdbcTypeName(((ObjectRelationalDatabaseField)arg).getSqlTypeName());
          }
          if (i == 0) {
            metadata.setReturnParameter(param);
          }
 else {
            param.setName(arg.getName());
            param.setDirection(getDirectionAsString((Integer)types.get(i)));
            params.add(param);
          }
        }
        if (params.size() > 0) {
          metadata.setParameters(params);
        }
        storedFuncs.add(metadata);
      }
    }
 else     if (query.getCall().isStoredProcedureCall()) {
      if (query.getCall() instanceof PLSQLStoredProcedureCall) {
        PLSQLStoredProcedureCall call=(PLSQLStoredProcedureCall)query.getCall();
        if (plsqlStoredProcs == null) {
          plsqlStoredProcs=new ArrayList<NamedPLSQLStoredProcedureQueryMetadata>();
        }
        NamedPLSQLStoredProcedureQueryMetadata metadata=new NamedPLSQLStoredProcedureQueryMetadata();
        metadata.setName(query.getName());
        metadata.setProcedureName(call.getProcedureName());
        PLSQLParameterMetadata param;
        List<PLSQLParameterMetadata> params=new ArrayList<PLSQLParameterMetadata>();
        List<PLSQLargument> types=call.getArguments();
        for (        PLSQLargument arg : types) {
          param=new PLSQLParameterMetadata();
          param.setName(arg.name);
          String dbType=processTypeName(arg.databaseType.getTypeName());
          if (arg.cursorOutput) {
            param.setDirection(CURSOR_STR);
          }
 else {
            param.setDirection(getDirectionAsString(arg.direction));
          }
          if (arg.databaseType == XMLType) {
            param.setDatabaseType(XMLType.name());
          }
 else {
            param.setDatabaseType(dbType);
          }
          params.add(param);
        }
        if (params.size() > 0) {
          metadata.setParameters(params);
        }
        plsqlStoredProcs.add(metadata);
      }
 else {
        StoredProcedureCall call=(StoredProcedureCall)query.getCall();
        NamedStoredProcedureQueryMetadata metadata=new NamedStoredProcedureQueryMetadata();
        metadata.setName(query.getName());
        metadata.setProcedureName(call.getProcedureName());
        List<StoredProcedureParameterMetadata> params=new ArrayList<StoredProcedureParameterMetadata>();
        DatabaseField arg;
        StoredProcedureParameterMetadata param;
        List<DatabaseField> paramFields=call.getParameters();
        List types=call.getParameterTypes();
        for (int i=0; i < paramFields.size(); i++) {
          arg=paramFields.get(i);
          param=new StoredProcedureParameterMetadata();
          param.setName(arg.getName());
          param.setTypeName(arg.getTypeName());
          param.setJdbcType(arg.getSqlType());
          if (arg.isObjectRelationalDatabaseField()) {
            param.setJdbcTypeName(((ObjectRelationalDatabaseField)arg).getSqlTypeName());
          }
          param.setDirection(getDirectionAsString((Integer)types.get(i)));
          params.add(param);
        }
        if (params.size() > 0) {
          metadata.setParameters(params);
        }
        if (storedProcs == null) {
          storedProcs=new ArrayList<NamedStoredProcedureQueryMetadata>();
        }
        storedProcs.add(metadata);
      }
    }
 else {
      NamedNativeQueryMetadata namedQuery=new NamedNativeQueryMetadata();
      namedQuery.setName(query.getName());
      namedQuery.setQuery(query.getSQLString());
      namedQuery.setResultClassName(query.getReferenceClassName());
      if (namedNativeQueries == null) {
        namedNativeQueries=new ArrayList<NamedNativeQueryMetadata>();
      }
      namedNativeQueries.add(namedQuery);
    }
  }
  if (plsqlStoredProcs != null) {
    xmlEntityMappings.setNamedPLSQLStoredProcedureQueries(plsqlStoredProcs);
  }
  if (plsqlStoredFuncs != null) {
    xmlEntityMappings.setNamedPLSQLStoredFunctionQueries(plsqlStoredFuncs);
  }
  if (storedProcs != null) {
    xmlEntityMappings.setNamedStoredProcedureQueries(storedProcs);
  }
  if (storedFuncs != null) {
    xmlEntityMappings.setNamedStoredFunctionQueries(storedFuncs);
  }
  if (namedNativeQueries != null) {
    xmlEntityMappings.setNamedNativeQueries(namedNativeQueries);
  }
  List<String> embeddables=new ArrayList<String>();
  Map<String,ClassAccessor> accessors=new HashMap<String,ClassAccessor>();
  for (  ClassDescriptor cdesc : descriptors) {
    boolean embeddable=false;
    ClassAccessor classAccessor;
    if (cdesc.isAggregateDescriptor()) {
      embeddable=true;
      classAccessor=new EmbeddableAccessor();
      ((EmbeddableAccessor)classAccessor).setName(cdesc.getAlias());
      embeddables.add(cdesc.getJavaClassName());
    }
 else {
      classAccessor=new EntityAccessor();
      ((EntityAccessor)classAccessor).setEntityName(cdesc.getAlias());
    }
    classAccessor.setClassName(cdesc.getJavaClassName());
    classAccessor.setAccess(EL_ACCESS_VIRTUAL);
    if (cdesc.isObjectRelationalDataTypeDescriptor()) {
      ObjectRelationalDataTypeDescriptor odesc=(ObjectRelationalDataTypeDescriptor)cdesc;
      if (odesc.getOrderedFields().size() > 0) {
        StructMetadata struct=new StructMetadata();
        struct.setName(odesc.getStructureName());
        struct.setFields(odesc.getOrderedFields());
        classAccessor.setStruct(struct);
      }
    }
    if (!embeddable && cdesc.getTableName() != null) {
      TableMetadata table=new TableMetadata();
      table.setName(cdesc.getTableName());
      ((EntityAccessor)classAccessor).setTable(table);
    }
    if (!embeddable) {
      List<NamedNativeQueryMetadata> namedNatQueries=new ArrayList<NamedNativeQueryMetadata>();
      NamedNativeQueryMetadata namedQuery;
      DatabaseQuery dbQuery;
      for (Iterator<DatabaseQuery> queryIt=cdesc.getQueryManager().getAllQueries().iterator(); queryIt.hasNext(); ) {
        dbQuery=queryIt.next();
        namedQuery=new NamedNativeQueryMetadata();
        namedQuery.setName(dbQuery.getName());
        namedQuery.setQuery(dbQuery.getSQLString());
        namedQuery.setResultClassName(dbQuery.getReferenceClassName());
        namedNatQueries.add(namedQuery);
      }
      if (namedNatQueries.size() > 0) {
        ((EntityAccessor)classAccessor).setNamedNativeQueries(namedNatQueries);
      }
    }
    classAccessor.setAttributes(new XMLAttributes());
    classAccessor.getAttributes().setIds(new ArrayList<IdAccessor>());
    classAccessor.getAttributes().setBasics(new ArrayList<BasicAccessor>());
    classAccessor.getAttributes().setArrays(new ArrayList<ArrayAccessor>());
    classAccessor.getAttributes().setStructures(new ArrayList<StructureAccessor>());
    classAccessor.getAttributes().setEmbeddeds(new ArrayList<EmbeddedAccessor>());
    if (embeddable) {
      xmlEntityMappings.getEmbeddables().add((EmbeddableAccessor)classAccessor);
    }
 else {
      xmlEntityMappings.getEntities().add((EntityAccessor)classAccessor);
    }
    accessors.put(cdesc.getJavaClassName(),classAccessor);
  }
  for (  ClassDescriptor cdesc : descriptors) {
    ClassAccessor classAccessor=accessors.get(cdesc.getJavaClassName());
    MappingAccessor mapAccessor;
    for (    DatabaseMapping dbMapping : cdesc.getMappings()) {
      mapAccessor=generateMappingAccessor(dbMapping,embeddables);
      if (mapAccessor == null) {
        continue;
      }
      if (mapAccessor.isId()) {
        classAccessor.getAttributes().getIds().add((IdAccessor)mapAccessor);
      }
 else       if (mapAccessor.isBasic()) {
        classAccessor.getAttributes().getBasics().add((BasicAccessor)mapAccessor);
      }
 else       if (mapAccessor instanceof ArrayAccessor) {
        classAccessor.getAttributes().getArrays().add((ArrayAccessor)mapAccessor);
      }
 else       if (mapAccessor instanceof StructureAccessor) {
        classAccessor.getAttributes().getStructures().add((StructureAccessor)mapAccessor);
      }
 else {
        classAccessor.getAttributes().getEmbeddeds().add((EmbeddedAccessor)mapAccessor);
      }
    }
  }
  EntityAccessor eAccessor=new EntityAccessor();
  eAccessor.setAttributes(new XMLAttributes());
  eAccessor.getAttributes().setEmbeddeds(new ArrayList<EmbeddedAccessor>());
  eAccessor.getAttributes().setIds(new ArrayList<IdAccessor>());
  eAccessor.setClassName(ENTITY_STR);
  eAccessor.setAccess(EL_ACCESS_VIRTUAL);
  xmlEntityMappings.getEntities().add(eAccessor);
  EmbeddedAccessor fakeAccessor;
  int i=0;
  for (  ClassDescriptor cdesc : descriptors) {
    if (cdesc.isAggregateDescriptor()) {
      fakeAccessor=new EmbeddedAccessor();
      fakeAccessor.setName(FAKE_STR + i++);
      fakeAccessor.setAttributeType(cdesc.getJavaClassName());
      eAccessor.getAttributes().getEmbeddeds().add(fakeAccessor);
    }
  }
  IdAccessor idAccessor=new IdAccessor();
  idAccessor.setName(FAKEPK_STR);
  idAccessor.setAttributeType(STRING_STR);
  ColumnMetadata column=new ColumnMetadata();
  column.setName(FAKE_PK_STR);
  idAccessor.setColumn(column);
  eAccessor.getAttributes().getIds().add(idAccessor);
  return xmlEntityMappings;
}