Package org.exolab.castor.mapping.xml

Examples of org.exolab.castor.mapping.xml.FieldMapping


        Enumeration ef = cm.getClassChoice().enumerateFieldMapping();
        boolean isExistFieldId = isUseFieldIdentity(cm);

        // Go through all fields.
        while (ef.hasMoreElements()) {
            FieldMapping fm = (FieldMapping) ef.nextElement();
           
            // Identity are defined at field.
            if (isExistFieldId && fm.getIdentity()) {
                // Get field type.
                TypeInfo typeinfo = null;
                String sqltype = fm.getSql().getType();

                if (sqltype != null) {
                    typeinfo = _typeMapper.getType(sqltype);
                }

                if (typeinfo == null) {
                    String[] refRefType = resolveTypeReferenceForIds(fm
                            .getType());
                    for (int l = 0; l < refRefType.length; l++) {
                        types.add(refRefType[l]);
                        isFoundKey = true;
                    }
                } else {
                    for (int i = 0; i < fm.getSql().getNameCount(); i++) {
                        types.add(fm.getSql().getType());
                        isFoundKey = true;
                    }
                }
            } else if (!isExistFieldId) {
                // Identities are defined at class tag.
                String fieldName = fm.getName();
                for (int j = 0; j < ids.length; j++) {
                    // If sqlnames[i] equals ids[j] we found a reference type.
                    if (fieldName.equals(ids[j])) {

                        // Check for type if this table is a reference table.
                        TypeInfo typeinfo = null;
                        String sqltype = fm.getSql().getType();

                        // Verify if sqltype exists.
                        if (sqltype != null) {
                            typeinfo = _typeMapper.getType(sqltype);
                        }

                        if (typeinfo == null) {
                            ClassMapping cmRef = getClassMappingByName(fm.getType());
                            // If cmRef is null, the reference class could not be found
                            // so we need to use field type.
                            if (cmRef == null) {                       
                                typeinfo = _typeMapper.getType(fm.getType());
                               
                                if (typeinfo == null) {
                                    throw new TypeNotFoundException(
                                            "Can't resolve type " + fm.getType());
                                }
                                int count = fm.getSql().getNameCount();
                                if (count == 0) { count = fm.getSql().getManyKeyCount(); }
                               
                                for (int l = 0; l < count; l++) {
                                    types.add(fm.getType());
                                    isFoundKey = true;
                                }
                               
                            } else {
                                // Resolve type for reference class.
                                String[] refRefType = resolveTypeReferenceForIds(
                                        fm.getType());
                                for (int l = 0; l < refRefType.length; l++) {
                                    types.add(refRefType[l]);
                                    isFoundKey = true;
                                }
                            }
                        } else {
                            types.add(fm.getSql().getType());
                            isFoundKey = true;
                        }
                    }
                }
            }
View Full Code Here


     */
    public boolean isUseFieldIdentity(final ClassMapping cm) {
        Enumeration ef = cm.getClassChoice().enumerateFieldMapping();

        while (ef.hasMoreElements()) {
            FieldMapping fm = (FieldMapping) ef.nextElement();
            if (fm.getIdentity()) { return true; }
        }
        return false;
    }
View Full Code Here

        }

        Enumeration ef = cm.getClassChoice().enumerateFieldMapping();
        boolean isExistFieldId = isUseFieldIdentity(cm);
        while (ef.hasMoreElements()) {
            FieldMapping fm = (FieldMapping) ef.nextElement();
            // Add all sql columns into identity list.
            if (isExistFieldId && fm.getIdentity()) {
                isExistFieldId = true;
                int ncount = fm.getSql().getNameCount();
                for (int i = 0; i < ncount; i++) {
                    ids.add(fm.getSql().getName(i));
                }
            } else if (!isExistFieldId) {
                // If using class identity, find out all correspondent column names.
                String fieldName = fm.getName();
                for (int j = 0; j < identities.length; j++) {
                    if (fieldName.equals(identities[j])) {
                        // Check for type if this table is a reference table.
                        int ncount = fm.getSql().getNameCount();
                        for (int i = 0; i < ncount; i++) {
                            ids.add(fm.getSql().getName(i));
                        }
                    }
                }              
            }
        }
