private void createValidDataRestrictions(IAuditStrategy auditStrategy, MiddleIdData referencedIdData,
                                                 String versionsMiddleEntityName, QueryBuilder qb, Parameters rootParameters,
                                                 bool inclusive, IEnumerable <MiddleComponentData> componentData)
        {
            var revisionPropertyPath     = VerEntCfg.RevisionNumberPath;
            var originalIdPropertyName   = VerEntCfg.OriginalIdPropName;
            var eeOriginalIdPropertyPath = QueryConstants.MiddleEntityAlias + "." + originalIdPropertyName;
            var revisionTypePropName     = RevisionTypePath();

            // (selecting e entities at revision :revision)
            // --> based on auditStrategy (see above)
            auditStrategy.AddEntityAtRevisionRestriction(qb, rootParameters,
                                                         QueryConstants.ReferencedEntityAlias + "." + revisionPropertyPath,
                                                         QueryConstants.ReferencedEntityAlias + "." +
                                                         VerEntCfg.RevisionEndFieldName, false,
                                                         referencedIdData, revisionPropertyPath, originalIdPropertyName,
                                                         QueryConstants.ReferencedEntityAlias,
                                                         QueryConstants.ReferencedEntityAliasDefAudStr);

            // (with ee association at revision :revision)
            // --> based on auditStrategy (see above)
            auditStrategy.AddAssociationAtRevisionRestriction(qb, rootParameters, revisionPropertyPath,
                                                              VerEntCfg.RevisionEndFieldName, true, ReferencingIdData,
                                                              versionsMiddleEntityName,
                                                              eeOriginalIdPropertyPath, revisionPropertyPath,
                                                              originalIdPropertyName, QueryConstants.MiddleEntityAlias, inclusive,
                                                              componentData.ToArray());
            // ee.revision_type != DEL
            rootParameters.AddWhereWithNamedParam(revisionTypePropName, "!=", QueryConstants.DelRevisionTypeParameter);
            // e.revision_type != DEL
            rootParameters.AddWhereWithNamedParam(QueryConstants.ReferencedEntityAlias + "." + revisionTypePropName, false, "!=", QueryConstants.DelRevisionTypeParameter);
        }
예제 #2
0
        public static void AddAssociationAtRevision(QueryBuilder qb, Parameters rootParameters,
                                                    MiddleIdData referencingIdData, String versionsMiddleEntityName,
                                                    String eeOriginalIdPropertyPath, String revisionPropertyPath,
                                                    String originalIdPropertyName, IEnumerable <MiddleComponentData> componentDatas)
        {
            // SELECT max(ee2.revision) FROM middleEntity ee2
            QueryBuilder maxEeRevQb = qb.NewSubQueryBuilder(versionsMiddleEntityName, "ee2");

            maxEeRevQb.AddProjection("max", revisionPropertyPath, false);
            // WHERE
            Parameters maxEeRevQbParameters = maxEeRevQb.RootParameters;

            // ee2.revision <= :revision
            maxEeRevQbParameters.AddWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
            // ee2.originalId.* = ee.originalId.*
            String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;

            referencingIdData.PrefixedMapper.AddIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
            foreach (MiddleComponentData componentData in componentDatas)
            {
                componentData.ComponentMapper.AddMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
            }

            // ee.revision = (SELECT max(...) ...)
            rootParameters.AddWhere(revisionPropertyPath, "=", maxEeRevQb);
        }
        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();
        }
예제 #4
0
        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();
        }
        private static void addRevisionRestriction(Parameters rootParameters, string revisionProperty, string revisionEndProperty, bool addAlias, bool inclusive)
        {
            // e.revision <= _revision and (e.endRevision > _revision or e.endRevision is null)
            var subParm = rootParameters.AddSubParameters("or");

            rootParameters.AddWhereWithNamedParam(revisionProperty, addAlias, inclusive ? "<=" : "<", QueryConstants.RevisionParameter);
            subParm.AddWhereWithNamedParam(revisionEndProperty + ".id", addAlias, inclusive ? ">" : ">=", QueryConstants.RevisionParameter);
            subParm.AddWhere(revisionEndProperty, addAlias, "is", "null", false);
        }
예제 #6
0
        public void AddNamedIdEqualsToQuery(Parameters parameters, String prefix, bool equals)
        {
            IList <QueryParameterData> paramDatas = MapToQueryParametersFromId(null);

            Parameters parametersToUse = GetParametersToUse(parameters, paramDatas);

            foreach (QueryParameterData paramData in paramDatas)
            {
                parametersToUse.AddWhereWithNamedParam(paramData.getProperty(prefix), equals ? "=" : "<>", paramData.GetQueryParameterName());
            }
        }
        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();
        }
        /// <summary>
        /// Creates query restrictions used to retrieve only actual data.
        /// </summary>
        private void createValidDataRestrictions(IAuditStrategy auditStrategy,
                                                 MiddleIdData referencedIdData, QueryBuilder qb, Parameters rootParameters)
        {
            var revisionPropertyPath = VerEntCfg.RevisionNumberPath;

            // (selecting e entities at revision :revision)
            // --> based on auditStrategy (see above)
            auditStrategy.AddEntityAtRevisionRestriction(qb, rootParameters, revisionPropertyPath, VerEntCfg.RevisionEndFieldName, true,
                                                         referencedIdData, revisionPropertyPath, VerEntCfg.OriginalIdPropName, QueryConstants.ReferencedEntityAlias, QueryConstants.ReferencedEntityAliasDefAudStr);
            // e.revision_type != DEL
            rootParameters.AddWhereWithNamedParam(RevisionTypePath(), false, "!=", QueryConstants.DelRevisionTypeParameter);
        }
예제 #9
0
        public static void AddEntityAtRevision(GlobalConfiguration globalCfg, QueryBuilder qb, Parameters rootParameters,
                                               MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName,
                                               String alias1, String alias2)
        {
            // SELECT max(e.revision) FROM versionsReferencedEntity e2
            QueryBuilder maxERevQb = qb.NewSubQueryBuilder(idData.AuditEntityName, alias2);

            maxERevQb.AddProjection("max", revisionPropertyPath, false);
            // WHERE
            Parameters 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);

            // e.revision = (SELECT max(...) ...)
            rootParameters.AddWhere("e." + revisionPropertyPath, false, globalCfg.getCorrelatedSubqueryOperator(), maxERevQb);
        }