Superclass for built-in mapping strategies. Implements functionalty common to both mapping strategies
May be considered an immutable view of the mapping object
Inheritance: IOuterJoinLoadable, IQueryable, IClassMetadata, IUniqueKeyLoadable, ISqlLoadable, ILazyPropertyInitializer, IPostInsertIdentityPersister, ILockable
Exemplo n.º 1
0
        public override string GetAuditNoteForComponentProperty(AbstractEntityPersister persister, ComponentType componentType, int propertyIndexToAudit)
        {
            string componentPropertyName = persister.PropertyNames[propertyIndexToAudit];

            object oldComponentValue = _oldStates[propertyIndexToAudit];
            object newComponentValue = _newStates[propertyIndexToAudit];

            string note = GetAuditNoteForComponent(persister, componentType, componentPropertyName, new UpdateComponentAuditStrategy(oldComponentValue, newComponentValue));

            return note;
        }
Exemplo n.º 2
0
        internal string GetAuditNoteForComponent(AbstractEntityPersister persister, ComponentType componentType, string componentPropertyNameChain, IComponentAuditStrategy propertyAuditStrategy)
        {
            var noteBulder = new StringBuilder();

            Type componentDotNetType = componentType.ReturnedClass;

            foreach (PropertyInfo propertyInfo in componentDotNetType.GetProperties())
            {
                if (propertyAuditStrategy.IsExcludedFromAudit(propertyInfo))
                {
                    continue;
                }

                var ignoreMappingTypeAttributes = propertyInfo.GetCustomAttributes(typeof(IgnoreMappingAttribute), false);
                if (ignoreMappingTypeAttributes.Length != 0)
                {
                    continue;
                }

                string propertyName = propertyInfo.Name;
                var wholeComponentPropertyNameChain = string.Format("{0}.{1}", componentPropertyNameChain, propertyName);

                var subComponentType =
                    componentType.Subtypes.FirstOrDefault(p => p.ReturnedClass.FullName == propertyInfo.PropertyType.FullName && p.IsComponentType)
                    as
                    ComponentType;

                string note;

                if (subComponentType == null)
                {
                    string columnName = string.Join(",", persister.GetPropertyColumnNames(wholeComponentPropertyNameChain));

                    note = propertyAuditStrategy.GetAuditNoteForNonComponentProperty(propertyInfo, columnName);
                }
                else
                {
                    note = GetAuditNoteForComponent (
                        persister,
                        subComponentType,
                        wholeComponentPropertyNameChain,
                        propertyAuditStrategy.GetComponentPropertyAuditStrategy ( propertyInfo ) );
                }

                if (!string.IsNullOrWhiteSpace(note))
                {
                    noteBulder.AppendLine ( note );
                }
            }

            return noteBulder.ToString().Trim();
        }
Exemplo n.º 3
0
        public override string GetAuditNoteForComponentProperty(AbstractEntityPersister persister, ComponentType componentType, int propertyIndexToAudit)
        {
            string componentPropertyName = persister.PropertyNames[propertyIndexToAudit];

            object componentValue = _states[propertyIndexToAudit];

            string note = string.Empty;

            if (componentValue != null)
            {
                note = GetAuditNoteForComponent(persister, componentType, componentPropertyName, new DefaultComponentAuditStrategy(componentValue));
            }

            return note;
        }
			public GeneratedIdentifierBinder(object[] fields, bool[] notNull, ISessionImplementor session, object entity, AbstractEntityPersister entityPersister)
			{
				this.fields = fields;
				this.notNull = notNull;
				this.session = session;
				this.entity = entity;
				this.entityPersister = entityPersister;
			}
 /// <summary>
 /// Get the column names for a given property as a comma-delimited string of unbracketed names.
 /// </summary>
 /// <param name="persister"></param>
 /// <param name="propertyName"></param>
 /// <returns></returns>
 string GetPropertyColumnNames(AbstractEntityPersister persister, string propertyName)
 {
     var propColumnNames = persister.GetPropertyColumnNames(propertyName);
     if (propColumnNames.Length == 0)
     {
         // this happens when the property is part of the key
         propColumnNames = persister.KeyColumnNames;
     }
     var sb = new StringBuilder();
     foreach (var s in propColumnNames)
     {
         if (sb.Length > 0) sb.Append(',');
         sb.Append(UnBracket(s));
     }
     return sb.ToString();
 }
