public SetCollectionInitializor(AuditConfiguration verCfg,
                                 IAuditReaderImplementor versionsReader,
                                 IRelationQueryGenerator queryGenerator,
                                 object primaryKey, long revision, bool removed,
                                 MiddleComponentData elementComponentData)
     : base(verCfg, versionsReader, queryGenerator, primaryKey, revision, removed)
 {
     _elementComponentData = elementComponentData;
 }
 public CommonCollectionMapperData(AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName,
                                   PropertyData collectionReferencingPropertyData, MiddleIdData referencingIdData,
                                   IRelationQueryGenerator queryGenerator) {
     this._verEntCfg = verEntCfg;
     this._versionsMiddleEntityName = versionsMiddleEntityName;
     this._collectionReferencingPropertyData = collectionReferencingPropertyData;
     this._referencingIdData = referencingIdData;
     this._queryGenerator = queryGenerator;
 }
Example #3
0
 public CommonCollectionMapperData(AuditEntitiesConfiguration verEntCfg, string versionsMiddleEntityName,
                                   PropertyData collectionReferencingPropertyData, MiddleIdData referencingIdData,
                                   IRelationQueryGenerator queryGenerator)
 {
     VerEntCfg = verEntCfg;
     VersionsMiddleEntityName          = versionsMiddleEntityName;
     CollectionReferencingPropertyData = collectionReferencingPropertyData;
     ReferencingIdData = referencingIdData;
     QueryGenerator    = queryGenerator;
 }
Example #4
0
        public AbstractCollectionInitializor(AuditConfiguration verCfg,
                                             IAuditReaderImplementor versionsReader,
                                             IRelationQueryGenerator queryGenerator,
                                             Object primaryKey, long revision)
        {
            this.versionsReader = versionsReader;
            this.queryGenerator = queryGenerator;
            this.primaryKey     = primaryKey;
            this.revision       = revision;

            entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
        }
 public SortedMapCollectionInitializor(AuditConfiguration verCfg,
                                       IAuditReaderImplementor versionsReader,
                                       IRelationQueryGenerator queryGenerator,
                                       object primaryKey,
                                       long revision,
                                       bool removed,
                                       MiddleComponentData elementComponentData,
                                       MiddleComponentData indexComponentData,
                                       IComparer <TKey> comparer)
     : base(verCfg, versionsReader, queryGenerator, primaryKey, revision, removed, elementComponentData, indexComponentData)
 {
     _comparer = comparer;
 }
 protected AbstractCollectionInitializor(AuditConfiguration verCfg,
                                         IAuditReaderImplementor versionsReader,
                                         IRelationQueryGenerator queryGenerator,
                                         object primaryKey,
                                         long revision,
                                         bool removed)
 {
     _versionsReader    = versionsReader;
     _queryGenerator    = queryGenerator;
     _primaryKey        = primaryKey;
     _removed           = removed;
     Revision           = revision;
     EntityInstantiator = new EntityInstantiator(verCfg, versionsReader);
 }
Example #7
0
 public BasicCollectionInitializor(AuditConfiguration verCfg,
                                   IAuditReaderImplementor versionsReader,
                                   IRelationQueryGenerator queryGenerator,
                                   Object primaryKey, long revision,
                                   System.Type collectionType,
                                   MiddleComponentData elementComponentData)
     : base(verCfg, versionsReader, queryGenerator, primaryKey, revision)
 {
     if (!(typeof(T).IsSubclassOf(typeof(ICollection))))
     {
         throw new NotSupportedException("Type supplied has to be derived from ICollection!");
     }
     this.collectionType       = collectionType;
     this.elementComponentData = elementComponentData;
 }
