Ejemplo n.º 1
0
        public void AddAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder,
														string revisionProperty,
														string revisionEndProperty,
														bool addAlias,
														MiddleIdData referencingIdData,
														string versionsMiddleEntityName,
														string eeOriginalIdPropertyPath,
														string revisionPropertyPath,
														string originalIdPropertyName,
														params MiddleComponentData[] componentDatas)
        {
            var rootParameters = rootQueryBuilder.RootParameters;

            // SELECT max(ee2.revision) FROM middleEntity ee2
            var maxEeRevQb = rootQueryBuilder.NewSubQueryBuilder(versionsMiddleEntityName, "ee2");
            maxEeRevQb.AddProjection("max", revisionPropertyPath, false);
            // WHERE
            var maxEeRevQbParameters = maxEeRevQb.RootParameters;
            // ee2.revision <= :revision
            maxEeRevQbParameters.AddWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
            // ee2.originalId.* = ee.originalId.*
            var ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;
            referencingIdData.PrefixedMapper.AddIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);

            foreach (var componentData in componentDatas)
            {
                componentData.ComponentMapper.AddMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
            }

            // add subquery to rootParameters
            rootParameters.AddWhere(revisionProperty, addAlias, "=", maxEeRevQb);
        }
 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;
 }
Ejemplo n.º 3
0
        protected override void FillResult(IList result)
        {
            /*
             * The query that we need to create:
             *   SELECT new list(e) FROM versionsReferencedEntity e
             *   WHERE
             * (all specified conditions, transformed, on the "e" entity) 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 verEntCfg = VerCfg.AuditEntCfg;
            var revisionPropertyPath = verEntCfg.RevisionNumberPath;
            var originalIdPropertyName = verEntCfg.OriginalIdPropName;

            var referencedIdData = new MiddleIdData(verEntCfg, VerCfg.EntCfg[EntityName].IdMappingData,
                    null, EntityName, VerCfg.EntCfg.IsVersioned(EntityName));

            // (selecting e entities at revision :revision)
            // --> based on auditStrategy (see above)
            VerCfg.AuditStrategy.AddEntityAtRevisionRestriction(VerCfg.GlobalCfg, QueryBuilder, revisionPropertyPath,
                    verEntCfg.RevisionEndFieldName, true, referencedIdData,
                    revisionPropertyPath, originalIdPropertyName, "e", "e2");

            // e.revision_type != DEL
            QueryBuilder.RootParameters.AddWhereWithParam(verEntCfg.RevisionTypePropName, "<>", RevisionType.Deleted);

            // all specified conditions
            foreach (var criterion in Criterions)
            {
                criterion.AddToQuery(VerCfg, EntityName, QueryBuilder, QueryBuilder.RootParameters);
            }

            var query = BuildQuery();
            // add named parameter (only used for ValidAuditTimeStrategy)
            if (query.NamedParameters.Contains("revision"))
            {
                query.SetParameter("revision", _revision);
            }

            if (HasProjection)
            {
                query.List(result);
                return;
            }
            var queryResult = new List<IDictionary>();
            query.List(queryResult);
            EntityInstantiator.AddInstancesFromVersionsEntities(EntityName, result, queryResult, _revision);
        }
Ejemplo n.º 4
0
 public CommonCollectionMapperData(AuditEntitiesConfiguration verEntCfg, string versionsMiddleEntityName,
                                   PropertyData collectionReferencingPropertyData, MiddleIdData referencingIdData,
                                   IRelationQueryGenerator queryGenerator)
 {
     VerEntCfg = verEntCfg;
     VersionsMiddleEntityName          = versionsMiddleEntityName;
     CollectionReferencingPropertyData = collectionReferencingPropertyData;
     ReferencingIdData = referencingIdData;
     QueryGenerator    = queryGenerator;
 }
        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>();
        }
Ejemplo n.º 6
0
        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>();
        }
Ejemplo n.º 7
0
        public void AddEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder, string revisionProperty, string revisionEndProperty, bool addAlias, MiddleIdData idData, string revisionPropertyPath, string originalIdPropertyName, string alias1, string alias2)
        {
            var rootParameters = rootQueryBuilder.RootParameters;

            // create a subquery builder
            // SELECT max(e.revision) FROM versionsReferencedEntity e2
            var maxERevQb = rootQueryBuilder.NewSubQueryBuilder(idData.AuditEntityName, alias2);
            maxERevQb.AddProjection("max", revisionPropertyPath, false);
            // WHERE
            var maxERevQbParameters = maxERevQb.RootParameters;
            // e2.revision <= :revision
            maxERevQbParameters.AddWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
            // e2.id_ref_ed = e.id_ref_ed
            idData.OriginalMapper.AddIdsEqualToQuery(maxERevQbParameters,
                    alias1 + "." + originalIdPropertyName, alias2 + "." + originalIdPropertyName);

            // add subquery to rootParameters
            var subqueryOperator = globalCfg.CorrelatedSubqueryOperator;
            rootParameters.AddWhere(revisionProperty, addAlias, subqueryOperator, maxERevQb);
        }
Ejemplo n.º 8
0
 public void AddRelation(MiddleIdData idData)
 {
     _idDatas.Add(idData);
 }