Ejemplo n.º 1
0
        private Subcriteria CreateSubcriteria(string associationPath, string alias, Func <ICriteria, ICriteria> subcriteriaFactory)
        {
            var subcriteria = new Subcriteria(this, alias, subcriteriaFactory);

            this.subcriteriaByPath[associationPath] = subcriteria;
            if (!string.IsNullOrEmpty(alias))
            {
                this.subcriteriaByAlias[alias] = subcriteria;
            }

            foreach (var pair in this.establishedCriteriaByShard)
            {
                subcriteria.EstablishFor(pair.Key, pair.Value);
            }
            return(subcriteria);
        }
Ejemplo n.º 2
0
        private void CloneSubcriteria(CriteriaImpl clone)
        {
            //we need to preserve the parent criteria, we rely on the ordering when creating the
            //subcriterias initially here, so we don't need to make more than a single pass
            Dictionary <ICriteria, ICriteria> newParents = new Dictionary <ICriteria, ICriteria>();

            newParents[this] = clone;

            foreach (Subcriteria subcriteria in IterateSubcriteria())
            {
                ICriteria currentParent;
                if (!newParents.TryGetValue(subcriteria.Parent, out currentParent))
                {
                    throw new AssertionFailure(
                              "Could not find parent for subcriteria in the previous subcriteria. If you see this error, it is a bug");
                }
                Subcriteria clonedSubCriteria =
                    new Subcriteria(clone, currentParent, subcriteria.Path, subcriteria.Alias, subcriteria.JoinType);
                clonedSubCriteria.SetLockMode(subcriteria.LockMode);
                newParents[subcriteria] = clonedSubCriteria;
            }

            // remap the orders
            foreach (OrderEntry orderEntry in IterateOrderings())
            {
                ICriteria currentParent;
                if (!newParents.TryGetValue(orderEntry.Criteria, out currentParent))
                {
                    throw new AssertionFailure(
                              "Could not find parent for order in the previous criteria. If you see this error, it is a bug");
                }
                currentParent.AddOrder(orderEntry.Order);
            }

            // remap the restrictions to appropriate criterias
            foreach (CriterionEntry criterionEntry in criteria)
            {
                ICriteria currentParent;
                if (!newParents.TryGetValue(criterionEntry.Criteria, out currentParent))
                {
                    throw new AssertionFailure(
                              "Could not find parent for restriction in the previous criteria. If you see this error, it is a bug.");
                }

                currentParent.Add(criterionEntry.Criterion);
            }
        }