private string GetWholeAssociationPath(CriteriaImpl.Subcriteria subcriteria, out string parentAlias) { string path = subcriteria.Path; // some messy, complex stuff here, since createCriteria() can take an // aliased path, or a path rooted at the creating criteria instance ICriteria parent = null; if (StringHelper.IsNotRoot(path, out var testAlias)) { // if it is a compound path if (!testAlias.Equals(subcriteria.Alias)) { // and the qualifier is not the alias of this criteria // -> check to see if we belong to some criteria other // than the one that created us aliasCriteriaMap.TryGetValue(testAlias, out parent); } } if (parent == null) { // otherwise assume the parent is the the criteria that created us parent = subcriteria.Parent; } else { path = StringHelper.Unroot(path); } parentAlias = parent.Alias; if (parent.Equals(rootCriteria)) { // if its the root criteria, we are done return(path); } else { // otherwise, recurse return(GetWholeAssociationPath((CriteriaImpl.Subcriteria)parent, out _) + '.' + path); } }
private static void CloneSubcriteriaAndOrders(CriteriaImpl clone, CriteriaImpl original) { //we need to preserve the parent criteria, we rely on the orderring when creating the //subcriterias initially here, so we don't need to make more than a single pass Hashtable newParents = new Hashtable(); newParents[original] = clone; foreach (CriteriaImpl.Subcriteria subcriteria in original.IterateSubcriteria()) { ICriteria currentParent = (ICriteria)newParents[subcriteria.Parent]; if (currentParent == null) { throw new AssertionFailure( "Could not find parent for subcriteria in the previous subcriteria. If you see this error, it is a bug"); } CriteriaImpl.Subcriteria clonedSubCriteria = new CriteriaImpl.Subcriteria(clone, currentParent, subcriteria.Path, subcriteria.Alias, subcriteria.JoinType); clonedSubCriteria.SetLockMode(subcriteria.LockMode); newParents[subcriteria] = clonedSubCriteria; } // remap the orders foreach (CriteriaImpl.OrderEntry orderEntry in original.IterateOrderings()) { ICriteria currentParent = (ICriteria)newParents[orderEntry.Criteria]; if (currentParent == null) { 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 (CriteriaImpl.CriterionEntry criterionEntry in original.Restrictions) { ICriteria currentParent = (ICriteria) newParents[criterionEntry.Criteria]; if (currentParent == null) { 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); } }