public OneAuditEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg, IAuditStrategy auditStrategy, MiddleIdData referencingIdData, string referencedEntityName, MiddleIdData referencedIdData, bool revisionTypeInId) : base(verEntCfg, referencingIdData, revisionTypeInId) { /* * The valid 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) * --> for DefaultAuditStrategy: * e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2 * WHERE e2.revision <= :revision AND e2.id = e.id) * --> for ValidityAuditStrategy * e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null) * AND * (only non-deleted entities) * e.revision_type != DEL */ var commonPart = commonQueryPart(verEntCfg.GetAuditEntityName(referencedEntityName)); var validQuery = (QueryBuilder)commonPart.Clone(); var removedQuery = (QueryBuilder)commonPart.Clone(); createValidDataRestrictions(auditStrategy, referencedIdData, validQuery, validQuery.RootParameters); createValidAndRemovedDataRestrictions(auditStrategy, referencedIdData, removedQuery); _queryString = QueryToString(validQuery); _queryRemovedString = QueryToString(removedQuery); }
public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg, IAuditStrategy auditStrategy, string versionsMiddleEntityName, MiddleIdData referencingIdData, bool revisionTypeInId, IEnumerable <MiddleComponentData> componentDatas) : base(verEntCfg, referencingIdData, revisionTypeInId) { /* * The query that we need to create: * SELECT new list(ee) FROM middleEntity ee WHERE * (only entities referenced by the association; id_ref_ing = id of the referencing entity) * ee.originalId.id_ref_ing = :id_ref_ing AND * (the association at revision :revision) * --> for DefaultAuditStrategy: * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2 * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) * --> for ValidityAuditStrategy * ee.revision <= :revision and (ee.endRevision > :revision or ee.endRevision is null) * AND * (only non-deleted entities and associations) * ee.revision_type != DEL */ var commonPart = commonQueryPart(versionsMiddleEntityName); var validQuery = (QueryBuilder)commonPart.Clone(); var removedQuery = (QueryBuilder)commonPart.Clone(); createValidDataRestrictions(auditStrategy, versionsMiddleEntityName, validQuery, validQuery.RootParameters, true, componentDatas); createValidAndRemovedDataRestrictions(auditStrategy, versionsMiddleEntityName, removedQuery, componentDatas); _queryString = QueryToString(validQuery); _queryRemovedString = QueryToString(removedQuery); }
public MiddleIdData(AuditEntitiesConfiguration verEntCfg, IdMappingData mappingData, string prefix, string entityName, bool audited) { OriginalMapper = mappingData.IdMapper; PrefixedMapper = mappingData.IdMapper.PrefixMappedProperties(prefix); EntityName = entityName; AuditEntityName = audited ? verEntCfg.GetAuditEntityName(entityName) : null; }
protected AbstractRelationQueryGenerator(AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, bool revisionTypeInId) { VerEntCfg = verEntCfg; ReferencingIdData = referencingIdData; _revisionTypeInId = revisionTypeInId; }
public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, MiddleIdData referencingIdData, IEnumerable <MiddleComponentData> componentDatas) { this._referencingIdData = referencingIdData; /* * The query that we need to create: * SELECT new list(ee) FROM middleEntity ee WHERE * (only entities referenced by the association; id_ref_ing = id of the referencing entity) * ee.originalId.id_ref_ing = :id_ref_ing AND * (the association at revision :revision) * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2 * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND * (only non-deleted entities and associations) * ee.revision_type != DEL */ String revisionPropertyPath = verEntCfg.RevisionNumberPath; String originalIdPropertyName = verEntCfg.OriginalIdPropName; // SELECT new list(ee) FROM middleEntity ee QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee"); qb.AddProjection("new list", "ee", false, false); // WHERE Parameters rootParameters = qb.RootParameters; // ee.originalId.id_ref_ing = :id_ref_ing referencingIdData.PrefixedMapper.AddNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true); // SELECT max(ee2.revision) FROM middleEntity ee2 QueryBuilder maxRevQb = qb.NewSubQueryBuilder(versionsMiddleEntityName, "ee2"); maxRevQb.AddProjection("max", revisionPropertyPath, false); // WHERE Parameters maxRevQbParameters = maxRevQb.RootParameters; // ee2.revision <= :revision maxRevQbParameters.AddWhereWithNamedParam(revisionPropertyPath, "<=", "revision"); // ee2.originalId.* = ee.originalId.* String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName; String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName; referencingIdData.PrefixedMapper.AddIdsEqualToQuery(maxRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath); foreach (MiddleComponentData componentData in componentDatas) { componentData.ComponentMapper.AddMiddleEqualToQuery(maxRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath); } // ee.revision = (SELECT max(...) ...) rootParameters.AddWhere(revisionPropertyPath, "=", maxRevQb); // ee.revision_type != DEL rootParameters.AddWhereWithNamedParam(verEntCfg.RevisionTypePropName, "!=", "delrevisiontype"); StringBuilder sb = new StringBuilder(); qb.Build(sb, EmptyDictionary <String, object> .Instance); _queryString = sb.ToString(); }
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 QueryGeneratorBuilder(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, String auditMiddleEntityName) { this._globalCfg = globalCfg; this._verEntCfg = verEntCfg; this._referencingIdData = referencingIdData; this._auditMiddleEntityName = auditMiddleEntityName; _idDatas = new List<MiddleIdData>(); }
public QueryGeneratorBuilder(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData, String auditMiddleEntityName) { this._globalCfg = globalCfg; this._verEntCfg = verEntCfg; this._referencingIdData = referencingIdData; this._auditMiddleEntityName = auditMiddleEntityName; _idDatas = new List <MiddleIdData>(); }
public CommonCollectionMapperData(AuditEntitiesConfiguration verEntCfg, string versionsMiddleEntityName, PropertyData collectionReferencingPropertyData, MiddleIdData referencingIdData, IRelationQueryGenerator queryGenerator) { VerEntCfg = verEntCfg; VersionsMiddleEntityName = versionsMiddleEntityName; CollectionReferencingPropertyData = collectionReferencingPropertyData; ReferencingIdData = referencingIdData; QueryGenerator = queryGenerator; }
public TwoEntityOneAuditedQueryGenerator( AuditEntitiesConfiguration verEntCfg, String versionsMiddleEntityName, MiddleIdData referencingIdData, MiddleIdData referencedIdData, IEnumerable <MiddleComponentData> componentDatas) { this.referencingIdData = referencingIdData; /* * The query that we need to create: * SELECT new list(ee, e) FROM referencedEntity e, middleEntity ee * WHERE * (entities referenced by the middle table; id_ref_ed = id of the referenced entity) * ee.id_ref_ed = e.id_ref_ed AND * (only entities referenced by the association; id_ref_ing = id of the referencing entity) * ee.id_ref_ing = :id_ref_ing AND * (the association at revision :revision) * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2 * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND * (only non-deleted entities and associations) * ee.revision_type != DEL */ String revisionPropertyPath = verEntCfg.RevisionNumberPath; String originalIdPropertyName = verEntCfg.OriginalIdPropName; String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName; // SELECT new list(ee) FROM middleEntity ee QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee"); qb.AddFrom(referencedIdData.EntityName, "e"); qb.AddProjection("new list", "ee, e", false, false); // WHERE Parameters rootParameters = qb.RootParameters; // ee.id_ref_ed = e.id_ref_ed referencedIdData.PrefixedMapper.AddIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath, referencedIdData.OriginalMapper, "e"); // ee.originalId.id_ref_ing = :id_ref_ing referencingIdData.PrefixedMapper.AddNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true); // ee.revision = (SELECT max(...) ...) QueryGeneratorTools.AddAssociationAtRevision(qb, rootParameters, referencingIdData, versionsMiddleEntityName, eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas); // ee.revision_type != DEL rootParameters.AddWhereWithNamedParam(verEntCfg.RevisionTypePropName, "!=", "delrevisiontype"); StringBuilder sb = new StringBuilder(); qb.Build(sb, EmptyDictionary <String, Object> .Instance); queryString = sb.ToString(); }
public QueryGeneratorBuilder(AuditEntitiesConfiguration verEntCfg, IAuditStrategy auditStrategy, MiddleIdData referencingIdData, string auditMiddleEntityName, bool revisionTypeInId) { _verEntCfg = verEntCfg; _auditStrategy = auditStrategy; _referencingIdData = referencingIdData; _auditMiddleEntityName = auditMiddleEntityName; _revisionTypeInId = revisionTypeInId; _idDatas = new List <MiddleIdData>(); }
public QueryGeneratorBuilder(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, IAuditStrategy auditStrategy, MiddleIdData referencingIdData, string auditMiddleEntityName) { _globalCfg = globalCfg; _verEntCfg = verEntCfg; _auditStrategy = auditStrategy; _referencingIdData = referencingIdData; _auditMiddleEntityName = auditMiddleEntityName; _idDatas = new List<MiddleIdData>(); }
protected void FillDataWithId(IDictionary <String, Object> data, Object revision, RevisionType revisionType) { AuditEntitiesConfiguration entitiesCfg = verCfg.AuditEntCfg; IDictionary <String, Object> originalId = new Dictionary <String, Object>(); originalId.Add(entitiesCfg.RevisionFieldName, revision); verCfg.EntCfg[EntityName].GetIdMapper().MapToMapFromId(originalId, EntityId); data.Add(entitiesCfg.RevisionTypePropName, revisionType.Representation); data.Add(entitiesCfg.OriginalIdPropName, originalId); }
// TODO Simon @SuppressWarnings({"unchecked"}) public void perform(ISession session, Object revisionData) { AuditEntitiesConfiguration entitiesCfg = verCfg.AuditEntCfg; foreach (PersistentCollectionChangeData persistentCollectionChangeData in collectionChanges) { // Setting the revision number ((IDictionary <String, Object>)persistentCollectionChangeData.getData()[entitiesCfg.OriginalIdPropName]) .Add(entitiesCfg.RevisionFieldName, revisionData); session.Save(persistentCollectionChangeData.EntityName, persistentCollectionChangeData.getData()); } }
public MiddleIdData(AuditEntitiesConfiguration verEntCfg, IdMappingData mappingData, Property mappedByProperty, string entityName, bool audited) { OriginalMapper = mappingData.IdMapper; if (mappedByProperty.Type.IsAssociationType) { PrefixedMapper = mappingData.IdMapper.PrefixMappedProperties(mappedByProperty.Name + MappingTools.RelationCharacter); } else { var singleIdMapper = mappingData.IdMapper as SingleIdMapper; PrefixedMapper = singleIdMapper.SetName("LegOrSectorID"); // HACK } EntityName = entityName; AuditEntityName = audited ? verEntCfg.GetAuditEntityName(entityName) : null; }
private long GetRevisionNumber(IDictionary <string, object> versionsEntity) { AuditEntitiesConfiguration verEntCfg = verCfg.AuditEntCfg; String originalId = verEntCfg.OriginalIdPropName; String revisionPropertyName = verEntCfg.RevisionFieldName; Object revisionInfoObject = ((IDictionary)versionsEntity[originalId])[revisionPropertyName]; if (revisionInfoObject is INHibernateProxy) { return((long)((INHibernateProxy)revisionInfoObject).HibernateLazyInitializer.Identifier); } else { // Not a proxy - must be read from cache or with a join return(verCfg.RevisionInfoNumberReader.getRevisionNumber(revisionInfoObject)); } }
public AuditMetadataGenerator(IMetaDataStore metaDataStore, Cfg.Configuration cfg, GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, XElement revisionInfoRelationMapping, AuditEntityNameRegister auditEntityNameRegister) { Cfg = cfg; GlobalCfg = globalCfg; VerEntCfg = verEntCfg; _metaDataStore = metaDataStore; this.revisionInfoRelationMapping = revisionInfoRelationMapping; BasicMetadataGenerator = new BasicMetadataGenerator(); componentMetadataGenerator = new ComponentMetadataGenerator(this); idMetadataGenerator = new IdMetadataGenerator(this); toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this); AuditEntityNameRegister = auditEntityNameRegister; EntitiesConfigurations = new Dictionary <string, EntityConfiguration>(); NotAuditedEntitiesConfigurations = new Dictionary <string, EntityConfiguration>(); entitiesJoins = new Dictionary <string, IDictionary <Join, XElement> >(); }
public AuditMetadataGenerator(Cfg.Configuration cfg, GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, IAuditStrategy auditStrategy, XmlElement revisionInfoRelationMapping, AuditEntityNameRegister auditEntityNameRegister) { Cfg = cfg; GlobalCfg = globalCfg; VerEntCfg = verEntCfg; AuditStrategy = auditStrategy; this.revisionInfoRelationMapping = revisionInfoRelationMapping; BasicMetadataGenerator = new BasicMetadataGenerator(); componentMetadataGenerator = new ComponentMetadataGenerator(this); idMetadataGenerator = new IdMetadataGenerator(this); toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this); AuditEntityNameRegister = auditEntityNameRegister; EntitiesConfigurations = new Dictionary<string, EntityConfiguration>(); NotAuditedEntitiesConfigurations = new Dictionary<string, EntityConfiguration>(); entitiesJoins = new Dictionary<string, IDictionary<Join, XmlElement>>(); }
public AuditMetadataGenerator(Cfg.Configuration cfg, GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, XmlElement revisionInfoRelationMapping, AuditEntityNameRegister auditEntityNameRegister, ClassesAuditingData classesAuditingData) { this.Cfg = cfg; this.GlobalCfg = globalCfg; this.VerEntCfg = verEntCfg; this.revisionInfoRelationMapping = revisionInfoRelationMapping; this.BasicMetadataGenerator = new BasicMetadataGenerator(); this.componentMetadataGenerator = new ComponentMetadataGenerator(this); this.idMetadataGenerator = new IdMetadataGenerator(this); this.toOneRelationMetadataGenerator = new ToOneRelationMetadataGenerator(this); this.AuditEntityNameRegister = auditEntityNameRegister; this.ClassesAuditingData = classesAuditingData; EntitiesConfigurations = new Dictionary<String, EntityConfiguration>(); NotAuditedEntitiesConfigurations = new Dictionary<String, EntityConfiguration>(); entitiesJoins = new Dictionary<String, IDictionary<Join, XmlElement>>(); }
public MiddleMapKeyIdComponentMapper(AuditEntitiesConfiguration verEntCfg, IIdMapper relatedIdMapper) { _verEntCfg = verEntCfg; _relatedIdMapper = relatedIdMapper; }
public MiddleSimpleComponentMapper(AuditEntitiesConfiguration verEntCfg, String propertyName) { this.propertyName = propertyName; this.verEntCfg = verEntCfg; }