private ICriteriaInfoProvider GetPathInfo(string path) { StringTokenizer tokens = new StringTokenizer(path, ".", false); string componentPath = string.Empty; // start with the 'rootProvider' ICriteriaInfoProvider provider; if (nameCriteriaInfoMap.TryGetValue(rootEntityName, out provider) == false) { throw new ArgumentException("Could not find ICriteriaInfoProvider for: " + path); } foreach (string token in tokens) { componentPath += token; logger.DebugFormat("searching for {0}", componentPath); IType type = provider.GetType(componentPath); if (type.IsAssociationType) { // CollectionTypes are always also AssociationTypes - but there's not always an associated entity... IAssociationType atype = (IAssociationType)type; CollectionType ctype = type.IsCollectionType ? (CollectionType)type : null; IType elementType = (ctype != null) ? ctype.GetElementType(sessionFactory) : null; // is the association a collection of components or value-types? (i.e a colloction of valued types?) if (ctype != null && elementType.IsComponentType) { provider = new ComponentCollectionCriteriaInfoProvider(helper.GetCollectionPersister(ctype.Role)); } else if (ctype != null && !elementType.IsEntityType) { provider = new ScalarCollectionCriteriaInfoProvider(helper, ctype.Role); } else { provider = new EntityCriteriaInfoProvider((NHibernate_Persister_Entity.IQueryable)sessionFactory.GetEntityPersister( atype.GetAssociatedEntityName( sessionFactory) )); } componentPath = string.Empty; } else if (type.IsComponentType) { componentPath += '.'; } else { throw new QueryException("not an association: " + componentPath); } } logger.DebugFormat("returning entity name={0} for path={1} class={2}", provider.Name, path, provider.GetType().Name); return(provider); }
private void CreateCriteriaEntityNameMap() { // initialize the rootProvider first ICriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider(rootPersister); criteriaInfoMap.Add(rootCriteria, rootProvider); nameCriteriaInfoMap.Add(rootProvider.Name, rootProvider); foreach (var me in associationPathCriteriaMap) { var info = GetPathInfo(me.Key.Path, rootProvider); criteriaInfoMap.Add(me.Value, info); nameCriteriaInfoMap[info.Name] = info; } }
private void CreateCriteriaEntityNameMap() { // initialize the rootProvider first ICriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider((NHibernate_Persister_Entity.IQueryable)sessionFactory.GetEntityPersister(rootEntityName)); criteriaInfoMap.Add(rootCriteria, rootProvider); nameCriteriaInfoMap.Add(rootProvider.Name, rootProvider); foreach (KeyValuePair <string, ICriteria> me in associationPathCriteriaMap) { ICriteriaInfoProvider info = GetPathInfo(me.Key); criteriaInfoMap.Add(me.Value, info); nameCriteriaInfoMap[info.Name] = info; } }
private ICriteriaInfoProvider GetPathInfo(string path) { StringTokenizer tokens = new StringTokenizer(path, ".", false); string componentPath = string.Empty; // start with the 'rootProvider' ICriteriaInfoProvider provider; if (nameCriteriaInfoMap.TryGetValue(rootEntityName, out provider) == false) throw new ArgumentException("Could not find ICriteriaInfoProvider for: " + path); foreach (string token in tokens) { componentPath += token; logger.DebugFormat("searching for {0}", componentPath); IType type = provider.GetType(componentPath); if (type.IsAssociationType) { // CollectionTypes are always also AssociationTypes - but there's not always an associated entity... IAssociationType atype = (IAssociationType)type; CollectionType ctype = type.IsCollectionType ? (CollectionType)type : null; IType elementType = (ctype != null) ? ctype.GetElementType(sessionFactory) : null; // is the association a collection of components or value-types? (i.e a colloction of valued types?) if (ctype != null && elementType.IsComponentType) { provider = new ComponentCollectionCriteriaInfoProvider(helper.GetCollectionPersister(ctype.Role)); } else if (ctype != null && !elementType.IsEntityType) { provider = new ScalarCollectionCriteriaInfoProvider(helper, ctype.Role); } else { provider = new EntityCriteriaInfoProvider((NHibernate_Persister_Entity.IQueryable)sessionFactory.GetEntityPersister( atype.GetAssociatedEntityName( sessionFactory) )); } componentPath = string.Empty; } else if (type.IsComponentType) { componentPath += '.'; } else { throw new QueryException("not an association: " + componentPath); } } logger.DebugFormat("returning entity name={0} for path={1} class={2}", provider.Name, path, provider.GetType().Name); return provider; }
private void CreateCriteriaEntityNameMap() { // initialize the rootProvider first ICriteriaInfoProvider rootProvider = new EntityCriteriaInfoProvider((NHibernate_Persister_Entity.IQueryable)sessionFactory.GetEntityPersister(rootEntityName)); criteriaInfoMap.Add(rootCriteria, rootProvider); nameCriteriaInfoMap.Add(rootProvider.Name, rootProvider); foreach (KeyValuePair<string, ICriteria> me in associationPathCriteriaMap) { ICriteriaInfoProvider info = GetPathInfo(me.Key); criteriaInfoMap.Add(me.Value, info); nameCriteriaInfoMap[info.Name] = info; } }
private static List<string> GetMappedColumns(IEntityPersister persister, IEnumerable<string> columnNames) { var criteriaInfoProvider = new EntityCriteriaInfoProvider((IQueryable)persister); var propertySpaces = persister.PropertySpaces; var propertyTableNumbersInSelect = (int[])persister.GetType().GetProperty("PropertyTableNumbersInSelect", InstanceNonPublicBinding | BindingFlags.GetProperty).GetValue(persister, new object[0]); var result = columnNames.Select((x, index) => { return String.IsNullOrWhiteSpace(x) ? String.Empty : GenerateAlias(criteriaInfoProvider.PropertyMapping.ToColumns(x)[0], propertySpaces, propertyTableNumbersInSelect[index]); }).ToList(); return result; }
private ICriteriaInfoProvider GetPathInfo(string path, ICriteriaInfoProvider rootProvider) { var tokens = path.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries); // start with the root ICriteriaInfoProvider provider = rootProvider; if (tokens.Length == 0) { return(provider); } int i = 0; if (entityJoins.TryGetValue(tokens[0], out var entityJoinInfo)) { provider = new EntityCriteriaInfoProvider(entityJoinInfo.Persister); i++; } string componentPath = string.Empty; for (; i < tokens.Length; i++) { componentPath += tokens[i]; logger.Debug("searching for {0}", componentPath); IType type = provider.GetType(componentPath); if (type.IsAssociationType) { // CollectionTypes are always also AssociationTypes - but there's not always an associated entity... IAssociationType atype = (IAssociationType)type; CollectionType ctype = type.IsCollectionType ? (CollectionType)type : null; IType elementType = (ctype != null) ? ctype.GetElementType(sessionFactory) : null; // is the association a collection of components or value-types? (i.e a colloction of valued types?) if (ctype != null && elementType.IsComponentType) { provider = new ComponentCollectionCriteriaInfoProvider(helper.GetCollectionPersister(ctype.Role)); } else if (ctype != null && !elementType.IsEntityType) { provider = new ScalarCollectionCriteriaInfoProvider(helper, ctype.Role); } else { provider = new EntityCriteriaInfoProvider( GetQueryablePersister(atype.GetAssociatedEntityName(sessionFactory))); } componentPath = string.Empty; } else if (type.IsComponentType) { componentPath += '.'; } else { throw new QueryException("not an association: " + componentPath); } } logger.Debug("returning entity name={0} for path={1} class={2}", provider.Name, path, provider.GetType().Name); return(provider); }