Пример #1
0
        public void AddToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters)
        {
            Parameters opParameters = parameters.AddSubParameters(op);

            lhs.AddToQuery(verCfg, entityName, qb, opParameters.AddSubParameters("and"));
            rhs.AddToQuery(verCfg, entityName, qb, opParameters.AddSubParameters("and"));
        }
        public void AddToQuery(AuditConfiguration verCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters)
        {
            var opParameters = parameters.AddSubParameters(op);

            lhs.AddToQuery(verCfg, versionsReader, entityName, qb, opParameters.AddSubParameters("and"));
            rhs.AddToQuery(verCfg, versionsReader, entityName, qb, opParameters.AddSubParameters("and"));
        }
Пример #3
0
        private static void addMiddleEqualToQuery(ICompositeMapperBuilder compositeMapper, Parameters parameters, string idPrefix1,
                                                  string prefix1, string idPrefix2, string prefix2)
        {
            foreach (var keyValue in compositeMapper.Properties)
            {
                var propertyName = keyValue.Key.Name;
                var nestedMapper = keyValue.Value;

                var nestedCompositeMapper = nestedMapper as ICompositeMapperBuilder;
                if (nestedCompositeMapper != null)
                {
                    addMiddleEqualToQuery(nestedCompositeMapper, parameters, idPrefix1, prefix1, idPrefix2, prefix2);
                }
                else
                {
                    var nestedToOneIdMapper = nestedMapper as ToOneIdMapper;
                    if (nestedToOneIdMapper != null)
                    {
                        nestedToOneIdMapper.AddMiddleEqualToQuery(parameters, idPrefix1, prefix1, idPrefix2, prefix2);
                    }
                    else
                    {
                        // (p1.prop = p2.prop or (p1.prop is null and p2.prop is null))
                        var sub1 = parameters.AddSubParameters("or");
                        sub1.AddWhere(prefix1 + "." + propertyName, false, "=", prefix2 + "." + propertyName, false);
                        var sub2 = sub1.AddSubParameters("and");
                        sub2.AddNullRestriction(prefix1 + '.' + propertyName, false);
                        sub2.AddNullRestriction(prefix2 + '.' + propertyName, false);
                    }
                }
            }
        }
        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);
        }
Пример #5
0
        public void AddToQuery(AuditConfiguration auditCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters)
        {
            var propertyName = CriteriaTools.DeterminePropertyName(auditCfg, versionsReader, entityName, propertyNameGetter);

            CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName);
            var subParams = parameters.AddSubParameters(Parameters.AND);

            subParams.AddWhereWithParam(propertyName, ">=", lo);
            subParams.AddWhereWithParam(propertyName, "<=", hi);
        }
Пример #6
0
        public void AddToQuery(AuditConfiguration verCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters)
        {
            var andParameters = parameters.AddSubParameters(Parameters.AND);

            if (criterions.Count == 0)
            {
                andParameters.AddWhere("1", false, "=", "1", false);
            }
            else
            {
                foreach (var criterion in criterions)
                {
                    criterion.AddToQuery(verCfg, versionsReader, entityName, qb, andParameters);
                }
            }
        }
Пример #7
0
        public void AddToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters)
        {
            Parameters andParameters = parameters.AddSubParameters(Parameters.AND);

            if (criterions.Count == 0)
            {
                andParameters.AddWhere("1", false, "=", "1", false);
            }
            else
            {
                foreach (IAuditCriterion criterion in criterions)
                {
                    criterion.AddToQuery(verCfg, entityName, qb, andParameters);
                }
            }
        }
Пример #8
0
        public void AddToQuery(AuditConfiguration auditCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters)
        {
            var propertyName = CriteriaTools.DeterminePropertyName(auditCfg, versionsReader, entityName, propertyNameGetter);

            CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName);

            // Make sure our conditions are ANDed together even if the parent Parameters have a different connective
            var subParams = parameters.AddSubParameters(Parameters.AND);
            // This will be the aggregated query, containing all the specified conditions
            var subQb = qb.NewSubQueryBuilder();

            // Adding all specified conditions both to the main query, as well as to the
            // aggregated one.
            foreach (var versionsCriteria in criterions)
            {
                versionsCriteria.AddToQuery(auditCfg, versionsReader, entityName, qb, subParams);
                versionsCriteria.AddToQuery(auditCfg, versionsReader, entityName, subQb, subQb.RootParameters);
            }

            // Setting the desired projection of the aggregated query
            switch (mode)
            {
            case AggregatedMode.Min:
                subQb.AddProjection("min", propertyName, false);
                break;

            case AggregatedMode.Max:
                subQb.AddProjection("max", propertyName, false);
                break;
            }

            // Correlating subquery with the outer query by entity id.
            if (correlate)
            {
                var originalIdPropertyName = auditCfg.AuditEntCfg.OriginalIdPropName;
                auditCfg.EntCfg[entityName].IdMapper.AddIdsEqualToQuery(subQb.RootParameters, subQb.RootAlias + "." + originalIdPropertyName, qb.RootAlias + "." + originalIdPropertyName);
            }

            // Adding the constrain on the result of the aggregated criteria
            subParams.AddWhere(propertyName, "=", subQb);
        }
Пример #9
0
 private static Parameters GetParametersToUse(Parameters parameters, ICollection <QueryParameterData> paramDatas)
 {
     return(paramDatas.Count > 1 ? parameters.AddSubParameters("and") : parameters);
 }