public void AddToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters)
        {
            String propertyName = propertyNameGetter.Get(auditCfg);

            CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName);

            // This will be the aggregated query, containing all the specified conditions
            QueryBuilder subQb = qb.NewSubQueryBuilder();

            // Adding all specified conditions both to the main query, as well as to the
            // aggregated one.
            foreach (IAuditCriterion versionsCriteria in criterions) {
                versionsCriteria.AddToQuery(auditCfg, entityName, qb, parameters);
                versionsCriteria.AddToQuery(auditCfg, 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;
            }

            // Adding the constrain on the result of the aggregated criteria
            parameters.AddWhere(propertyName, "=", subQb);
        }
        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 auditCfg, String entityName, QueryBuilder qb, Parameters parameters)
 {
     String propertyName = propertyNameGetter.Get(auditCfg);
     CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName);
     parameters.AddWhereWithParam(propertyName, ">=", lo);
     parameters.AddWhereWithParam(propertyName, "<=", hi);
 }
Exemplo n.º 4
0
 /**
  * Adds sub-parameters with a new connective. That is, the parameters will be grouped in parentheses in the
  * generated query, e.g.: ... and (exp1 or exp2) and ..., assuming the old connective is "and", and the
  * new connective is "or".
  * @param newConnective New connective of the parameters.
  * @return Sub-parameters with the given connective.
  */
 public Parameters AddSubParameters(String newConnective) {
     if (connective.Equals(newConnective)) {
         return this;
     } else {
         Parameters newParams = new Parameters(alias, newConnective, queryParamCounter);
         subParameters.Add(newParams);
         return newParams;
     }
 }
        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 void AddIdsEqualToQuery(Parameters parameters, String prefix1, String prefix2)
        {
            IList<QueryParameterData> paramDatas = MapToQueryParametersFromId(null);

            Parameters parametersToUse = GetParametersToUse(parameters, paramDatas);

            foreach (QueryParameterData paramData in paramDatas) {
            parametersToUse.AddWhere(paramData.getProperty(prefix1), false, "=", paramData.getProperty(prefix2), false);
            }
        }
        public void AddIdEqualsToQuery(Parameters parameters, Object id, String prefix, bool equals)
        {
            IList<QueryParameterData> paramDatas = MapToQueryParametersFromId(id);

            Parameters parametersToUse = GetParametersToUse(parameters, paramDatas);

            foreach (QueryParameterData paramData in paramDatas) {
            parametersToUse.AddWhereWithParam(paramData.getProperty(prefix) , equals ? "=" : "<>", paramData.getValue());
            }
        }
Exemplo n.º 8
0
        public void AddIdsEqualToQuery(Parameters parameters, string prefix1, string prefix2)
        {
            var paramDatas = MapToQueryParametersFromId(null);
            var parametersToUse = GetParametersToUse(parameters, paramDatas);

            foreach (var paramData in paramDatas)
            {
                parametersToUse.AddWhere(paramData.GetProperty(prefix1), false, "=", paramData.GetProperty(prefix2), false);
            }
        }
Exemplo n.º 9
0
        public void AddNamedIdEqualsToQuery(Parameters parameters, string prefix, bool equals)
        {
            var paramDatas = MapToQueryParametersFromId(null);
            var parametersToUse = GetParametersToUse(parameters, paramDatas);

            foreach (var paramData in paramDatas)
            {
                parametersToUse.AddWhereWithNamedParam(paramData.GetProperty(prefix), equals ? "=" : "<>", paramData.QueryParameterName);
            }
        }
        public void AddToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
            String propertyName = propertyNameGetter.Get(auditCfg);
            RelationDescription relatedEntity = CriteriaTools.GetRelatedEntity(auditCfg, entityName, propertyName);

            if (relatedEntity == null) {
                parameters.AddWhereWithParam(propertyName, "<>", null);
            } else {
                relatedEntity.IdMapper.AddIdEqualsToQuery(parameters, null, propertyName, false);
            }
        }
Exemplo n.º 11
0
 private static void handleNullValue(Parameters parameters, string propertyName, bool equals)
 {
     if (equals)
     {
         parameters.AddNullRestriction(propertyName, equals);
     }
     else
     {
         parameters.AddNotNullRestriction(propertyName, equals);
     }
 }
        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);
                }
            }
        }
        public void AddToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
            String propertyName = propertyNameGetter.Get(auditCfg);
            
            RelationDescription relatedEntity = CriteriaTools.GetRelatedEntity(auditCfg, entityName, propertyName);

            if (relatedEntity == null) {
                throw new AuditException("This criterion can only be used on a property that is " +
                        "a relation to another property.");
            } else {
                relatedEntity.IdMapper.AddIdEqualsToQuery(parameters, id, propertyName, equals);
            }
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        public void AddToQuery(AuditConfiguration auditCfg, string entityName, QueryBuilder qb, Parameters parameters)
        {
            var propertyName = propertyNameGetter.Get(auditCfg);
            var relatedEntity = CriteriaTools.GetRelatedEntity(auditCfg, entityName, propertyName);

            if (relatedEntity == null)
            {
                parameters.AddNullRestriction(propertyName, true);
            }
            else
            {
                relatedEntity.IdMapper.AddIdEqualsToQuery(parameters, null, propertyName, true);
            }
        }