Example #8
0
        private void AddWithMiddleTable()
        {
            log.Debug("Adding audit mapping for property " + referencingEntityName + "." + propertyName +
                      ": collection with a join table.");

            // Generating the name of the middle table
            String auditMiddleTableName;
            String auditMiddleEntityName;

            if (!String.IsNullOrEmpty(propertyAuditingData.JoinTable.Name))
            {
                auditMiddleTableName  = propertyAuditingData.JoinTable.Name;
                auditMiddleEntityName = propertyAuditingData.JoinTable.Name;
            }
            else
            {
                String middleTableName = GetMiddleTableName(propertyValue, referencingEntityName);
                auditMiddleTableName  = mainGenerator.VerEntCfg.GetAuditTableName(null, middleTableName);
                auditMiddleEntityName = mainGenerator.VerEntCfg.GetAuditEntityName(middleTableName);
            }

            log.Debug("Using join table name: " + auditMiddleTableName);

            // Generating the XML mapping for the middle entity, only if the relation isn't inverse.
            // If the relation is inverse, will be later checked by comparing middleEntityXml with null.
            XmlElement middleEntityXml;

            if (!propertyValue.IsInverse)
            {
                // Generating a unique middle entity name
                auditMiddleEntityName = mainGenerator.AuditEntityNameRegister.createUnique(auditMiddleEntityName);

                // Registering the generated name
                mainGenerator.AuditEntityNameRegister.register(auditMiddleEntityName);

                middleEntityXml = CreateMiddleEntityXml(auditMiddleTableName, auditMiddleEntityName, propertyValue.Where);
            }
            else
            {
                middleEntityXml = null;
            }

            // ******
            // Generating the mapping for the referencing entity (it must be an entity).
            // ******
            // Getting the id-mapping data of the referencing entity (the entity that "owns" this collection).
            IdMappingData referencingIdMapping = referencingEntityConfiguration.IdMappingData;

            // Only valid for an inverse relation; null otherwise.
            String mappedBy;

            // The referencing prefix is always for a related entity. So it has always the "_" at the end added.
            String referencingPrefixRelated;
            String referencedPrefix;

            if (propertyValue.IsInverse)
            {
                // If the relation is inverse, then referencedEntityName is not null.
                mappedBy = GetMappedBy(propertyValue.CollectionTable, mainGenerator.Cfg.GetClassMapping(referencedEntityName));

                referencingPrefixRelated = mappedBy + "_";
                referencedPrefix         = StringTools.GetLastComponent(referencedEntityName);
            }
            else
            {
                mappedBy = null;

                referencingPrefixRelated = StringTools.GetLastComponent(referencingEntityName) + "_";
                referencedPrefix         = referencedEntityName == null ? "element" : propertyName;
            }

            // Storing the id data of the referencing entity: original mapper, prefixed mapper and entity name.
            MiddleIdData referencingIdData = CreateMiddleIdData(referencingIdMapping,
                                                                referencingPrefixRelated, referencingEntityName);

            // Creating a query generator builder, to which additional id data will be added, in case this collection
            // references some entities (either from the element or index). At the end, this will be used to build
            // a query generator to read the raw data collection from the middle table.
            QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder(mainGenerator.GlobalCfg,
                                                                                    mainGenerator.VerEntCfg, referencingIdData, auditMiddleEntityName);

            // Adding the XML mapping for the referencing entity, if the relation isn't inverse.
            if (middleEntityXml != null)
            {
                // Adding related-entity (in this case: the referencing's entity id) id mapping to the xml.
                AddRelatedToXmlMapping(middleEntityXml, referencingPrefixRelated,
                                       MetadataTools.GetColumnNameEnumerator(propertyValue.Key.ColumnIterator.GetEnumerator()),
                                       referencingIdMapping);
            }

            // ******
            // Generating the element mapping.
            // ******
            MiddleComponentData elementComponentData = AddValueToMiddleTable(propertyValue.Element, middleEntityXml,
                                                                             queryGeneratorBuilder, referencedPrefix, propertyAuditingData.JoinTable.InverseJoinColumns);

            // ******
            // Generating the index mapping, if an index exists.
            // ******
            MiddleComponentData indexComponentData = AddIndex(middleEntityXml, queryGeneratorBuilder);

            // ******
            // Generating the property mapper.
            // ******
            // Building the query generator.
            IRelationQueryGenerator queryGenerator = queryGeneratorBuilder.Build(new Collection <MiddleComponentData> {
                elementComponentData, indexComponentData
            });

            // Creating common data
            CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
                mainGenerator.VerEntCfg, auditMiddleEntityName,
                propertyAuditingData.getPropertyData(),
                referencingIdData, queryGenerator);

            // Checking the type of the collection and adding an appropriate mapper.
            AddMapper(commonCollectionMapperData, elementComponentData, indexComponentData);

            // ******
            // Storing information about this relation.
            // ******
            StoreMiddleEntityRelationInformation(mappedBy);
        }