/// <summary> /// Find a join. Return the name of the corresponding property. /// </summary> private static AbstractEntityPersister FindJoinedEntity(SessionFactoryImpl sf, AbstractEntityPersister root, string toTable, string fromField, out string propertyName) { // root.ClassMetadata.PropertyTypes.First().Na for (int i = 0; i < root.PropertyTypes.Length; i++) { if (root.PropertyTypes[i].IsAssociationType && !root.PropertyTypes[i].IsCollectionType) { String[] cols = root.ToColumns(root.PropertyNames[i]); if (cols.Length == 1 && cols[0] == fromField) { propertyName = root.PropertyNames[i]; Type t = root.PropertyTypes[i].ReturnedClass; String entityName = sf.TryGetGuessEntityName(t); AbstractEntityPersister persister = (AbstractEntityPersister)sf.GetEntityPersister(entityName); if (persister.TableName == toTable) { return(persister); } // special case for acct mgr if (toTable == "USERINFO" && persister.TableName == "USERSECURITY") { propertyName = propertyName + ".UserInfo"; entityName = "Sage.SalesLogix.Security.UserInfo"; return((AbstractEntityPersister)sf.GetEntityPersister(entityName)); } } } } propertyName = null; return(null); }
/// <summary> /// Path represents path to a field, based at origin. /// Return the field object. /// A field path is normally of the form: /// Source Table:Path /// where Path is recursively defined as either: /// FieldName /// or /// From Field=To Field.To Table!Path /// </summary> /// <param name="sf"></param> /// <param name="root"></param> /// <param name="path"></param> /// <param name="format"></param> internal static String DecomposePath(SessionFactoryImpl sf, AbstractEntityPersister root, String path, String format) { String[] parts; parts = path.Split(new char[] { '!' }, 2); if (parts.Length == 1) { // field name // remove initial "@" (this is used to indicate calculated fields) if (parts[0][0] == '@') { parts[0] = parts[0].Substring(1); } String fieldName = parts[0].ToUpper(); for (int i = 0; i < root.PropertyTypes.Length; i++) { IType propType = root.PropertyTypes[i]; if (propType.IsCollectionType) { continue; } String propName = root.PropertyNames[i]; String[] columns = root.ToColumns(propName); if (columns.Length == 1 && columns[0].ToUpper() == fieldName) { return(FormatProperty(propName, propType, format)); } } LOG.Warn("Unable to locate property by column - " + parts[0]); return(null); } else { String newpath = parts[1]; // part after the exclamation mark Match matches = _fieldPathRegexp.Match(parts[0]); if (!matches.Success) { throw new ArgumentException("Path did not match field expression pattern: " + parts[0]); } System.Diagnostics.Debug.Assert(matches.Groups.Count == 5, "Number of Groups should have been 5, was " + matches.Groups.Count + " (path = " + parts[0] + ")"); String toTable = matches.Groups[4].Value; String fromField = matches.Groups[1].Value; String propertyName; root = FindJoinedEntity(sf, root, toTable, fromField, out propertyName); if (root == null) { throw new ArgumentException("Unable to locate linked property " + toTable + " via " + fromField + "!"); } return(propertyName + "." + DecomposePath(sf, root, newpath, format)); } }