コード例 #1
0
            public ComponentPropertiesSource(Component component)
            {
                var xclass = component.IsDynamic ?
                             typeof(markerClassForDynamicEntity) :
                             component.ComponentClass;

                DeclaredPersistentProperties = component.IsDynamic ?
                                               createDeclaredPersistentPropertyForDynamicComponent(component) :
                                               PropertyAndMemberInfo.PersistentInfo(xclass, component.PropertyIterator);
                Class = xclass;
            }
コード例 #2
0
        private void addBidirectionalInfo(IDictionary <System.Type, IEntityMeta> metas)
        {
            foreach (var type in metas.Keys)
            {
                var persistentClass = _nhibernateConfiguration.GetClassMapping(type);
                if (persistentClass == null)
                {
                    continue;
                }
                foreach (var property in persistentClass.PropertyIterator)
                {
                    //is it a collection?
                    var collectionValue = property.Value as Mapping.Collection;
                    if (collectionValue == null)
                    {
                        continue;
                    }

                    //find referenced entity name
                    var referencedEntity = MappingTools.ReferencedEntityName(property.Value);
                    if (referencedEntity == null)
                    {
                        continue;
                    }


                    var refPersistentClass = _nhibernateConfiguration.GetClassMapping(referencedEntity);
                    foreach (var refProperty in refPersistentClass.PropertyClosureIterator)
                    {
                        var attr = createAuditMappedByAttributeIfReferenceImmutable(collectionValue, refProperty);
                        if (attr == null)
                        {
                            continue;
                        }
                        mightAddIndexToAttribute(attr, collectionValue, refPersistentClass.PropertyClosureIterator);
                        var entityMeta = (EntityMeta)metas[type];


                        var declaredPersistentProperty = PropertyAndMemberInfo.PersistentInfo(type, new[] { property }).FirstOrDefault();
                        if (declaredPersistentProperty == null)
                        {
                            //pawel owerko
                            log.WarnFormat(string.Format("Cannot create '{0}' object for property '{1}'. Property not found in type '{2}'.", typeof(DeclaredPersistentProperty).Name, property.Name, type.FullName));
                            continue; //todo: Can we handle declaredPersistentProperty==null in that way ?
                        }

                        var methodInfo = declaredPersistentProperty.Member;
                        addToEntityMeta(attr, entityMeta, methodInfo);
                    }
                }
            }
        }
コード例 #3
0
 private void fillMembers(System.Type type, IEnumerable <Property> properties, IDictionary <System.Type, IEntityMeta> dicToFill)
 {
     foreach (var propInfo in PropertyAndMemberInfo.PersistentInfo(type, properties))
     {
         foreach (var attr in Attribute.GetCustomAttributes(propInfo.Member))
         {
             if (!dicToFill.ContainsKey(type))
             {
                 dicToFill[type] = new EntityMeta();
             }
             var memberAttributeToAdd = MemberAttribute(attr, type, propInfo);
             ((EntityMeta)dicToFill[type]).AddMemberMeta(propInfo.Member, memberAttributeToAdd);
         }
     }
 }
コード例 #4
0
        private void addBidirectionalInfo(IDictionary <System.Type, IEntityMeta> metas)
        {
            foreach (var type in metas.Keys)
            {
                var persistentClass = _nhibernateConfiguration.GetClassMapping(type);
                if (persistentClass == null)
                {
                    continue;
                }
                foreach (var property in persistentClass.PropertyIterator)
                {
                    //is it a collection?
                    var collectionValue = property.Value as Mapping.Collection;
                    if (collectionValue == null)
                    {
                        continue;
                    }

                    //find referenced entity name
                    var referencedEntity = MappingTools.ReferencedEntityName(property.Value);
                    if (referencedEntity == null)
                    {
                        continue;
                    }


                    var refPersistentClass = _nhibernateConfiguration.GetClassMapping(referencedEntity);
                    foreach (var refProperty in refPersistentClass.PropertyClosureIterator)
                    {
                        if (MetadataTools.IsNoneAccess(refProperty.PropertyAccessorName))
                        {
                            continue;
                        }
                        var attr = createAuditMappedByAttributeIfReferenceImmutable(collectionValue, refProperty);
                        if (attr == null)
                        {
                            continue;
                        }
                        mightAddIndexToAttribute(attr, collectionValue, refPersistentClass.PropertyClosureIterator);
                        var entityMeta = (EntityMeta)metas[type];
                        var methodInfo = PropertyAndMemberInfo.PersistentInfo(type, new[] { property }).First().Member;
                        addToEntityMeta(attr, entityMeta, methodInfo);
                    }
                }
            }
        }
