public BasicCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type collectionType, System.Type proxyType, MiddleComponentData elementComponentData) : base(commonCollectionMapperData, collectionType, proxyType) { this.elementComponentData = elementComponentData; }
public IdBagCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, MiddleComponentData elementComponentData, bool revisionTypeInId) : base(commonCollectionMapperData, proxyType, elementComponentData, revisionTypeInId) { }
protected AbstractCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, bool ordinalInId, bool revisionTypeInId) { CommonCollectionMapperData = commonCollectionMapperData; _proxyType = proxyType; _ordinalInId = ordinalInId; _revisionTypeInId = revisionTypeInId; }
public IdBagCollectionMapper(IEnversProxyFactory enversProxyFactory, CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, MiddleComponentData elementComponentData, bool revisionTypeInId) : base(enversProxyFactory, commonCollectionMapperData, proxyType, elementComponentData, revisionTypeInId) { }
public SetCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, MiddleComponentData elementComponentData, bool ordinalInId, bool revisionTypeInId) : base(commonCollectionMapperData, proxyType, ordinalInId, revisionTypeInId) { ElementComponentData = elementComponentData; }
public SortedMapCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, IComparer <TKey> comparer, bool revisionTypeInId) : base(commonCollectionMapperData, proxyType, elementComponentData, indexComponentData, revisionTypeInId) { _comparer = comparer; }
public MapCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, bool revisionTypeInId) : base(commonCollectionMapperData, proxyType, false, revisionTypeInId) { ElementComponentData = elementComponentData; IndexComponentData = indexComponentData; }
protected AbstractCollectionMapper(IEnversProxyFactory enversProxyFactory, CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, bool ordinalInId, bool revisionTypeInId) { CommonCollectionMapperData = commonCollectionMapperData; _enversProxyFactory = enversProxyFactory; _proxyType = proxyType; _ordinalInId = ordinalInId; _revisionTypeInId = revisionTypeInId; }
public SortedSetCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, MiddleComponentData elementComponentData, IComparer <T> comparer, bool ordinalInId, bool revisionTypeInId) : base(commonCollectionMapperData, proxyType, elementComponentData, ordinalInId, revisionTypeInId) { _comparer = comparer; }
public ListCollectionMapper(IEnversProxyFactory enversProxyFactory, CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType, MiddleComponentData elementComponentData, MiddleComponentData indexComponentData, bool revisionTypeInId) : base(enversProxyFactory, commonCollectionMapperData, proxyType, false, revisionTypeInId) { _elementComponentData = elementComponentData; _indexComponentData = indexComponentData; }
protected AbstractCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type collectionType, System.Type proxyType) { this.commonCollectionMapperData = commonCollectionMapperData; this.collectionType = collectionType; try { proxyConstructor = proxyType.GetConstructor(new System.Type[] { typeof(IInitializor <>) }); } catch (ArgumentException e) { throw new AuditException(e); } }
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); }
private void AddOneToManyAttached(bool fakeOneToManyBidirectional) { //throw new NotImplementedException(); log.Debug("Adding audit mapping for property " + referencingEntityName + "." + propertyName + ": one-to-many collection, using a join column on the referenced entity."); String mappedBy = GetMappedBy(propertyValue); IdMappingData referencedIdMapping = mainGenerator.GetReferencedIdMappingData(referencingEntityName, referencedEntityName, propertyAuditingData, false); IdMappingData referencingIdMapping = referencingEntityConfiguration.IdMappingData; // Generating the id mappers data for the referencing side of the relation. MiddleIdData referencingIdData = CreateMiddleIdData(referencingIdMapping, mappedBy + "_", referencingEntityName); // And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted // in a join table, so the prefix value is arbitrary). MiddleIdData referencedIdData = CreateMiddleIdData(referencedIdMapping, null, referencedEntityName); // Generating the element mapping. MiddleComponentData elementComponentData = new MiddleComponentData( new MiddleRelatedComponentMapper(referencedIdData), 0); // Generating the index mapping, if an index exists. It can only exists in case a javax.persistence.MapKey // annotation is present on the entity. So the middleEntityXml will be not be used. The queryGeneratorBuilder // will only be checked for nullnes. MiddleComponentData indexComponentData = AddIndex(null, null); // Generating the query generator - it should read directly from the related entity. IRelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator(mainGenerator.GlobalCfg, mainGenerator.VerEntCfg, referencingIdData, referencedEntityName, referencedIdMapping.IdMapper); // Creating common mapper data. CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData( mainGenerator.VerEntCfg, referencedEntityName, propertyAuditingData.getPropertyData(), referencingIdData, queryGenerator); IPropertyMapper fakeBidirectionalRelationMapper; IPropertyMapper fakeBidirectionalRelationIndexMapper; if (fakeOneToManyBidirectional) { // In case of a fake many-to-one bidirectional relation, we have to generate a mapper which maps // the mapped-by property name to the id of the related entity (which is the owner of the collection). String auditMappedBy = propertyAuditingData.AuditMappedBy; // Creating a prefixed relation mapper. IIdMapper relMapper = referencingIdMapping.IdMapper.PrefixMappedProperties( MappingTools.createToOneRelationPrefix(auditMappedBy)); fakeBidirectionalRelationMapper = new ToOneIdMapper( relMapper, // The mapper will only be used to map from entity to map, so no need to provide other details // when constructing the PropertyData. new PropertyData(auditMappedBy, null, null, ModificationStore._NULL), referencedEntityName, false); // Checking if there's an index defined. If so, adding a mapper for it. if (propertyAuditingData.PositionMappedBy != null) { String positionMappedBy = propertyAuditingData.PositionMappedBy; fakeBidirectionalRelationIndexMapper = new SinglePropertyMapper(new PropertyData(positionMappedBy, null, null, ModificationStore._NULL)); // Also, overwriting the index component data to properly read the index. indexComponentData = new MiddleComponentData(new MiddleStraightComponentMapper(positionMappedBy), 0); } else { fakeBidirectionalRelationIndexMapper = null; } } else { fakeBidirectionalRelationMapper = null; fakeBidirectionalRelationIndexMapper = null; } // Checking the type of the collection and adding an appropriate mapper. AddMapper(commonCollectionMapperData, elementComponentData, indexComponentData); // Storing information about this relation. referencingEntityConfiguration.AddToManyNotOwningRelation(propertyName, mappedBy, referencedEntityName, referencingIdData.PrefixedMapper, fakeBidirectionalRelationMapper, fakeBidirectionalRelationIndexMapper); }
private void AddMapper(CommonCollectionMapperData commonCollectionMapperData, MiddleComponentData elementComponentData, MiddleComponentData indexComponentData) { IType type = propertyValue.Type; if (type is SortedSetType) { currentMapper.AddComposite(propertyAuditingData.getPropertyData(), new BasicCollectionMapper<IDictionary>(commonCollectionMapperData, typeof(TreeSet<>), typeof(SortedSetProxy<>), elementComponentData)); } else if (type is SetType) { currentMapper.AddComposite(propertyAuditingData.getPropertyData(), new BasicCollectionMapper<Set>(commonCollectionMapperData, typeof(HashedSet<>), typeof(SetProxy<>), elementComponentData)); } else throw new NotImplementedException(); //else if (type is SortedMapType) { // // Indexed collection, so <code>indexComponentData</code> is not null. // currentMapper.addComposite(propertyAuditingData.getPropertyData(), // new MapCollectionMapper<Map>(commonCollectionMapperData, // TreeMap.class, SortedMapProxy.class, elementComponentData, indexComponentData)); //} else if (type is MapType) { // // Indexed collection, so <code>indexComponentData</code> is not null. // currentMapper.addComposite(propertyAuditingData.getPropertyData(), // new MapCollectionMapper<Map>(commonCollectionMapperData, // HashMap.class, MapProxy.class, elementComponentData, indexComponentData)); //} else if (type is BagType) { // currentMapper.addComposite(propertyAuditingData.getPropertyData(), // new BasicCollectionMapper<List>(commonCollectionMapperData, // ArrayList.class, ListProxy.class, elementComponentData)); //} else if (type is ListType) { // // Indexed collection, so <code>indexComponentData</code> is not null. // currentMapper.addComposite(propertyAuditingData.getPropertyData(), // new ListCollectionMapper(commonCollectionMapperData, // elementComponentData, indexComponentData)); //} else { // mainGenerator.ThrowUnsupportedTypeException(type, referencingEntityName, propertyName); //} }
protected AbstractCollectionMapper(CommonCollectionMapperData commonCollectionMapperData, System.Type proxyType) { CommonCollectionMapperData = commonCollectionMapperData; _proxyType = proxyType; }