Exemplo n.º 16
0
        private QueryBuilder(String entityName, String alias, MutableInteger aliasCounter, MutableInteger paramCounter)
        {
            this.entityName = entityName;
            this.alias = alias;
            this.aliasCounter = aliasCounter;
            this.paramCounter = paramCounter;

            rootParameters = new Parameters(alias, "and", paramCounter);

            froms = new List<Pair<String, String>>();
            orders = new List<Pair<String, Boolean>>();
            projections = new List<String>();

            AddFrom(entityName, alias);
        }
Exemplo n.º 17
0
        private QueryBuilder(string entityName, string alias, Incrementor aliasCounter, Incrementor paramCounter)
        {
            this.entityName = entityName;
            this.alias = alias;
            this.aliasCounter = aliasCounter;
            this.paramCounter = paramCounter;

            rootParameters = new Parameters(alias, "and", paramCounter);

            froms = new List<Pair<string, string>>();
            orders = new List<Pair<string, bool>>();
            projections = new List<string>();

            AddFrom(entityName, alias);
        }
        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);
            }
        }
Exemplo n.º 19
0
        public void AddIdEqualsToQuery(Parameters parameters, object id, string prefix, bool equals)
        {
            var paramDatas = MapToQueryParametersFromId(id);
            var parametersToUse = GetParametersToUse(parameters, paramDatas);

            foreach (var paramData in paramDatas)
            {
                if (paramData.Value == null)
                {
                    handleNullValue(parametersToUse, paramData.GetProperty(prefix), equals);
                }
                else
                {
                    parametersToUse.AddWhereWithParam(paramData.GetProperty(prefix), equals ? "=" : "<>", paramData.Value);
                }
            }
        }
        public void AddToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
            String propertyName = propertyNameGetter.Get(auditCfg);

            RelationDescription relatedEntity = CriteriaTools.GetRelatedEntity(auditCfg, entityName, propertyName);

            if (relatedEntity == null) {
                parameters.AddWhereWithParam(propertyName, op, value);
            } else {
                if (!"=".Equals(op) && !"<>".Equals(op)) {
                    throw new AuditException("This type of operation: " + op + " (" + entityName + "." + propertyName +
                            ") isn't supported and can't be used in queries.");
                }

                Object id = relatedEntity.IdMapper.MapToIdFromEntity(value);

                relatedEntity.IdMapper.AddIdEqualsToQuery(parameters, id, propertyName, "=".Equals(op));
            }
        }
        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);
        }
        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);
        }
Exemplo n.º 23
0
        public void AddToQuery(AuditConfiguration auditCfg, string entityName, QueryBuilder qb, Parameters parameters)
        {
            if (parameterValues.Length == 0)
            {
                parameters.AddWhere("1", false, "=", "0", false);
                return;
            }

            var propertyName = propertyNameGetter.Get(auditCfg);

            var relEntityDesc = CriteriaTools.GetRelatedEntity(auditCfg, entityName, propertyName);
            if (relEntityDesc == null)
            {
                parameters.AddWhereWithParams(propertyName, "in (", parameterValues, ")");
            }
            else
            {
                //move to IIdMapper when allowing more id sort of queries later
                var dic = new Dictionary<QueryParameterData, IList<object>>();
                for (var i = 0; i < parameterValues.Length; i++)
                {
                    var id = relEntityDesc.IdMapper.MapToIdFromEntity(parameterValues[i]);
                    var queryParams = relEntityDesc.IdMapper.MapToQueryParametersFromId(id);
                    foreach (var queryParam in queryParams)
                    {
                        if (i == 0)
                        {
                            dic[queryParam] = new List<object>();
                        }
                        dic[queryParam].Add(queryParam.Value);
                    }
                }
                foreach (var paramNameAndValue in dic)
                {
                    parameters.AddWhereWithParams(paramNameAndValue.Key.GetProperty(propertyName), "in (", paramNameAndValue.Value.ToArray(), ")");
                }
            }
        }
 public void AddToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
     criterion.AddToQuery(verCfg, entityName, qb, parameters.AddNegatedParameters());
 }
 public void AddMiddleEqualToQuery(Parameters parameters, string prefix1, string prefix2)
 {
     // Doing nothing.
 }
Exemplo n.º 26
0
 private static Parameters GetParametersToUse(Parameters parameters, ICollection<QueryParameterData> paramDatas)
 {
     return paramDatas.Count > 1 ? parameters.AddSubParameters("and") : parameters;
 }
Exemplo n.º 27
0
 /**
  * Adds negated parameters, by default with the "and" connective. These paremeters will be grouped in parentheses
  * in the generated query and negated, e.g. ... not (exp1 and exp2) ...
  * @return Negated sub paremters.
  */
 public Parameters AddNegatedParameters() {
     Parameters newParams = new Parameters(alias, AND, queryParamCounter);
     negatedParameters.Add(newParams);
     return newParams;
 }
Exemplo n.º 28
0
 public void AddToQuery(AuditConfiguration verCfg, string entityName, QueryBuilder qb, Parameters parameters)
 {
     verCfg.EntCfg[entityName].IdMapper
               .AddIdEqualsToQuery(parameters, id, verCfg.AuditEntCfg.OriginalIdPropName, equals);
 }
 public void AddMiddleEqualToQuery(Parameters parameters, String prefix1, String prefix2)
 {
     relatedIdData.PrefixedMapper.AddIdsEqualToQuery(parameters, prefix1, prefix2);
 }
 public void AddMiddleEqualToQuery(Parameters parameters, String prefix1, String prefix2)
 {
     throw new NotSupportedException("Cannot use this mapper with a middle table!");
 }