Exemplo n.º 6
0
		public BasicEntityPropertyMapping(AbstractEntityPersister persister)
		{
			this.persister = persister;
		}
Exemplo n.º 7
0
        /// <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);
            }
        }
Exemplo n.º 8
0
 /// <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>
 /// Gets the simple (non-Entity) property that has the given columns
 /// </summary>
 /// <param name="persister"></param>
 /// <param name="columnNames">Comma-delimited column name string</param>
 /// <returns></returns>
 string GetPropertyNameForColumn(AbstractEntityPersister persister, string columnNames)
 {
     var propNames = persister.PropertyNames;
     var propTypes = persister.PropertyTypes;
     for (int i = 0; i < propNames.Length; i++)
     {
         var propName = propNames[i];
         var propType = propTypes[i];
         if (propType.IsAssociationType) continue;
         var columnArray = persister.GetPropertyColumnNames(i);
         var columns = CatColumnNames(columnArray);
         if (columns == columnNames) return propName;
     }
     return persister.IdentifierPropertyName;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Get the column names for a given property as a comma-delimited string of unbracketed names.
 /// For a collection property, the column name is the inverse foreign key (i.e. the column on 
 /// the other table that points back to the persister's table)
 /// </summary>
 /// <param name="persister"></param>
 /// <param name="propertyName"></param>
 /// <returns></returns>
 string GetPropertyColumnNames(AbstractEntityPersister persister, string propertyName, IType propType)
 {
     string[] propColumnNames = null;
     if (propType.IsCollectionType)
     {
         propColumnNames = ((CollectionType)propType).GetReferencedColumns((ISessionFactoryImplementor)this._sessionFactory);
     }
     else
     {
         propColumnNames = persister.GetPropertyColumnNames(propertyName);
     }
     if (propColumnNames == null || propColumnNames.Length == 0)
     {
         // this happens when the property is part of the key
         propColumnNames = persister.KeyColumnNames;
     }
     return CatColumnNames(propColumnNames);
 }
Exemplo n.º 11
0
        /// <param name="type"></param>
        /// <param name="propName"></param>
        /// <returns>True if the type declares the given property, false otherwise.</returns>
        //bool hasOwnProperty(Type type, string propName)
        //{
        //    // this doesn't work: return persister.GetSubclassPropertyDeclarer(propName) == Declarer.Class;
        //    var flags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public;
        //    var hasProperty = type.GetProperty(propName, flags) != null || type.GetField(propName, flags) != null;
        //    return hasProperty;
        //}

        /// <summary>
        /// Return names of all properties that are defined in the mapped ancestors of the 
        /// given persister.  Note that unmapped superclasses are deliberately ignored, because
        /// they shouldn't affect the metadata.
        /// </summary>
        /// <param name="persister"></param>
        /// <returns>set of property names.  Empty if the persister doesn't have a superclass.</returns>
        HashSet<string> GetSuperProperties(AbstractEntityPersister persister)
        {
            HashSet<string> set = new HashSet<String>();
            if (!persister.IsInherited) return set;
            string superClassName = persister.MappedSuperclass;
            if (superClassName == null) return set;

            IClassMetadata superMeta = _sessionFactory.GetClassMetadata(superClassName);
            if (superMeta == null) return set;

            string[] superProps = superMeta.PropertyNames;
            set = new HashSet<string>(superProps);
            set.Add(superMeta.IdentifierPropertyName);
            return set;
        }
Exemplo n.º 12
0
 public abstract string GetAuditNoteForComponentProperty( AbstractEntityPersister persister, ComponentType componentType, int propertyIndexToAudit );