Esempio n. 1
0
        protected internal virtual FieldReader getFieldReader(Type[] returnTypes, IDictionary <string, int> aliasesMap, JRField field)
        {
            FieldReader reader;

            string fieldMapping = getFieldMapping(field);
            int?   fieldIdx     = aliasesMap[fieldMapping];

            if (fieldIdx == null)
            {
                int firstNestedIdx = fieldMapping.IndexOf(PropertyUtils.NESTED_DELIM);

                if (firstNestedIdx < 0)
                {
                    throw new JRRuntimeException("Unknown HQL return alias \"" + fieldMapping + "\".");
                }

                string fieldAlias    = fieldMapping.Substring(0, firstNestedIdx);
                string fieldProperty = fieldMapping.Substring(firstNestedIdx + 1);

                fieldIdx = aliasesMap[fieldAlias];
                if (fieldIdx == null)
                {
                    throw new JRRuntimeException("The HQL query does not have a \"" + fieldAlias + "\" alias.");
                }

                Type type = returnTypes[fieldIdx.Value];
                if (!type.EntityType && !type.ComponentType)
                {
                    throw new JRRuntimeException("The HQL query does not have a \"" + fieldAlias + "\" alias.");
                }

                reader = new IndexPropertyFieldReader(fieldIdx.Value, fieldProperty);
            }
            else
            {
                reader = new IndexFieldReader(fieldIdx.Value);
            }

            return(reader);
        }
Esempio n. 2
0
        protected internal virtual FieldReader getFieldReaderSingleReturn(IDictionary <string, int> aliasesMap, JRField field, bool useIndex)
        {
            FieldReader reader;

            string fieldMapping = getFieldMapping(field);

            if (aliasesMap.ContainsKey(fieldMapping))
            {
                if (useIndex)
                {
                    reader = new IndexFieldReader(0);
                }
                else
                {
                    reader = new IdentityFieldReader();
                }
            }
            else
            {
                int firstNestedIdx = fieldMapping.IndexOf(PropertyUtils.NESTED_DELIM);

                if (firstNestedIdx >= 0 && aliasesMap.ContainsKey(fieldMapping.Substring(0, firstNestedIdx)))
                {
                    fieldMapping = fieldMapping.Substring(firstNestedIdx + 1);
                }

                if (useIndex)
                {
                    reader = new IndexPropertyFieldReader(0, fieldMapping);
                }
                else
                {
                    reader = new PropertyFieldReader(fieldMapping);
                }
            }

            return(reader);
        }