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 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 auditCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters) { var propertyName = CriteriaTools.DeterminePropertyName(auditCfg, versionsReader, entityName, propertyNameGetter); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, otherPropertyName); parameters.AddWhere(propertyName, op, otherPropertyName); }
public void AddToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) { String propertyName = propertyNameGetter.Get(auditCfg); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, propertyName); CriteriaTools.CheckPropertyNotARelation(auditCfg, entityName, otherPropertyName); parameters.AddWhere(propertyName, op, otherPropertyName); }
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 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 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 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); } }
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 void AddToQuery(AuditConfiguration auditCfg, IAuditReaderImplementor versionsReader, string entityName, QueryBuilder qb, Parameters parameters) { if (parameterValues.Length == 0) { parameters.AddWhere("1", false, "=", "0", false); return; } var propertyName = CriteriaTools.DeterminePropertyName(auditCfg, versionsReader, entityName, propertyNameGetter); 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(null), "in (", paramNameAndValue.Value.ToArray(), ")"); } } }
public void AddEntityAtRevisionRestriction(QueryBuilder rootQueryBuilder, Parameters parameters, string revisionProperty, string revisionEndProperty, bool addAlias, MiddleIdData idData, string revisionPropertyPath, string originalIdPropertyName, string alias1, string alias2) { // 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, "<=", QueryConstants.RevisionParameter); // e2.id_ref_ed = e.id_ref_ed idData.OriginalMapper.AddIdsEqualToQuery(maxERevQbParameters, alias1 + "." + originalIdPropertyName, alias2 + "." + originalIdPropertyName); // add subquery to rootParameters var subqueryOperator = _auditConfiguration.GlobalCfg.CorrelatedSubqueryOperator; parameters.AddWhere(revisionProperty, addAlias, subqueryOperator, maxERevQb); }
public void AddAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, Parameters parameters, string revisionProperty, string revisionEndProperty, bool addAlias, MiddleIdData referencingIdData, string versionsMiddleEntityName, string eeOriginalIdPropertyPath, string revisionPropertyPath, string originalIdPropertyName, string alias1, bool inclusive, params MiddleComponentData[] componentDatas) { // SELECT max(ee2.revision) FROM middleEntity ee2 var maxEeRevQb = rootQueryBuilder.NewSubQueryBuilder(versionsMiddleEntityName, QueryConstants.MiddleEntityAliasDefAudStr); maxEeRevQb.AddProjection("max", revisionPropertyPath, false); // WHERE var maxEeRevQbParameters = maxEeRevQb.RootParameters; // ee2.revision <= :revision maxEeRevQbParameters.AddWhereWithNamedParam(revisionPropertyPath, inclusive ? "<=" : "<", QueryConstants.RevisionParameter); // ee2.originalId.* = ee.originalId.* var ee2OriginalIdPropertyPath = QueryConstants.MiddleEntityAliasDefAudStr + "." + originalIdPropertyName; referencingIdData.PrefixedMapper.AddIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath); foreach (var componentData in componentDatas) { componentData.ComponentMapper.AddMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, alias1, ee2OriginalIdPropertyPath, QueryConstants.MiddleEntityAliasDefAudStr); } // add subquery to rootParameters parameters.AddWhere(revisionProperty, addAlias, "=", maxEeRevQb); }
public void AddMiddleEqualToQuery(Parameters parameters, string prefix1, string prefix2) { parameters.AddWhere(prefix1 + "." + propertyName, false, "=", prefix2 + "." + propertyName, false); }