Exemple #1
0
 public BasicCollectionMapper(CommonCollectionMapperData commonCollectionMapperData,
                              System.Type collectionType, System.Type proxyType,
                              MiddleComponentData elementComponentData)
     : base(commonCollectionMapperData, collectionType, proxyType)
 {
     this.elementComponentData = elementComponentData;
 }
Exemple #2
0
 public IdBagCollectionMapper(CommonCollectionMapperData commonCollectionMapperData,
                              System.Type proxyType,
                              MiddleComponentData elementComponentData,
                              bool revisionTypeInId)
     : base(commonCollectionMapperData, proxyType, elementComponentData, revisionTypeInId)
 {
 }
Exemple #3
0
 public IdBagCollectionMapper(IEnversProxyFactory enversProxyFactory,
                              CommonCollectionMapperData commonCollectionMapperData,
                              System.Type proxyType,
                              MiddleComponentData elementComponentData,
                              bool revisionTypeInId)
     : base(enversProxyFactory, commonCollectionMapperData, proxyType, elementComponentData, revisionTypeInId)
 {
 }
Exemple #4
0
 public SetCollectionMapper(CommonCollectionMapperData commonCollectionMapperData,
                            System.Type proxyType,
                            MiddleComponentData elementComponentData,
                            bool ordinalInId,
                            bool revisionTypeInId)
     : base(commonCollectionMapperData, proxyType, ordinalInId, revisionTypeInId)
 {
     ElementComponentData = elementComponentData;
 }
Exemple #5
0
 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;
 }
 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;
 }
        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);
     //}
 }