Exemplo n.º 1
0
        /// <summary>
        /// Creates a child entity
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="server">Aptify server connection</param>
        /// <param name="store">Entity storage</param>
        private AptifyEntity(AptifyEntity parent, AptifyServer server, EntityStore store)
        {
            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            this.parent = parent;
            this.server = server;
            this.store  = store;

            // Get the entity that is mapped to this model instance
            this.table = server.Tables.GetTableMetadata(store.EntityObject);

            // Get the aptify generic entity and load its contents
            this.genericEntity = GetGenericEntity(server, parent, store, this.table.Entity);
            UpdateEntityContent( );

            // Load any child items
            if (store.Persister.HasCascades)
            {
                this.children = LoadChildEntities( ).ToArray( );
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a child entity from the server
        /// </summary>
        /// <param name="parent">Parent entity</param>
        /// <param name="entityMetadata">Metadata for the entity</param>
        /// <param name="store">The NHibernate storage about the updated object</param>
        /// <returns>A new generic entity that maps to this table and store</returns>
        internal AptifyGenericEntityBase GetEntity(AptifyEntity parent, AptifyEntityMetadata entityMetadata,
                                                   EntityStore store)
        {
            Log.DebugFormat("Creating child aptify entity for {0}", entityMetadata.Name);

            AptifySubTypeBase subType = parent.GenericEntity.SubTypes[entityMetadata.Name];

            // This is not a child entity within Aptify
            if (subType == null)
            {
                return(GetEntity(entityMetadata, store));
            }

            switch (store.Status)
            {
            case EntityStatus.Clean:
            case EntityStatus.Dirty:
                Log.DebugFormat("Loading subentity for {0}", entityMetadata.Name);
                return(subType.Find("id", store.Id));

            case EntityStatus.New:
                Log.DebugFormat("Loading new subentity for {0}", entityMetadata.Name);
                return(subType.Add( ));

            default:
                throw new InvalidOperationException("Unknown entity status " + store.Status);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads an aptify entity
        /// </summary>
        private static AptifyGenericEntityBase GetGenericEntity(AptifyServer server, AptifyEntity parent, EntityStore store,
                                                                AptifyEntityMetadata metadata)
        {
            // Clean entities don't need to be loaded
            if (store.Status == EntityStatus.Clean && parent != null)
            {
                return(null);
            }

            Log.DebugFormat("Loading entity: '{0}'", metadata.Name);

            if (parent != null)
            {
                return(server.GetEntity(parent, metadata, store));
            }

            return(server.GetEntity(metadata, store));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Updates the column
        /// </summary>
        /// <param name="genericEntityBase">Entity to update</param>
        /// <param name="column">Column description</param>
        /// <param name="state">Column state</param>
        /// <param name="doCascade">Should this column be persisted if it's a foreign key column</param>
        private void SetColumnValue(AptifyGenericEntityBase genericEntityBase, AptifyColumnMetadata column,
                                    object state, bool doCascade)
        {
            if (genericEntityBase == null)
            {
                throw new ArgumentNullException("genericEntityBase");
            }

            if (column == null)
            {
                throw new ArgumentNullException("column");
            }

            if (column.IsForeignKeyColumn && state != null || state is INHibernateProxy)
            {
                if (doCascade)
                {
                    var          cascadeStore = new EntityStore(this.store.Session, state);
                    AptifyEntity cascadeEntity;

                    if (column.IsEmbedded)
                    {
                        cascadeEntity =
                            new AptifyEntity(this.GenericEntity.Fields[column.Name], this.server, cascadeStore);
                    }
                    else
                    {
                        cascadeEntity = new AptifyEntity(this.server, cascadeStore);
                    }

                    state = cascadeEntity.SaveOrUpdate( );
                }
                else
                {
                    state = this.store.Session.GetIdentifier(state);
                }
            }

            genericEntityBase.SetValue(column.Name, state);
        }