public ToOneIdMapper(IIdMapper delegat, PropertyData propertyData, String referencedEntityName, bool nonInsertableFake) { this.delegat = delegat; this.propertyData = propertyData; this.referencedEntityName = referencedEntityName; this.nonInsertableFake = nonInsertableFake; }
private void GenerateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, AbstractCollectionEvent evt, PersistentCollectionChangeWorkUnit workUnit, RelationDescription rd) { // Checking if this is enabled in configuration ... if (!verCfg.GlobalCfg.isGenerateRevisionsForCollections()) { return; } // Checking if this is not a bidirectional relation - then, a revision needs also be generated for // the other side of the relation. // relDesc can be null if this is a collection of simple values (not a relation). if (rd != null && rd.Bidirectional) { String relatedEntityName = rd.ToEntityName; IIdMapper relatedIdMapper = verCfg.EntCfg[relatedEntityName].GetIdMapper(); foreach (PersistentCollectionChangeData changeData in workUnit.getCollectionChanges()) { Object relatedObj = changeData.GetChangedElement(); object relatedId = relatedIdMapper.MapToIdFromEntity(relatedObj); verSync.AddWorkUnit(new CollectionChangeWorkUnit(evt.Session, relatedEntityName, verCfg, relatedId, relatedObj)); } } }
public AuditRevisionsAssociationQuery(AuditConfiguration auditConfiguration, IAuditReaderImplementor auditReader, IEntityAuditQuery <TEntity> parent, QueryBuilder queryBuilder, string ownerEntityName, string propertyName, JoinType joinType, string ownerAlias) { _auditConfiguration = auditConfiguration; _auditReader = auditReader; _parent = parent; _queryBuilder = queryBuilder; _joinType = joinType; _ownerAlias = ownerAlias; var relationDescription = CriteriaTools.GetRelatedEntity(auditConfiguration, ownerEntityName, propertyName); if (relationDescription == null) { throw new ArgumentException("Property " + propertyName + " of entity " + ownerEntityName + " is not a valid association for queries"); } _entityName = relationDescription.ToEntityName; _ownerAssociationIdMapper = relationDescription.IdMapper; _alias = queryBuilder.GenerateAlias(); _parameters = queryBuilder.AddParameters(_alias); _criterions = new List <IAuditCriterion>(); _associationQueries = new List <AuditRevisionsAssociationQuery <TEntity> >(); _associationQueryMap = new Dictionary <string, AuditRevisionsAssociationQuery <TEntity> >(); }
public void AddToManyNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName, IIdMapper idMapper, IPropertyMapper fakeBidirectionalRelationMapper, IPropertyMapper fakeBidirectionalRelationIndexMapper) { relations.Add(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_MANY_NOT_OWNING, toEntityName, mappedByPropertyName, idMapper, fakeBidirectionalRelationMapper, fakeBidirectionalRelationIndexMapper, true)); }
public void AddToManyNotOwningRelation(string fromPropertyName, string mappedByPropertyName, string toEntityName, IIdMapper idMapper, IPropertyMapper fakeBidirectionalRelationMapper, IPropertyMapper fakeBidirectionalRelationIndexMapper) { relations.Add(fromPropertyName, RelationDescription.ToMany(fromPropertyName, RelationType.ToManyNotOwning, toEntityName, mappedByPropertyName, idMapper, fakeBidirectionalRelationMapper, fakeBidirectionalRelationIndexMapper, true)); }
public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, String referencedEntityName, IIdMapper referencedIdMapper) { this.referencingIdData = referencingIdData; /* * The query that we need to create: * SELECT new list(e) FROM versionsReferencedEntity e * WHERE * (only entities referenced by the association; id_ref_ing = id of the referencing entity) * e.id_ref_ing = :id_ref_ing AND * (selecting e entities at revision :revision) * e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2 * WHERE e2.revision <= :revision AND e2.id = e.id) AND * (only non-deleted entities) * e.revision_type != DEL */ String revisionPropertyPath = verEntCfg.RevisionNumberPath; String originalIdPropertyName = verEntCfg.OriginalIdPropName; String versionsReferencedEntityName = verEntCfg.GetAuditEntityName(referencedEntityName); // SELECT new list(e) FROM versionsEntity e QueryBuilder qb = new QueryBuilder(versionsReferencedEntityName, "e"); qb.AddProjection("new list", "e", false, false); // WHERE Parameters rootParameters = qb.RootParameters; // e.id_ref_ed = :id_ref_ed referencingIdData.PrefixedMapper.AddNamedIdEqualsToQuery(rootParameters, null, true); // SELECT max(e.revision) FROM versionsReferencedEntity e2 QueryBuilder maxERevQb = qb.NewSubQueryBuilder(versionsReferencedEntityName, "e2"); maxERevQb.AddProjection("max", revisionPropertyPath, false); // WHERE Parameters maxERevQbParameters = maxERevQb.RootParameters; // e2.revision <= :revision maxERevQbParameters.AddWhereWithNamedParam(revisionPropertyPath, "<=", "revision"); // e2.id = e.id referencedIdMapper.AddIdsEqualToQuery(maxERevQbParameters, "e." + originalIdPropertyName, "e2." + originalIdPropertyName); // e.revision = (SELECT max(...) ...) rootParameters.AddWhere(revisionPropertyPath, false, globalCfg.getCorrelatedSubqueryOperator(), maxERevQb); // e.revision_type != DEL rootParameters.AddWhereWithNamedParam(verEntCfg.RevisionTypePropName, false, "!=", "delrevisiontype"); StringBuilder sb = new StringBuilder(); qb.Build(sb, EmptyDictionary <String, object> .Instance); queryString = sb.ToString(); }
public static RelationDescription ToOne(string fromPropertyName, RelationType relationType, string toEntityName, string mappedByPropertyName, IIdMapper idMapper, IPropertyMapper fakeBidirectionalRelationMapper, IPropertyMapper fakeBidirectionalRelationIndexMapper, bool insertable, bool ignoreNotFound) { return(new RelationDescription(fromPropertyName, relationType, toEntityName, mappedByPropertyName, idMapper, fakeBidirectionalRelationMapper, fakeBidirectionalRelationIndexMapper, insertable, ignoreNotFound)); }
public ToOneIdMapper(IIdMapper delegat, PropertyData propertyData, string referencedEntityName, bool nonInsertableFake) : base(propertyData) { _delegat = delegat; _referencedEntityName = referencedEntityName; _nonInsertableFake = nonInsertableFake; }
/// <summary> /// Applies any conventions required for the ID property. /// </summary> /// <param name="map"> The ID mapper. </param> /// <param name="property"> The ID property. </param> protected virtual void ApplyIdConventions(IIdMapper map, PropertyInfo property) { if (property.PropertyType == typeof(int) || property.PropertyType == typeof(long)) { map.Generator(Generators.HighLow, g => g.Params(new { max_lo = 100 })); } else if (property.PropertyType == typeof(Guid)) { map.Generator(Generators.GuidComb); } }
//@SuppressWarnings({"unchecked"}) public void AddToOne(XmlElement parent, PropertyAuditingData propertyAuditingData, IValue value, ICompositeMapperBuilder mapper, String entityName, bool insertable) { String referencedEntityName = ((ToOne)value).ReferencedEntityName; IdMappingData idMapping = mainGenerator.GetReferencedIdMappingData(entityName, referencedEntityName, propertyAuditingData, true); String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(propertyAuditingData.Name); // Generating the id mapper for the relation IIdMapper relMapper = idMapping.IdMapper.PrefixMappedProperties(lastPropertyPrefix); // Storing information about this relation mainGenerator.EntitiesConfigurations[entityName].AddToOneRelation( propertyAuditingData.Name, referencedEntityName, relMapper, insertable); // If the property isn't insertable, checking if this is not a "fake" bidirectional many-to-one relationship, // that is, when the one side owns the relation (and is a collection), and the many side is non insertable. // When that's the case and the user specified to store this relation without a middle table (using // @AuditMappedBy), we have to make the property insertable for the purposes of Envers. In case of changes to // the entity that didn't involve the relation, it's value will then be stored properly. In case of changes // to the entity that did involve the relation, it's the responsibility of the collection side to store the // proper data. bool nonInsertableFake; if (!insertable && propertyAuditingData.ForceInsertable) { nonInsertableFake = true; insertable = true; } else { nonInsertableFake = false; } // Adding an element to the mapping corresponding to the references entity id's // Use OwnerDocument.ImportNode() instead of XmlNode.Clone(); XmlElement properties = (XmlElement)parent.OwnerDocument.ImportNode(idMapping.XmlRelationMapping, true); properties.SetAttribute("name", propertyAuditingData.Name); MetadataTools.PrefixNamesInPropertyElement(properties, lastPropertyPrefix, MetadataTools.GetColumnNameEnumerator((IEnumerator <ISelectable>)value.ColumnIterator.GetEnumerator()), false, insertable); parent.AppendChild(properties); // Adding mapper for the id PropertyData propertyData = propertyAuditingData.getPropertyData(); mapper.AddComposite(propertyData, new ToOneIdMapper(relMapper, propertyData, referencedEntityName, nonInsertableFake)); }
public ToOneIdMapper(IEnversProxyFactory enversProxyFactory, IIdMapper delegat, PropertyData propertyData, string referencedEntityName, bool nonInsertableFake) : base(propertyData) { _enversProxyFactory = enversProxyFactory; _delegat = delegat; _referencedEntityName = referencedEntityName; _nonInsertableFake = nonInsertableFake; }
public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, String referencedEntityName, IIdMapper referencedIdMapper) { this.referencingIdData = referencingIdData; /* * The query that we need to create: * SELECT new list(e) FROM versionsReferencedEntity e * WHERE * (only entities referenced by the association; id_ref_ing = id of the referencing entity) * e.id_ref_ing = :id_ref_ing AND * (selecting e entities at revision :revision) * e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2 * WHERE e2.revision <= :revision AND e2.id = e.id) AND * (only non-deleted entities) * e.revision_type != DEL */ String revisionPropertyPath = verEntCfg.RevisionNumberPath; String originalIdPropertyName = verEntCfg.OriginalIdPropName; String versionsReferencedEntityName = verEntCfg.GetAuditEntityName(referencedEntityName); // SELECT new list(e) FROM versionsEntity e QueryBuilder qb = new QueryBuilder(versionsReferencedEntityName, "e"); qb.AddProjection("new list", "e", false, false); // WHERE Parameters rootParameters = qb.RootParameters; // e.id_ref_ed = :id_ref_ed referencingIdData.PrefixedMapper.AddNamedIdEqualsToQuery(rootParameters, null, true); // SELECT max(e.revision) FROM versionsReferencedEntity e2 QueryBuilder maxERevQb = qb.NewSubQueryBuilder(versionsReferencedEntityName, "e2"); maxERevQb.AddProjection("max", revisionPropertyPath, false); // WHERE Parameters maxERevQbParameters = maxERevQb.RootParameters; // e2.revision <= :revision maxERevQbParameters.AddWhereWithNamedParam(revisionPropertyPath, "<=", "revision"); // e2.id = e.id referencedIdMapper.AddIdsEqualToQuery(maxERevQbParameters, "e." + originalIdPropertyName, "e2." + originalIdPropertyName); // e.revision = (SELECT max(...) ...) rootParameters.AddWhere(revisionPropertyPath, false, globalCfg.getCorrelatedSubqueryOperator(), maxERevQb); // e.revision_type != DEL rootParameters.AddWhereWithNamedParam(verEntCfg.RevisionTypePropName, false, "!=", "delrevisiontype"); StringBuilder sb = new StringBuilder(); qb.Build(sb, EmptyDictionary<String, object>.Instance); queryString = sb.ToString(); }
public static RelationDescription ToMany(string fromPropertyName, RelationType relationType, string toEntityName, string mappedByPropertyName, IIdMapper idMapper, IPropertyMapper fakeBidirectionalRelationMapper, IPropertyMapper fakeBidirectionalRelationIndexMapper, bool insertable) { // Envers populates collections by executing dedicated queries. Special handling of // @NotFound(action = NotFoundAction.IGNORE) can be omitted in such case as exceptions // (e.g. EntityNotFoundException, ObjectNotFoundException) are never thrown. // Therefore assigning false to ignoreNotFound. return(new RelationDescription(fromPropertyName, relationType, toEntityName, mappedByPropertyName, idMapper, fakeBidirectionalRelationMapper, fakeBidirectionalRelationIndexMapper, insertable, false)); }
public void AddIdsEqualToQuery(Parameters parameters, string prefix1, IIdMapper mapper2, string prefix2) { var paramDatas1 = MapToQueryParametersFromId(null); var paramDatas2 = mapper2.MapToQueryParametersFromId(null); var parametersToUse = GetParametersToUse(parameters, paramDatas1); for (var i = 0; i < paramDatas1.Count; i++) { var paramData1 = paramDatas1[i]; var paramData2 = paramDatas2[i]; parametersToUse.AddWhere(paramData1.GetProperty(prefix1), false, "=", paramData2.GetProperty(prefix2), false); } }
public RelationDescription(String fromPropertyName, RelationType relationType, String toEntityName, String mappedByPropertyName, IIdMapper idMapper, IPropertyMapper fakeBidirectionalRelationMapper, IPropertyMapper fakeBidirectionalRelationIndexMapper, bool insertable) { this.FromPropertyName = fromPropertyName; this.RelationType = relationType; this.ToEntityName = toEntityName; this.MappedByPropertyName = mappedByPropertyName; this.IdMapper = idMapper; this.FakeBidirectionalRelationMapper = fakeBidirectionalRelationMapper; this.FakeBidirectionalRelationIndexMapper = fakeBidirectionalRelationIndexMapper; this.Insertable = insertable; this.Bidirectional = false; }
/** * Creates an entity instance based on an entry from the versions table. * @param entityName Name of the entity, which instances should be read * @param versionsEntity An entry in the versions table, from which data should be mapped. * @param revision Revision at which this entity was read. * @return An entity instance, with versioned properties set as in the versionsEntity map, and proxies * created for collections. */ public Object CreateInstanceFromVersionsEntity(String entityName, IDictionary <string, object> versionsEntity, long revision) { if (versionsEntity == null) { return(null); } // The $type$ property holds the name of the (versions) entity String name = verCfg.EntCfg.GetEntityNameForVersionsEntityName(((String)versionsEntity["$type$"])); if (name != null) { entityName = name; } // First mapping the primary key IIdMapper idMapper = verCfg.EntCfg[entityName].GetIdMapper(); IDictionary <string, object> originalId = DictionaryWrapper <string, object> .Wrap((IDictionary)versionsEntity[verCfg.AuditEntCfg.OriginalIdPropName]); Object primaryKey = idMapper.MapToIdFromMap(originalId); // Checking if the entity is in cache if (versionsReader.FirstLevelCache.Contains(entityName, revision, primaryKey)) { return(versionsReader.FirstLevelCache[entityName, revision, primaryKey]); } // If it is not in the cache, creating a new entity instance Object ret; try { //System.Type cls = ReflectionTools.loadClass(entityName); //ret = ReflectHelper.GetDefaultConstructor(cls).newInstance(); ret = Activator.CreateInstance(Toolz.ResolveDotnetType(entityName)); } catch (Exception e) { throw new AuditException(e); } // Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional // relation is present (which is eagerly loaded). versionsReader.FirstLevelCache.Add(entityName, revision, primaryKey, ret); verCfg.EntCfg[entityName].PropertyMapper.MapToEntityFromMap(verCfg, ret, versionsEntity, primaryKey, versionsReader, revision); idMapper.MapToEntityFromMap(ret, originalId); return(ret); }
private RelationDescription(string fromPropertyName, RelationType relationType, string toEntityName, string mappedByPropertyName, IIdMapper idMapper, IPropertyMapper fakeBidirectionalRelationMapper, IPropertyMapper fakeBidirectionalRelationIndexMapper, bool insertable, bool ignoreNotFound) { FromPropertyName = fromPropertyName; RelationType = relationType; ToEntityName = toEntityName; MappedByPropertyName = mappedByPropertyName; IdMapper = idMapper; FakeBidirectionalRelationMapper = fakeBidirectionalRelationMapper; FakeBidirectionalRelationIndexMapper = fakeBidirectionalRelationIndexMapper; Insertable = insertable; IsIgnoreNotFound = ignoreNotFound; Bidirectional = false; }
public void AddIdsEqualToQuery(Parameters parameters, String prefix1, IIdMapper mapper2, String prefix2) { IList<QueryParameterData> paramDatas1 = MapToQueryParametersFromId(null); IList<QueryParameterData> paramDatas2 = mapper2.MapToQueryParametersFromId(null); Parameters parametersToUse = GetParametersToUse(parameters, paramDatas1); IEnumerator<QueryParameterData> paramDataIter1 = paramDatas1.GetEnumerator(); IEnumerator<QueryParameterData> paramDataIter2 = paramDatas2.GetEnumerator(); while (paramDataIter1.MoveNext()) { QueryParameterData paramData1 = paramDataIter1.Current; QueryParameterData paramData2 = paramDataIter2.Current; parametersToUse.AddWhere(paramData1.getProperty(prefix1), false, "=", paramData2.getProperty(prefix2), false); } }
public void AddIdsEqualToQuery(Parameters parameters, String prefix1, IIdMapper mapper2, String prefix2) { IList <QueryParameterData> paramDatas1 = MapToQueryParametersFromId(null); IList <QueryParameterData> paramDatas2 = mapper2.MapToQueryParametersFromId(null); Parameters parametersToUse = GetParametersToUse(parameters, paramDatas1); IEnumerator <QueryParameterData> paramDataIter1 = paramDatas1.GetEnumerator(); IEnumerator <QueryParameterData> paramDataIter2 = paramDatas2.GetEnumerator(); while (paramDataIter1.MoveNext()) { QueryParameterData paramData1 = paramDataIter1.Current; QueryParameterData paramData2 = paramDataIter2.Current; parametersToUse.AddWhere(paramData1.getProperty(prefix1), false, "=", paramData2.getProperty(prefix2), false); } }
public ClassMapper(Type rootClass, HbmMapping mapDoc, MemberInfo idProperty) : base(rootClass, mapDoc) { classMapping = new HbmClass(); var toAdd = new[] { classMapping }; classMapping.name = rootClass.GetShortClassName(mapDoc); if(rootClass.IsAbstract) { classMapping.@abstract = true; classMapping.abstractSpecified = true; } var hbmId = new HbmId(); classMapping.Item = hbmId; idMapper = new IdMapper(idProperty, hbmId); mapDoc.Items = mapDoc.Items == null ? toAdd : mapDoc.Items.Concat(toAdd).ToArray(); }
public ClassMapper(System.Type rootClass, HbmMapping mapDoc, MemberInfo idProperty) : base(rootClass, mapDoc) { classMapping = new HbmClass(); classMapping.name = rootClass.GetShortClassName(mapDoc); if (rootClass.IsAbstract) { classMapping.@abstract = true; classMapping.abstractSpecified = true; } var hbmId = new HbmId(); classMapping.Item = hbmId; idMapper = new IdMapper(idProperty, hbmId); mapDoc.Items = ArrayHelper.Append(mapDoc.Items, classMapping); }
public ClassMapper(Type rootClass, HbmMapping mapDoc, MemberInfo idProperty) : base(rootClass, mapDoc) { classMapping = new HbmClass(); var toAdd = new[] { classMapping }; classMapping.name = rootClass.GetShortClassName(mapDoc); if (rootClass.IsAbstract) { classMapping.@abstract = true; classMapping.abstractSpecified = true; } var hbmId = new HbmId(); classMapping.Item = hbmId; idMapper = new IdMapper(idProperty, hbmId); mapDoc.Items = mapDoc.Items == null ? toAdd : mapDoc.Items.Concat(toAdd).ToArray(); }
private void GenerateFakeBidirecationalRelationWorkUnits(AuditSync verSync, IPersistentCollection newColl, object oldColl, String collectionEntityName, String referencingPropertyName, AbstractCollectionEvent evt, RelationDescription rd) { // First computing the relation changes IList <PersistentCollectionChangeData> collectionChanges = verCfg.EntCfg[collectionEntityName].PropertyMapper .MapCollectionChanges(referencingPropertyName, newColl, oldColl, evt.AffectedOwnerIdOrNull); // Getting the id mapper for the related entity, as the work units generated will corrspond to the related // entities. String relatedEntityName = rd.ToEntityName; IIdMapper relatedIdMapper = verCfg.EntCfg[relatedEntityName].GetIdMapper(); // For each collection change, generating the bidirectional work unit. foreach (PersistentCollectionChangeData changeData in collectionChanges) { Object relatedObj = changeData.GetChangedElement(); object relatedId = relatedIdMapper.MapToIdFromEntity(relatedObj); RevisionType revType = (RevisionType)changeData.getData()[verCfg.AuditEntCfg.RevisionTypePropName]; // This can be different from relatedEntityName, in case of inheritance (the real entity may be a subclass // of relatedEntityName). String realRelatedEntityName = evt.Session.BestGuessEntityName(relatedObj); // By default, the nested work unit is a collection change work unit. IAuditWorkUnit nestedWorkUnit = new CollectionChangeWorkUnit(evt.Session, realRelatedEntityName, verCfg, relatedId, relatedObj); verSync.AddWorkUnit(new FakeBidirectionalRelationWorkUnit(evt.Session, realRelatedEntityName, verCfg, relatedId, referencingPropertyName, evt.AffectedOwnerOrNull, rd, revType, changeData.GetChangedElementIndex(), nestedWorkUnit)); } // We also have to generate a collection change work unit for the owning entity. verSync.AddWorkUnit(new CollectionChangeWorkUnit(evt.Session, collectionEntityName, verCfg, evt.AffectedOwnerIdOrNull, evt.AffectedOwnerOrNull)); }
public void SetUp() { _classFilter = MockRepository.GenerateMock<IClassFilter>(); _classFilter .Stub(arg => arg.Matches(Arg<Type>.Is.Anything)) .WhenCalled(arg => arg.ReturnValue = (Type)arg.Arguments.First() == typeof(Endpoint)) .Return(false); _idMapper = MockRepository.GenerateMock<IIdMapper>(); _idMapper .Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)) .WhenCalled(arg => arg.ReturnValue = IdResult.IdMapped(Guid.NewGuid())) .Return(null); _nameMapper = MockRepository.GenerateMock<INameMapper>(); _nameMapper.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(NameResult.NameMapped("name")); _resolvedRelativeUrlMapper = MockRepository.GenerateMock<IResolvedRelativeUrlMapper>(); _resolvedRelativeUrlMapper.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(ResolvedRelativeUrlResult.ResolvedRelativeUrlMapped("relative")); _autoRouteCollection = new AutoRouteCollection(true) .Assemblies(Assembly.GetExecutingAssembly()) .ClassFilters(_classFilter) .NameMappers(_nameMapper) .IdMappers(_idMapper) .ResolvedRelativeUrlMappers(_resolvedRelativeUrlMapper); }
//@SuppressWarnings({"unchecked"}) public void AddOneToOneNotOwning(PropertyAuditingData propertyAuditingData, IValue value, ICompositeMapperBuilder mapper, String entityName) { OneToOne propertyValue = (OneToOne)value; String owningReferencePropertyName = propertyValue.ReferencedPropertyName; // mappedBy EntityConfiguration configuration = mainGenerator.EntitiesConfigurations[entityName]; if (configuration == null) { throw new MappingException("An audited relation to a non-audited entity " + entityName + "!"); } IdMappingData ownedIdMapping = configuration.IdMappingData; if (ownedIdMapping == null) { throw new MappingException("An audited relation to a non-audited entity " + entityName + "!"); } String lastPropertyPrefix = MappingTools.createToOneRelationPrefix(owningReferencePropertyName); String referencedEntityName = propertyValue.ReferencedEntityName; // Generating the id mapper for the relation IIdMapper ownedIdMapper = ownedIdMapping.IdMapper.PrefixMappedProperties(lastPropertyPrefix); // Storing information about this relation mainGenerator.EntitiesConfigurations[entityName].AddToOneNotOwningRelation( propertyAuditingData.Name, owningReferencePropertyName, referencedEntityName, ownedIdMapper); // Adding mapper for the id PropertyData propertyData = propertyAuditingData.getPropertyData(); mapper.AddComposite(propertyData, new OneToOneNotOwningMapper(owningReferencePropertyName, referencedEntityName, propertyData)); }
public void SetUp() { _classFilter = MockRepository.GenerateMock<IClassFilter>(); _classFilter .Stub(arg => arg.Matches(Arg<Type>.Is.Anything)) .WhenCalled(arg => arg.ReturnValue = (Type)arg.Arguments.First() == typeof(Endpoint)) .Return(false); _idMapper1 = MockRepository.GenerateMock<IIdMapper>(); _idMapper1.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(IdResult.IdMapped(Guid.Parse("1dffe3ee-1ade-4aa2-835a-9cb91b7e31c4"))); _idMapper2 = MockRepository.GenerateMock<IIdMapper>(); _idMapper2.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(IdResult.IdMapped(Guid.Parse("493e725c-cbc1-4ea4-b6d1-350018d4542d"))); _nameMapper = MockRepository.GenerateMock<INameMapper>(); _nameMapper.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(NameResult.NameMapped("name")); _resolvedRelativeUrlMapper = MockRepository.GenerateMock<IResolvedRelativeUrlMapper>(); _resolvedRelativeUrlMapper.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(ResolvedRelativeUrlResult.ResolvedRelativeUrlMapped("relative")); _responseMapper = MockRepository.GenerateMock<IResponseMapper>(); _autoRouteCollection = new AutoRouteCollection() .Assemblies(Assembly.GetExecutingAssembly()) .ClassFilters(_classFilter) .NameMappers(_nameMapper) .IdMappers(_idMapper1) .ResolvedRelativeUrlMappers(_resolvedRelativeUrlMapper) .ResponseMapper(_responseMapper); _routes = _autoRouteCollection.GenerateRouteCollection().ToArray(); }
public IdMappingData(IIdMapper idMapper, XElement xmlMapping, XElement xmlRelationMapping) { IdMapper = idMapper; XmlMapping = xmlMapping; XmlRelationMapping = xmlRelationMapping; }
public IdMappingData(IIdMapper idMapper, XmlElement xmlMapping, XmlElement xmlRelationMapping) { this.IdMapper = idMapper; this.XmlMapping = xmlMapping; this.XmlRelationMapping = xmlRelationMapping; }
public MiddleMapKeyIdComponentMapper(AuditEntitiesConfiguration verEntCfg, IIdMapper relatedIdMapper) { this.verEntCfg = verEntCfg; this.relatedIdMapper = relatedIdMapper; }
public static void Type <TPersistentType>(this IIdMapper idMapper, object parameters) { Type(idMapper, typeof(TPersistentType), parameters); }
public ProtocolBuilder UseIds(IIdHeader header, IIdMapper resolver) { _idHeader = header; _idResolver = resolver; return(this); }
public void AddToOneNotOwningRelation(String fromPropertyName, String mappedByPropertyName, String toEntityName, IIdMapper idMapper) { relations.Add(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_ONE_NOT_OWNING, toEntityName, mappedByPropertyName, idMapper, null, null, true)); }
private void ClassMappings(IIdMapper mapper) { mapper.Generator(Generators.Identity); mapper.UnsavedValue(-1); }
private void GenerateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, IEntityPersister entityPersister, String entityName, Object[] newState, Object[] oldState, ISessionImplementor session) { // Checking if this is enabled in configuration ... if (!verCfg.GlobalCfg.isGenerateRevisionsForCollections()) { return; } // Checks every property of the entity, if it is an "owned" to-one relation to another entity. // If the value of that property changed, and the relation is bi-directional, a new revision // for the related entity is generated. String[] propertyNames = entityPersister.PropertyNames; for (int i = 0; i < propertyNames.GetLength(0); i++) { String propertyName = propertyNames[i]; RelationDescription relDesc = verCfg.EntCfg.GetRelationDescription(entityName, propertyName); if (relDesc != null && relDesc.Bidirectional && relDesc.RelationType == RelationType.TO_ONE && relDesc.Insertable) { // Checking for changes Object oldValue = oldState == null ? null : oldState[i]; Object newValue = newState == null ? null : newState[i]; if (!Toolz.EntitiesEqual(session, oldValue, newValue)) { // We have to generate changes both in the old collection (size decreses) and new collection // (size increases). //<TODO Simon: doua if-uri cu cod duplicat, refact. if (newValue != null) { // relDesc.getToEntityName() doesn't always return the entity name of the value - in case // of subclasses, this will be root class, no the actual class. So it can't be used here. String toEntityName; // Java: Serializable id object id; if (newValue is INHibernateProxy) { INHibernateProxy hibernateProxy = (INHibernateProxy)newValue; toEntityName = session.BestGuessEntityName(newValue); id = hibernateProxy.HibernateLazyInitializer.Identifier; // We've got to initialize the object from the proxy to later read its state. newValue = NHibernate.Envers.Tools.Toolz.GetTargetFromProxy(session.Factory, hibernateProxy); } else { toEntityName = session.GuessEntityName(newValue); IIdMapper idMapper = verCfg.EntCfg[toEntityName].GetIdMapper(); id = idMapper.MapToIdFromEntity(newValue); } verSync.AddWorkUnit(new CollectionChangeWorkUnit(session, toEntityName, verCfg, id, newValue)); } if (oldValue != null) { String toEntityName; object id; if (oldValue is INHibernateProxy) { INHibernateProxy hibernateProxy = (INHibernateProxy)oldValue; toEntityName = session.BestGuessEntityName(oldValue); id = hibernateProxy.HibernateLazyInitializer.Identifier; // We've got to initialize the object as we'll read it's state anyway. oldValue = Toolz.GetTargetFromProxy(session.Factory, hibernateProxy); } else { toEntityName = session.GuessEntityName(oldValue); IIdMapper idMapper = verCfg.EntCfg[toEntityName].GetIdMapper(); id = idMapper.MapToIdFromEntity(oldValue); } verSync.AddWorkUnit(new CollectionChangeWorkUnit(session, toEntityName, verCfg, id, oldValue)); } } } } }
public void SetUp() { _classFilter = MockRepository.GenerateMock<IClassFilter>(); _classFilter .Stub(arg => arg.Matches(Arg<Type>.Is.Anything)) .WhenCalled(arg => arg.ReturnValue = (Type)arg.Arguments.First() == typeof(Endpoint)) .Return(false); _idMapper = MockRepository.GenerateMock<IIdMapper>(); _idMapper.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(IdResult.IdMapped(Guid.NewGuid())); _nameMapper = MockRepository.GenerateMock<INameMapper>(); _nameMapper.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(NameResult.NameMapped("name")); _resolvedRelativeUrlMapper = MockRepository.GenerateMock<IResolvedRelativeUrlMapper>(); _resolvedRelativeUrlMapper.Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything)).Return(ResolvedRelativeUrlResult.ResolvedRelativeUrlMapped("relative")); _responseMapper = MockRepository.GenerateMock<IResponseMapper>(); _restrictionMapper1 = MockRepository.GenerateMock<IRestrictionMapper>(); _restrictionMapper1 .Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything, Arg<Route.Routing.Route>.Is.Anything, Arg<IContainer>.Is.Anything)) .WhenCalled(arg => ((Route.Routing.Route)arg.Arguments.Skip(2).First()).RestrictByMethods("GET")); _restrictionMapper2 = MockRepository.GenerateMock<IRestrictionMapper>(); _restrictionMapper2 .Stub(arg => arg.Map(Arg<Type>.Is.Anything, Arg<MethodInfo>.Is.Anything, Arg<Route.Routing.Route>.Is.Anything, Arg<IContainer>.Is.Anything)) .WhenCalled(arg => ((Route.Routing.Route)arg.Arguments.Skip(2).First()).RestrictByMethods("POST")); _autoRouteCollection = new AutoRouteCollection() .Assemblies(Assembly.GetExecutingAssembly()) .ClassFilters(_classFilter) .NameMappers(_nameMapper) .IdMappers(_idMapper) .ResolvedRelativeUrlMappers(_resolvedRelativeUrlMapper) .ResponseMapper(_responseMapper) .RestrictionMappers(_restrictionMapper1, _restrictionMapper2); }
public static void Type <TPersistentType>(this IIdMapper idMapper) { Type <TPersistentType>(idMapper, null); }
public void AddToOneNotOwningRelation(string fromPropertyName, string mappedByPropertyName, string toEntityName, IIdMapper idMapper, bool ignoreNotFound) { relations.Add(fromPropertyName, RelationDescription.ToOne(fromPropertyName, RelationType.ToOneNotOwning, toEntityName, mappedByPropertyName, idMapper, null, null, true, ignoreNotFound)); }
public void AddToOneRelation(String fromPropertyName, String toEntityName, IIdMapper idMapper, bool insertable) { relations.Add(fromPropertyName, new RelationDescription(fromPropertyName, RelationType.TO_ONE, toEntityName, null, idMapper, null, null, insertable)); }
public void AddToOneRelation(string fromPropertyName, string toEntityName, IIdMapper idMapper, bool insertable, bool ignoreNotFound) { relations.Add(fromPropertyName, RelationDescription.ToOne(fromPropertyName, RelationType.ToOne, toEntityName, null, idMapper, null, null, insertable, ignoreNotFound)); }
// 6.0 TODO: move into IIdMapper, // and probably add an ITypeMapper for mutualizing it with IElementMapper and IPropertyMapper // (Note that there is no IKeyPropertyMapper to be concerned with, the KeyPropertyMapper use IPropertyMapper // directly instead.) public static void Type(this IIdMapper idMapper, System.Type persistentType, object parameters) { ReflectHelper .CastOrThrow <IdMapper>(idMapper, "Type method with a type argument") .Type(persistentType, parameters); }