コード例 #5
0
        public RevisionInfoConfigurationResult Configure(Cfg.Configuration cfg)
        {
            IRevisionInfoGenerator revisionInfoGenerator;
            string    revisionAssQName;
            XDocument revisionInfoXmlMapping = null;

            System.Type revisionInfoClass;

            var revEntityType   = nhMappedTypesWithRevisionEntityAttribute(cfg);
            var noOfRevEntities = revEntityType.Count();

            switch (noOfRevEntities)
            {
            case 0:
            {
                if (_globalCfg.IsTrackEntitiesChangedInRevisionEnabled)
                {
                    revisionInfoClass      = typeof(DefaultTrackingModifiedEntitiesRevisionEntity);
                    revisionInfoEntityName = revisionInfoClass.FullName;
                    revisionInfoGenerator  = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName,
                                                                                                      revisionInfoClass,
                                                                                                      null,
                                                                                                      revisionInfoTimestampData,
                                                                                                      isTimestampAsDate(),
                                                                                                      modifiedEntityNamesData);
                }
                else
                {
                    revisionInfoClass     = typeof(DefaultRevisionEntity);
                    revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
                                                                             null, revisionInfoTimestampData, isTimestampAsDate());
                }
                revisionAssQName       = revisionInfoClass.AssemblyQualifiedName;
                revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
                break;
            }

            case 1:
            {
                var clazz         = revEntityType.First();
                var revEntityAttr = _metaDataStore.ClassMeta <RevisionEntityAttribute>(clazz);
                var pc            = cfg.GetClassMapping(clazz);
                // Checking if custom revision entity isn't audited))
                if (_metaDataStore.ClassMeta <AuditedAttribute>(clazz) != null)
                {
                    throw new MappingException("An entity decorated with [RevisionEntity] cannot be audited!");
                }

                var propertiesPlusIdentifier = new List <Property>();
                propertiesPlusIdentifier.AddRange(pc.PropertyIterator);
                propertiesPlusIdentifier.Add(pc.IdentifierProperty);
                var persistentProperties = PropertyAndMemberInfo.PersistentInfo(clazz, propertiesPlusIdentifier);

                if (!searchForRevisionNumberCfg(persistentProperties))
                {
                    throw new MappingException("An entity decorated with [RevisionEntity] must have a field decorated " +
                                               "with [RevisionNumber]!");
                }

                if (!searchForTimestampCfg(persistentProperties))
                {
                    throw new MappingException("An entity decorated with [RevisionEntity] must have a field decorated " +
                                               "with [RevisionTimestamp]!");
                }

                var modifiedEntityNames = searchForEntityNamesCfg(persistentProperties);

                revisionInfoEntityName = pc.EntityName;
                revisionAssQName       = pc.MappedClass.AssemblyQualifiedName;

                revisionInfoClass         = pc.MappedClass;
                revisionInfoTimestampType = pc.GetProperty(revisionInfoTimestampData.Name).Type;

                if (_globalCfg.IsTrackEntitiesChangedInRevisionEnabled ||
                    modifiedEntityNames ||
                    typeof(DefaultTrackingModifiedEntitiesRevisionEntity).IsAssignableFrom(revisionInfoClass))
                {
                    // If tracking modified entities parameter is enabled, custom revision info entity is a subtype
                    // of DefaultTrackingModifiedEntitiesRevisionEntity class, or ModifiedEntityNamesAttribute annotation is used.
                    revisionInfoGenerator = new DefaultTrackingModifiedEntitiesRevisionInfoGenerator(revisionInfoEntityName,
                                                                                                     revisionInfoClass,
                                                                                                     revEntityAttr.Listener,
                                                                                                     revisionInfoTimestampData,
                                                                                                     isTimestampAsDate(),
                                                                                                     modifiedEntityNamesData);
                    _globalCfg.SetTrackEntitiesChangedInRevisionEnabled();
                }
                else
                {
                    revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
                                                                             revEntityAttr.Listener, revisionInfoTimestampData, isTimestampAsDate());
                }
                break;
            }

            default:
            {
                throw new MappingException("Only one entity may be decorated with [RevisionEntity]!");
            }
            }

            return(new RevisionInfoConfigurationResult(
                       revisionInfoGenerator,
                       revisionInfoXmlMapping,
                       new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdData.Name, revisionInfoTimestampData.Name, isTimestampAsDate(), revisionPropType),
                       generateRevisionInfoRelationMapping(revisionAssQName),
                       new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdData),
                       _globalCfg.IsTrackEntitiesChangedInRevisionEnabled ? new ModifiedEntityNamesReader(revisionInfoClass, modifiedEntityNamesData) : null,
                       revisionInfoEntityName,
                       revisionInfoClass,
                       revisionInfoTimestampData));
        }
コード例 #6
0
 public PersistentClassPropertiesSource(System.Type typ, AnnotationsMetadataReader parent)
 {
     this.parent = parent;
     DeclaredPersistentProperties = PropertyAndMemberInfo.PersistentInfo(typ, parent.pc.PropertyIterator, true);
     Class = typ;
 }