Ejemplo n.º 1
0
        private void addValueInSecondPass(XElement parent, IValue value, ICompositeMapperBuilder currentMapper, string entityName,
                                          EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData,
                                          bool insertable, bool processModifiedFlag)
        {
            var type = value.Type;

            if (type is ComponentType)
            {
                componentMetadataGenerator.AddComponent(parent, propertyAuditingData, value, currentMapper,
                                                        entityName, xmlMappingData, false, insertable);
                return;                // mod flag field has been already generated in first pass
            }
            else if (type is ManyToOneType)
            {
                toOneRelationMetadataGenerator.AddToOne(parent, propertyAuditingData, value, currentMapper, entityName, insertable);
            }
            else if (type is OneToOneType)
            {
                var oneToOne = (OneToOne)value;
                if (oneToOne.ReferencedPropertyName != null && propertyAuditingData.RelationTargetAuditMode != RelationTargetAuditMode.NotAudited)
                {
                    toOneRelationMetadataGenerator.AddOneToOneNotOwning(propertyAuditingData, value, currentMapper, entityName);
                }
                else
                {
                    // @OneToOne relation marked with @PrimaryKeyJoinColumn
                    toOneRelationMetadataGenerator.AddOneToOnePrimaryKeyJoinColumn(propertyAuditingData, value,
                                                                                   currentMapper, entityName, insertable);
                }
            }
            else if (type is CollectionType)
            {
                var collectionMetadataGenerator = new CollectionMetadataGenerator(_metaDataStore, this, (Mapping.Collection)value, currentMapper, entityName,
                                                                                  xmlMappingData, propertyAuditingData);
                collectionMetadataGenerator.AddCollection();
            }
            else
            {
                return;
            }
            addModifiedFlagIfNeeded(parent, propertyAuditingData, processModifiedFlag);
        }
        //@SuppressWarnings({"unchecked"})
        public void AddValue(XmlElement parent, IValue value, ICompositeMapperBuilder currentMapper, String entityName,
                      EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData,
                      bool insertable, bool firstPass)
        {
            IType type = value.Type;

            // only first pass
            if (firstPass)
            {
                if (BasicMetadataGenerator.AddBasic(parent, propertyAuditingData, value, currentMapper,
                        insertable, false))
                {
                    // The property was mapped by the basic generator.
                    return;
                }
            }

            if (type is ComponentType)
            {
                // both passes
                componentMetadataGenerator.AddComponent(parent, propertyAuditingData, value, currentMapper,
                        entityName, xmlMappingData, firstPass);
            }
            else if (type is ManyToOneType)
            {
                // only second pass
                if (!firstPass)
                {
                    toOneRelationMetadataGenerator.AddToOne(parent, propertyAuditingData, value, currentMapper,
                            entityName, insertable);
                }
            }
            else if (type is OneToOneType)
            {
                // only second pass
                if (!firstPass)
                {
                    toOneRelationMetadataGenerator.AddOneToOneNotOwning(propertyAuditingData, value,
                            currentMapper, entityName);
                }
            }
            else if (type is CollectionType)
            {
                // only second pass
                if (!firstPass)
                {
                    CollectionMetadataGenerator collectionMetadataGenerator = new CollectionMetadataGenerator(this,
                            (Mapping.Collection)value, currentMapper, entityName, xmlMappingData,
                            propertyAuditingData);
                    collectionMetadataGenerator.AddCollection();
                }
            }
            else
            {
                if (firstPass)
                {
                    // If we got here in the first pass, it means the basic mapper didn't map it, and none of the
                    // above branches either.
                    ThrowUnsupportedTypeException(type, entityName, propertyAuditingData.Name);
                }
            }
        }