View Full Code Here

        Vector ids = new Vector();
       
        boolean isExistFieldId = false;
        Enumeration ef = cm.getClassChoice().enumerateFieldMapping();
        while (ef.hasMoreElements()) {
            FieldMapping fm = (FieldMapping) ef.nextElement();
            // Add names of all identity columns to list.
            if (isExistFieldId && fm.getIdentity()) {
                isExistFieldId = true;
                ids.add(fm.getName());
            }
        }
       
        if (!isExistFieldId) {
            String[] identities = cm.getIdentity();
View Full Code Here

        setMapping(mapping);

        //ssnr field
        String ssnrFieldName = "ssnr";
        FieldDescriptorImpl ssnrFieldDescr;
        FieldMapping ssnrFM = new FieldMapping();
        TypeInfo ssnrType = new TypeInfo(java.lang.Long.class);
        // Set columns required (= not null)
        ssnrType.setRequired(true);

        FieldHandler ssnrHandler;
        try {
            Method ssnrGetMethod = Father.class.getMethod("getSsnr", null);
            Method ssnrSetMethod = Father.class.getMethod("setSsnr", new Class[]{
                long.class});

            ssnrHandler = new FieldHandlerImpl(ssnrFieldName, null, null,
                ssnrGetMethod, ssnrSetMethod, ssnrType);

        } catch (SecurityException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (MappingException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (NoSuchMethodException e1) {
            throw new RuntimeException(e1.getMessage());
        }
        // Instantiate ssnr field descriptor
        ssnrFieldDescr = new FieldDescriptorImpl(ssnrFieldName, ssnrType,ssnrHandler, false);
        ssnrFieldDescr.addNature(FieldDescriptorJDONature.class.getName());
        FieldDescriptorJDONature ssnrFieldJdoNature = new FieldDescriptorJDONature(ssnrFieldDescr);
        ssnrFieldJdoNature.setSQLName(new String[] { "ssnr" });
        ssnrFieldJdoNature.setSQLType(new int[] {SQLTypeInfos.javaType2sqlTypeNum(java.lang.Long.class) });
        ssnrFieldJdoNature.setManyTable(null);
        ssnrFieldJdoNature.setManyKey(new String[] {});
        ssnrFieldJdoNature.setDirtyCheck(false);
        ssnrFieldJdoNature.setReadOnly(false);

        ssnrFieldDescr.setContainingClassDescriptor(this);
        ssnrFieldDescr.setIdentity(true);
        ssnrFM.setIdentity(true);
        ssnrFM.setDirect(false);
        ssnrFM.setName("ssnr");
        ssnrFM.setRequired(true);
        ssnrFM.setSetMethod("setSsnr");
        ssnrFM.setGetMethod("getSsnr");
        Sql ssnrSql = new Sql();
        ssnrSql.addName("ssnr");
        ssnrSql.setType("integer");
        ssnrFM.setSql(ssnrSql);
        ssnrFM.setType("long");
        choice.addFieldMapping(ssnrFM);

        //firstName field
        String firstNameFieldName = "firstName";
        FieldDescriptorImpl firstNameFieldDescr;
        FieldMapping firstNameFM = new FieldMapping();
        TypeInfo firstNameType = new TypeInfo(java.lang.String.class);
        // Set columns required (= not null)
        firstNameType.setRequired(true);

        FieldHandler firstNameHandler;
        try {
            Method firstNameGetMethod = Father.class.getMethod("getFirstName", null);
            Method firstNameSetMethod = Father.class.getMethod("setFirstName", new Class[]{
                java.lang.String.class});

            firstNameHandler = new FieldHandlerImpl(firstNameFieldName, null, null,
                firstNameGetMethod, firstNameSetMethod, firstNameType);

        } catch (SecurityException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (MappingException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (NoSuchMethodException e1) {
            throw new RuntimeException(e1.getMessage());
        }
        // Instantiate firstName field descriptor
        firstNameFieldDescr = new FieldDescriptorImpl(firstNameFieldName, firstNameType,firstNameHandler, false);
        firstNameFieldDescr.addNature(FieldDescriptorJDONature.class.getName());
        FieldDescriptorJDONature firstNameFieldJdoNature = new FieldDescriptorJDONature(firstNameFieldDescr);
        firstNameFieldJdoNature.setSQLName(new String[] { "firstName" });
        firstNameFieldJdoNature.setSQLType(new int[] {SQLTypeInfos.javaType2sqlTypeNum(java.lang.String.class) });
        firstNameFieldJdoNature.setManyTable(null);
        firstNameFieldJdoNature.setManyKey(new String[] {});
        firstNameFieldJdoNature.setDirtyCheck(false);
        firstNameFieldJdoNature.setReadOnly(false);

        firstNameFieldDescr.setContainingClassDescriptor(this);
        firstNameFieldDescr.setIdentity(false);
        firstNameFM.setIdentity(false);
        firstNameFM.setDirect(false);
        firstNameFM.setName("firstName");
        firstNameFM.setRequired(true);
        firstNameFM.setSetMethod("setFirstName");
        firstNameFM.setGetMethod("getFirstName");
        Sql firstNameSql = new Sql();
        firstNameSql.addName("firstName");
        firstNameSql.setType("varchar");
        firstNameFM.setSql(firstNameSql);
        firstNameFM.setType("java.lang.String");
        choice.addFieldMapping(firstNameFM);

        //lastName field
        String lastNameFieldName = "lastName";
        FieldDescriptorImpl lastNameFieldDescr;
        FieldMapping lastNameFM = new FieldMapping();
        TypeInfo lastNameType = new TypeInfo(java.lang.String.class);
        // Set columns required (= not null)
        lastNameType.setRequired(true);

        FieldHandler lastNameHandler;
        try {
            Method lastNameGetMethod = Father.class.getMethod("getLastName", null);
            Method lastNameSetMethod = Father.class.getMethod("setLastName", new Class[]{
                java.lang.String.class});

            lastNameHandler = new FieldHandlerImpl(lastNameFieldName, null, null,
                lastNameGetMethod, lastNameSetMethod, lastNameType);

        } catch (SecurityException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (MappingException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (NoSuchMethodException e1) {
            throw new RuntimeException(e1.getMessage());
        }
        // Instantiate lastName field descriptor
        lastNameFieldDescr = new FieldDescriptorImpl(lastNameFieldName, lastNameType,lastNameHandler, false);
        lastNameFieldDescr.addNature(FieldDescriptorJDONature.class.getName());
        FieldDescriptorJDONature lastNameFieldJdoNature = new FieldDescriptorJDONature(lastNameFieldDescr);
        lastNameFieldJdoNature.setSQLName(new String[] { "lastName" });
        lastNameFieldJdoNature.setSQLType(new int[] {SQLTypeInfos.javaType2sqlTypeNum(java.lang.String.class) });
        lastNameFieldJdoNature.setManyTable(null);
        lastNameFieldJdoNature.setManyKey(new String[] {});
        lastNameFieldJdoNature.setDirtyCheck(false);
        lastNameFieldJdoNature.setReadOnly(false);

        lastNameFieldDescr.setContainingClassDescriptor(this);
        lastNameFieldDescr.setIdentity(false);
        lastNameFM.setIdentity(false);
        lastNameFM.setDirect(false);
        lastNameFM.setName("lastName");
        lastNameFM.setRequired(true);
        lastNameFM.setSetMethod("setLastName");
        lastNameFM.setGetMethod("getLastName");
        Sql lastNameSql = new Sql();
        lastNameSql.addName("lastName");
        lastNameSql.setType("varchar");
        lastNameFM.setSql(lastNameSql);
        lastNameFM.setType("java.lang.String");
        choice.addFieldMapping(lastNameFM);

        setFields(new FieldDescriptor[] {firstNameFieldDescr,lastNameFieldDescr});
        setIdentities(new FieldDescriptor[] {ssnrFieldDescr});
    }
View Full Code Here

        LOG.info( "Begin: Walking the mapping descriptor via objects" );

        MappingRoot mappingRoot = _mapping.getRoot();
        ClassMapping classMap;
        FieldMapping fieldMap;
        FieldMapping[] fieldMaps;

        int mappingCount = mappingRoot.getClassMappingCount();

        // loop over the classes
        for ( int i = 0; i < mappingCount; ++i )
        {
            classMap = mappingRoot.getClassMapping( i );
            LOG.debug( "Class name: " + classMap.getName() );

            fieldMaps = classMap.getClassChoice().getFieldMapping();

            LOG.debug( "fieldMaps.length: " + fieldMaps.length );

            // loop over the fields in each class
            for ( int j = 0; j < fieldMaps.length; ++j )
            {
                fieldMap = fieldMaps[j];
                LOG.debug( "        Field name: " + fieldMap.getName() );
                LOG.debug( "        Field type: " + fieldMap.getType() );
            }
        }

        LOG.info( "End: Walking the mapping descriptor via objects" );
View Full Code Here

            throw new MappingException( "mapping.classNotConstructable", cls.getName() );

        XMLClassDescriptor xmlClass;
        FieldDescriptor[]  fields;
        ClassMapping       classMap;
        FieldMapping       fieldMap;

        boolean introspected = false;
        try {
            if (_forceIntrospection) {
                xmlClass = _introspector.generateClassDescriptor( cls );
                introspected = true;
            }
            else {
                xmlClass = _resolver.resolve( cls );
                introspected = _introspector.introspected(xmlClass);
            }
        }
        catch ( MarshalException except ) {
            throw new MappingException( except );
        }
        classMap = new ClassMapping();
        classMap.setName( cls.getName() );
        classMap.setDescription( "Default mapping for class " + cls.getName() );
       
        //-- prevent default access from showing up in the mapping
        classMap.setAccess(null);
       
        //-- map-to
        MapTo mapTo = new MapTo();
        mapTo.setXml( xmlClass.getXMLName() );
        mapTo.setNsUri( xmlClass.getNameSpaceURI() );
        mapTo.setNsPrefix( xmlClass.getNameSpacePrefix() );
        classMap.setMapTo( mapTo );
       
        //-- add mapping to hashtable before processing
        //-- fields so we can do recursive processing
        _mappings.put( cls, classMap );
       
        fields = xmlClass.getFields();
        for ( int i = 0 ; i < fields.length ; ++i ) {
           
            FieldDescriptor fdesc = fields[ i ];
           
            String fieldName = fdesc.getFieldName();
           
            boolean isContainer = false;
            //-- check for collection wrapper
            if (introspected && fieldName.startsWith("##container")) {
                fdesc = fdesc.getClassDescriptor().getFields()[0];
                fieldName = fdesc.getFieldName();
                isContainer = true;
            }
           
           
            Class fieldType = fdesc.getFieldType();
           
           
            //-- check to make sure we can find the accessors...
            //-- if we used introspection we don't need to
            //-- enter this block...only when descriptors
            //-- were generated using the source code generator
            //-- or by hand.
            if ((!introspected) && fieldName.startsWith(UNDERSCORE)) {
               
                //-- check to see if we need to remove underscore
                if (!_mappingLoader.canFindAccessors(cls, fieldName, fieldType))
                    fieldName = fieldName.substring(1);
               
                //-- check to see if we need to remove "List" prefix
                //-- used by generated source code
                if (!_mappingLoader.canFindAccessors(cls, fieldName, fieldType))
                {
                    if (fieldName.endsWith("List")) {
                        int len = fieldName.length()-4;
                        String tmpName = fieldName.substring(0, len);
                        if (_mappingLoader.canFindAccessors(cls, tmpName, fieldType))
                            fieldName = tmpName;                           
                    }
                }
            }
           
            fieldMap = new FieldMapping();
            fieldMap.setName( fieldName );
           
           
            //-- unwrap arrays of objects
            boolean isArray = fieldType.isArray();
            while (fieldType.isArray())
                fieldType = fieldType.getComponentType();
               
           
            //-- To prevent outputing of optional fields...check
            //-- for value first before setting
            if (fdesc.isRequired())  fieldMap.setRequired( true );
            if (fdesc.isTransient()) fieldMap.setTransient( true );
            if ( fdesc.isMultivalued() ) {
               
                //-- special case for collections
                if (isContainer) {
                    //-- backwards than what you'd expect, but
                    //-- if the collection had a "container" wrapper
                    //-- then we specify container="false" in the
                    //-- mapping file.
                    fieldMap.setContainer(false);
                }
               
                //-- try to guess collection type
                if (isArray) {
                    fieldMap.setCollection(CollectionType.ARRAY);
                }
                else {
                    //-- if the fieldType is the collection, then set appropriate
                    //-- collection type
                    String colName = CollectionHandlers.getCollectionName(fieldType);
                    if (colName != null) {
                        fieldMap.setCollection(CollectionType.valueOf(colName));
                        fieldType = Object.class;
                    }
                    //-- help maintain compatibility with generated
                    //-- descriptors
                    else if (_mappingLoader.returnsArray(cls, fieldName, fieldType)) {
                        fieldMap.setCollection( CollectionType.ARRAY );
                    }
                    else {
                        fieldMap.setCollection( CollectionType.ENUMERATE );
                    }
                }
            }
           
            //-- fieldType
            fieldMap.setType( fieldType.getName() );
           
               
            //-- handle XML Specific information
            fieldMap.setBindXml( new BindXml() );
            fieldMap.getBindXml().setName( ( (XMLFieldDescriptor) fdesc ).getXMLName() );
            fieldMap.getBindXml().setNode( BindXmlNodeType.valueOf( ((XMLFieldDescriptor) fields[ i ]).getNodeType().toString() ) );
            classMap.addFieldMapping( fieldMap );
           
            if (deep) {
                if ( _mappings.get(fieldType) != null) continue;
                if (Types.isSimpleType(fieldType)) continue;               
View Full Code Here

            throw new MappingException( "mapping.classNotConstructable", cls.getName() );

        XMLClassDescriptor xmlClass;
        FieldDescriptor[]  fields;
        ClassMapping       classMap;
        FieldMapping       fieldMap;

        boolean introspected = false;
        try {
            if (_forceIntrospection) {
                xmlClass = _introspector.generateClassDescriptor( cls );
                introspected = true;
            }
            else {
                xmlClass = _resolver.resolve( cls );
                introspected = _introspector.introspected(xmlClass);
            }
        }
        catch ( MarshalException except ) {
            throw new MappingException( except );
        }
        classMap = new ClassMapping();
        classMap.setName( cls.getName() );
        classMap.setDescription( "Default mapping for class " + cls.getName() );
       
        //-- prevent default access from showing up in the mapping
        classMap.setAccess(null);
       
        //-- map-to
        MapTo mapTo = new MapTo();
        mapTo.setXml( xmlClass.getXMLName() );
        mapTo.setNsUri( xmlClass.getNameSpaceURI() );
        mapTo.setNsPrefix( xmlClass.getNameSpacePrefix() );
        classMap.setMapTo( mapTo );
       
        //-- add mapping to hashtable before processing
        //-- fields so we can do recursive processing
        _mappings.put( cls, classMap );
       
        fields = xmlClass.getFields();
        for ( int i = 0 ; i < fields.length ; ++i ) {
           
            FieldDescriptor fdesc = fields[ i ];
           
            String fieldName = fdesc.getFieldName();
           
            boolean isContainer = false;
            //-- check for collection wrapper
            if (introspected && fieldName.startsWith("##container")) {
                fdesc = fdesc.getClassDescriptor().getFields()[0];
                fieldName = fdesc.getFieldName();
                isContainer = true;
            }
           
           
            Class fieldType = fdesc.getFieldType();
           
           
            //-- check to make sure we can find the accessors...
            //-- if we used introspection we don't need to
            //-- enter this block...only when descriptors
            //-- were generated using the source code generator
            //-- or by hand.
            if ((!introspected) && fieldName.startsWith(UNDERSCORE)) {
               
                //-- check to see if we need to remove underscore
                if (!_mappingLoader.canFindAccessors(cls, fieldName, fieldType))
                    fieldName = fieldName.substring(1);
               
                //-- check to see if we need to remove "List" prefix
                //-- used by generated source code
                if (!_mappingLoader.canFindAccessors(cls, fieldName, fieldType))
                {
                    if (fieldName.endsWith("List")) {
                        int len = fieldName.length()-4;
                        String tmpName = fieldName.substring(0, len);
                        if (_mappingLoader.canFindAccessors(cls, tmpName, fieldType))
                            fieldName = tmpName;                           
                    }
                }
            }
           
            fieldMap = new FieldMapping();
            fieldMap.setName( fieldName );
           
           
            //-- unwrap arrays of objects
            boolean isArray = fieldType.isArray();
            while (fieldType.isArray())
                fieldType = fieldType.getComponentType();
               
           
            //-- To prevent outputing of optional fields...check
            //-- for value first before setting
            if (fdesc.isRequired())  fieldMap.setRequired( true );
            if (fdesc.isTransient()) fieldMap.setTransient( true );
            if ( fdesc.isMultivalued() ) {
               
                //-- special case for collections
                if (isContainer) {
                    //-- backwards than what you'd expect, but
                    //-- if the collection had a "container" wrapper
                    //-- then we specify container="false" in the
                    //-- mapping file.
                    fieldMap.setContainer(false);
                }
               
                //-- try to guess collection type
                if (isArray) {
                    fieldMap.setCollection(CollectionType.ARRAY);
                }
                else {
                    //-- if the fieldType is the collection, then set appropriate
                    //-- collection type
                    String colName = CollectionHandlers.getCollectionName(fieldType);
                    if (colName != null) {
                        fieldMap.setCollection(CollectionType.valueOf(colName));
                        fieldType = Object.class;
                    }
                    //-- help maintain compatibility with generated
                    //-- descriptors
                    else if (_mappingLoader.returnsArray(cls, fieldName, fieldType)) {
                        fieldMap.setCollection( CollectionType.ARRAY );
                    }
                    else {
                        fieldMap.setCollection( CollectionType.ENUMERATE );
                    }
                }
            }
           
            //-- fieldType
            fieldMap.setType( fieldType.getName() );
           
               
            //-- handle XML Specific information
            fieldMap.setBindXml( new BindXml() );
            fieldMap.getBindXml().setName( ( (XMLFieldDescriptor) fdesc ).getXMLName() );
            fieldMap.getBindXml().setNode( BindXmlNodeType.valueOf( ((XMLFieldDescriptor) fields[ i ]).getNodeType().toString() ) );
            classMap.addFieldMapping( fieldMap );
           
            if (deep) {
                if ( _mappings.get(fieldType) != null) continue;
                if (Types.isSimpleType(fieldType)) continue;               
View Full Code Here

    AttributeListImpl attrs = new AttributeListImpl();

    for (int i = 0; i < attrCols.length; i++) {
        String attrCol = attrCols[i];
        Integer attrColNum = (Integer) _cols.get(attrCol);
        FieldMapping field = desc.getAttr(attrCol);
        String attrName = null;
        if (field.getBindXml() == null || field.getBindXml().getName() == null) {
      attrName = field.getName();
        } else {
      attrName = field.getBindXml().getName();
        }

        String attrValue = rs.getString(attrColNum.intValue());
        attrs.addAttribute(attrName, "CDATA", attrValue);
    }

    _handler.startElement(elementName, attrs);

    for (int j = 0; j < simpleElementCols.length; j++) {
        String simpleElementCol = simpleElementCols[j];
        Integer elementColNum = (Integer) _cols.get(simpleElementCol);
        FieldMapping elField = desc.getSimpleElement(simpleElementCol);
        String elName = null;
        if (elField.getBindXml() == null || elField.getBindXml().getName() == null) {
      elName = elField.getName();
        } else {
      elName = elField.getBindXml().getName();
        }

        String elValue = rs.getString(elementColNum.intValue());
        _handler.startElement(elName, new AttributeListImpl());
        _handler.characters(elValue.toCharArray(), 0, elValue.length());
View Full Code Here

  }

  String table = mapTo.getTable();

        FieldMapping[] fields = clsMapping.getFieldMapping();
  FieldMapping identity = null;

        String identityName = clsMapping.getIdentity(0);

  for (int j = 0; j < fields.length; j++) {
      if (fields[j].getName().equals(identityName)) {
    identity = fields[j];
    break;
      }
  }

  if (identity == null) {
      throw new DTXException("no identity field in class: " + clsMapping.getName());
  }

  Sql identitySQLElement = identity.getSql();

  if (identitySQLElement == null) {
      throw new DTXException("no identity SQL info in class: " + clsMapping.getName());
  }

  String identitySQL = identitySQLElement.getName()[0];

  _ids.add(table + "." + identitySQL);

  DTXClassDescriptor desc = new DTXClassDescriptor(clsMapping);

  _classes.put(table + "." + identitySQL, desc);

        // If this class extends another class, create a join with the parent table and
        // add the load fields of the parent class (but not the store fields)
        if (clsMapping.getExtends() != null) {

        /**
          * TODO : Needs to be resolved by Hand
          */

        MapTo extendsTo = new MapTo();//(ClassMapping) clsMapping.getExtends()).getMapTo();
      if (extendsTo == null) {
    throw new DTXException("no mapping info for extends table.");
      }
      String extendsTable = extendsTo.getTable();
            expr.addInnerJoin(table, identitySQL, extendsTable, identitySQL);
            /**
             * needs to be resolved by hand
             */
            initQuery(new ClassMapping(), expr);
            //(ClassMapping) clsMapping.getExtends(), expr);
        }

        for (int i = 0; i < fields.length; ++i) {
      FieldMapping field = fields[i];
      Sql fieldSql = field.getSql();
      ClassMapping relMapping = _eng.getClassMapping(field.getType());

      if (fieldSql == null) {
    if (relMapping != null) {

        // We have a one-to-many relationship with a sub object.
        // get those objects, too.

                    FieldMapping[] relFields = relMapping.getFieldMapping();
        MapTo relMapTo = relMapping.getMapTo();

        if (relMapTo == null) {
      throw new DTXException("dtx.NoRelatedMapTo");
        }

        String relTable = relMapTo.getTable();

        String relId = null;
                    String foreKey = null;

                    for (int k = 0; k < relFields.length; k++ ) {
      Sql relSql = relFields[k].getSql();
                        if (relSql != null) {
          String type = relFields[k].getType();
          if (type != null && type.equals(clsMapping.getName())) {
        foreKey = relSql.getName()[0];
          }
      }
                    }

                    if (foreKey != null) {
                        expr.addOuterJoin(table, identitySQL, relTable, foreKey);
      DTXClassDescriptor relDesc = new DTXClassDescriptor(relMapping);

      for (int n = 0; n < relFields.length; n++ ) {
          FieldMapping relField = relFields[n];
          Sql relSql = relFields[n].getSql();
          if (relSql != null) {
        String relFieldName = relSql.getName()[0];
        if (relFieldName == null) {
            relFieldName = relFields[n].getName();
        }
        String relFullName = relTable + "." + relFieldName;

        BindXml relFieldXml = relFields[n].getBindXml();
        String node = "element";
        if (relFieldXml != null) {
            node = relFieldXml.getNode().toString();
        }

        if (!relFieldName.equals(foreKey)) {
            expr.addColumn(relTable, relFieldName);
            _cols.put(relTable + "." + relFieldName, new Integer(++_lastCol));

            if (node.equalsIgnoreCase("attribute")) {
          relDesc.addAttr(relFullName, relField);
            } else if (node.equalsIgnoreCase("element")) {
          relDesc.addSimpleElement(relFullName, relField);
            } else if (node.equalsIgnoreCase("text")) {
          relDesc.setTextCol(relFullName, relField);
            }
        }
        if (relField.getName().equals(relMapping.getIdentity())) {
            _ids.add(relTable + "." + relFieldName);
            desc.addContained(relTable + "." + relFieldName, relMapping);
            _classes.put(relTable + "." + relFieldName, relDesc);
        }
          }
View Full Code Here

TOP

Related Classes of org.exolab.castor.mapping.xml.FieldMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.