public void VerifyAuditEntitySchemaAndCatalogName()
        {
            var table = configuration.GetClassMapping(assemblyName + ".Entities.StrTestEntity_AUD").Table;

            table.Schema
            .Should().Be.EqualTo(enversSchema);
            table.Catalog
            .Should().Be.EqualTo(enversCatalog);
        }
        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);
                    }
                }
            }
        }
 private void throwIfUsingNonMappedRevisionEntity(Cfg.Configuration nhConfiguration)
 {
     foreach (var revAttr in attributeFactories.OfType <FluentRevision>()
              .Where(revAttr => nhConfiguration.GetClassMapping(revAttr.RevisionEntityType) == null))
     {
         throw new MappingException("Custom revision entity " + revAttr.RevisionEntityType + " must be mapped!");
     }
 }
Esempio n. 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);
                    }
                }
            }
        }
Esempio n. 5
0
        public IEnumerable <MemberInfoAndAttribute> Attributes(Cfg.Configuration nhConfiguration)
        {
            if (nhConfiguration.GetClassMapping(RevisionEntityType) == null)
            {
                throw new FluentException("Revision entity " + RevisionEntityType.FullName + " must be mapped!");
            }
            var ret = new List <MemberInfoAndAttribute>
            {
                new MemberInfoAndAttribute(RevisionEntityType, new RevisionEntityAttribute {
                    Listener = _revisionListener
                }),
                new MemberInfoAndAttribute(RevisionEntityType, _number, new RevisionNumberAttribute()),
                new MemberInfoAndAttribute(RevisionEntityType, _timestamp, new RevisionTimestampAttribute())
            };

            if (_modifiedEntityNames != null)
            {
                ret.Add(new MemberInfoAndAttribute(RevisionEntityType, _modifiedEntityNames, new ModifiedEntityNamesAttribute()));
            }
            return(ret);
        }
        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));
        }
        public void ShouldBeOnCorrectSchema()
        {
            var table = configuration.GetClassMapping(typeof(Concrete).FullName + "_AUD").Table;

            table.Schema.Should().Be.EqualTo(enversSchema);
        }
Esempio n. 8
0
 public PersistentClass GetValue(string entityName)
 {
     return(cfg.GetClassMapping(entityName));
 }