Beispiel #1
0
        /// <summary>
        /// Returns the type of a property, given it's name (the last part) and the full path.
        /// </summary>
        /// <param name="propertyName">The last part of the full path to the property.</param>
        /// <param name="propertyPath">The full property path.</param>
        /// <returns>The type</returns>
        public IType GetPropertyType(string propertyName, string propertyPath)
        {
            CheckInitialized();

            IType type = null;

            // If this is an entity and the property is the identifier property, then use getIdentifierType().
            //      Note that the propertyName.equals( propertyPath ) checks whether we have a component
            //      key reference, where the component class property name is the same as the
            //      entity id property name; if the two are not equal, this is the case and
            //      we'd need to "fall through" to using the property mapping.
            if (_persister != null && (propertyName == propertyPath) && propertyName == _persister.IdentifierPropertyName)
            {
                type = _persister.IdentifierType;
            }
            else
            {                   // Otherwise, use the property mapping.
                IPropertyMapping mapping = GetPropertyMapping(propertyName);
                type = mapping.ToType(propertyPath);
            }
            if (type == null)
            {
                throw new MappingException("Property " + propertyName + " does not exist in " +
                                           ((_queryableCollection == null) ? "class" : "collection") + " "
                                           + ((_queryableCollection == null) ? _fromElement.ClassName : _queryableCollection.Role));
            }
            return(type);
        }
Beispiel #2
0
        protected IQueryableCollection GetQueryableCollection(string entityName, string actualPropertyName,
                                                              ISessionFactoryImplementor factory)
        {
            IPropertyMapping ownerMapping = (IPropertyMapping)factory.GetEntityPersister(entityName);
            IType            type         = ownerMapping.ToType(actualPropertyName);

            if (!type.IsCollectionType)
            {
                throw new MappingException(
                          "Property path [" + entityName + "." + actualPropertyName + "] does not reference a collection"
                          );
            }

            string role = ((CollectionType)type).Role;

            try
            {
                return((IQueryableCollection)factory.GetCollectionPersister(role));
            }
            catch (InvalidCastException cce)
            {
                throw new QueryException("collection role is not queryable: " + role, cce);
            }
            catch (Exception e)
            {
                throw new QueryException("collection role not found: " + role, e);
            }
        }
Beispiel #3
0
 public IType ToType(string propertyName)
 {
     if ("index".Equals(propertyName))
     {
         return(indexType);
     }
     return(elementPropertyMapping.ToType(propertyName));
 }
        private Persister.Entity.IJoinable GetPathJoinable(string path)
        {
            // start with the root
            IJoinable last = rootPersister;

            var tokens = path.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

            if (tokens.Length == 0)
            {
                return(last);
            }

            IPropertyMapping lastEntity = rootPersister;
            int i = 0;

            if (entityJoins.TryGetValue(tokens[0], out var entityJoinInfo))
            {
                last       = entityJoinInfo.Persister;
                lastEntity = (IPropertyMapping)last;
                i++;
            }

            string componentPath = string.Empty;

            for (; i < tokens.Length; i++)
            {
                componentPath += tokens[i];
                IType type = lastEntity.ToType(componentPath);
                if (type.IsAssociationType)
                {
                    if (type.IsCollectionType)
                    {
                        // ignore joinables for composite collections
                        var collectionType = (CollectionType)type;
                        var persister      = Factory.GetCollectionPersister(collectionType.Role);
                        if (persister.ElementType.IsEntityType == false)
                        {
                            return(null);
                        }
                    }
                    IAssociationType atype = (IAssociationType)type;

                    last          = atype.GetAssociatedJoinable(Factory);
                    lastEntity    = (NHibernate_Persister_Entity.IPropertyMapping)Factory.GetEntityPersister(atype.GetAssociatedEntityName(Factory));
                    componentPath = "";
                }
                else if (type.IsComponentType)
                {
                    componentPath += '.';
                }
                else
                {
                    throw new QueryException("not an association: " + componentPath);
                }
            }
            return(last);
        }
        private IJoinable GetPathJoinable(string path)
        {
            IJoinable        last       = (IJoinable)Factory.GetEntityPersister(rootEntityName);
            IPropertyMapping lastEntity = (IPropertyMapping)last;

            string componentPath = "";

            StringTokenizer tokens = new StringTokenizer(path, ".", false);

            foreach (string token in tokens)
            {
                componentPath += token;
                IType type = lastEntity.ToType(componentPath);
                if (type.IsAssociationType)
                {
                    if (type.IsCollectionType)
                    {
                        // ignore joinables for composite collections
                        var collectionType = (CollectionType)type;
                        var persister      = Factory.GetCollectionPersister(collectionType.Role);
                        if (persister.ElementType.IsEntityType == false)
                        {
                            return(null);
                        }
                    }
                    IAssociationType atype = (IAssociationType)type;

                    last          = atype.GetAssociatedJoinable(Factory);
                    lastEntity    = (IPropertyMapping)Factory.GetEntityPersister(atype.GetAssociatedEntityName(Factory));
                    componentPath = "";
                }
                else if (type.IsComponentType)
                {
                    componentPath += '.';
                }
                else
                {
                    throw new QueryException("not an association: " + componentPath);
                }
            }
            return(last);
        }