Example #1
0
 protected RelationshipAction(RelationshipPersistenceProvider persistenceProvider, Relationship?relationship, OGM inItem, OGM outItem)
 {
     Relationship        = relationship;
     InItem              = inItem;
     OutItem             = outItem;
     PersistenceProvider = persistenceProvider;
 }
        internal OGM OutItem(OGM foreign)
        {
            if (ForeignProperty == null || ForeignProperty.Direction == DirectionEnum.Out)
            {
                return(foreign);
            }

            return(Parent);
        }
        internal OGM InItem(OGM foreign)
        {
            if (ForeignProperty != null && ForeignProperty.Direction == DirectionEnum.In)
            {
                return(foreign);
            }

            return(Parent);
        }
Example #4
0
        public void Initialize(OGM parent)
        {
            if (wrapper is not null)
            {
                throw new NotSupportedException("You should not call this method... Leave it to the professionals... Greetzz from the A Team.");
            }

            wrapper = parent;
            InitializeCollections();

            if (wrapper.GetEntity().InheritedUnidentifiedProperties() is not null)
            {
                UnidentifiedProperties = new UnidentifiedPropertyCollection(Wrapper);
            }
        }
        protected CollectionItem(OGM parent, OGM item, DateTime?startDate, DateTime?endDate)
        {
            if (parent is null)
            {
                throw new ArgumentNullException("parent");
            }

            if (item is null)
            {
                throw new ArgumentNullException("item");
            }

            Parent    = parent;
            Item      = item;
            StartDate = startDate ?? Conversion.MinDateTime;
            EndDate   = endDate ?? Conversion.MaxDateTime;
        }
        internal static OGM?Map(RawNode node, string cypher, Dictionary <string, object?>?parameters, NodeMapping mappingMode)
        {
            object?key = null;

            if (!node.Properties.TryGetValue(Entity.Key.Name, out key))
            {
                throw new ArgumentException($"The node does not contain key '{Entity.Key.Name}' for entity '{Entity.Name}'.");
            }

            if (key is null)
            {
                throw new ArgumentException($"The node contains null key '{Entity.Key.Name}' for entity '{Entity.Name}'.");
            }

            Transaction trans = Transaction.RunningTransaction;

            TWrapper?instance = (TWrapper?)trans.GetEntityByKey(Entity.Name, key);

            if (!(instance is null))
            {
                return(instance);
            }

            instance = Transaction.Execute(() => new TWrapper(), EventOptions.GraphEvents);
            instance.SetKey((TKey)key);
            OGM ogm = instance as OGM;

            Dictionary <string, object?> properties = (Dictionary <string, object?>)node.Properties;

            if (cypher is not null)
            {
                Dictionary <string, object?>?customState = null;
                NodeEventArgs loadingArgs = Entity.RaiseOnNodeLoading(trans, ogm, cypher, parameters, ref customState);
                NodeEventArgs args        = Entity.RaiseOnNodeLoaded(trans, loadingArgs, node.Id, node.Labels, properties);
                properties = args.Properties !;
            }

            if (instance.PersistenceState == PersistenceState.HasUid || instance.PersistenceState == PersistenceState.Loaded)
            {
                ogm.SetData(properties);
                instance.PersistenceState = (mappingMode == NodeMapping.AsWritableEntity) ? PersistenceState.Loaded : PersistenceState.OutOfScope;
            }

            return(instance);
        }
Example #7
0
        private protected void ExecuteAction(ClearRelationshipsAction action)
        {
            if (DbTransaction != null)
            {
                DbTransaction?.Register(action);
            }
            else
            {
                foreach (Property property in GetEntity().Properties.Where(item => item.PropertyType != PropertyType.Attribute))
                {
                    if (property.ForeignProperty == null)
                    {
                        continue;
                    }

                    IEnumerable <OGM> instances;
                    object            value = property.GetValue(this, null);
                    if (property.PropertyType == PropertyType.Lookup)
                    {
                        instances = new OGM[] { (OGM)value }
                    }
                    ;
                    else
                    {
                        instances = (IEnumerable <OGM>)value;
                    }

                    foreach (OGM instance in instances)
                    {
                        if (property.ForeignProperty.PropertyType == PropertyType.Lookup)
                        {
                            property.ForeignProperty.SetValue(instance, null);
                        }
                        else
                        {
                            EntityCollectionBase collection = (EntityCollectionBase)property.ForeignProperty.GetValue(instance, null);
                            action.ExecuteInMemory(collection);
                        }
                    }
                    property.SetValue(this, null);
                }
            }
        }
        public EntityCollectionBase(OGM parent, Property property)
        {
            if (property.Relationship is null)
            {
                throw new NotSupportedException("The property is not a relationship property.");
            }

            Parent        = parent;
            Relationship  = property.Relationship;
            Direction     = property.Direction;
            DbTransaction = Transaction.Current;

            switch (Direction)
            {
            case DirectionEnum.In:
                ParentEntity    = Relationship.InEntity;
                ParentProperty  = Relationship.InProperty;
                ForeignEntity   = Relationship.OutEntity;
                ForeignProperty = Relationship.OutProperty;
                break;

            case DirectionEnum.Out:
                ParentEntity    = Relationship.OutEntity;
                ParentProperty  = Relationship.OutProperty;
                ForeignEntity   = Relationship.InEntity;
                ForeignProperty = Relationship.InProperty;
                break;

            case DirectionEnum.None:
                throw new NotSupportedException("You cannot initialize a collection without a direction.");

            default:
                throw new NotImplementedException();
            }

            IsLoaded = false;

            if (parent is OGMImpl || (parent is DynamicEntity && ((DynamicEntity)parent).ShouldExecute))
            {
                DbTransaction?.Register(this);
            }
        }
Example #9
0
 internal ClearRelationshipsAction(RelationshipPersistenceProvider persistenceProvider, OGM item)
     : base(persistenceProvider, null, item, item)
 {
 }
Example #10
0
 internal TimeDependentRemoveUnmanagedRelationshipAction(RelationshipPersistenceProvider persistenceProvider, Relationship relationship, OGM inItem, OGM outItem, DateTime?startDate)
     : base(persistenceProvider, relationship, inItem, outItem, startDate)
 {
 }
 public abstract bool RelationshipExists(Property foreignProperty, OGM instance);
Example #12
0
 internal override RelationshipAction RemoveAction(OGM item, DateTime?moment)
 {
     return(new RemoveRelationshipAction(RelationshipPersistenceProvider, Relationship, InItem(item), OutItem(item)));
 }
 internal RelationshipAction AddUnmanagedAction(OGM item, DateTime?startDate, DateTime?endDate)
 {
     return(new TimeDependentAddUnmanagedRelationshipAction(RelationshipPersistenceProvider, Relationship, InItem(item), OutItem(item), startDate, endDate));
 }
 internal override CollectionItem NewCollectionItem(OGM parent, OGM item, DateTime?startDate, DateTime?endDate)
 {
     return(new CollectionItem <TEntity>(parent, (TEntity)item, startDate, endDate));
 }
Example #15
0
 internal AddRelationshipAction(RelationshipPersistenceProvider persistenceProvider, Relationship relationship, OGM inItem, OGM outItem)
     : base(persistenceProvider, relationship, inItem, outItem)
 {
 }
Example #16
0
 internal override int[] IndexOf(OGM item)
 {
     return(InnerData.IndexOf((TEntity)item));
 }
Example #17
0
 internal TimeDependentAddUnmanagedRelationshipAction(RelationshipPersistenceProvider persistenceProvider, Relationship relationship, OGM inItem, OGM outItem, DateTime?startDate, DateTime?endDate)
     : base(persistenceProvider, relationship, inItem, outItem, startDate)
 {
     EndDate = (endDate.HasValue) ? endDate.Value : DateTime.MaxValue;
 }
 internal abstract CollectionItem NewCollectionItem(OGM parent, OGM item, DateTime?startDate, DateTime?endDate);
 internal abstract RelationshipAction AddAction(OGM item, DateTime?moment);
Example #20
0
 protected EntityCollectionBase(OGM parent, Property property, Action <TEntity>?eagerLoadLogic) : base(parent, property)
 {
     EagerLoadLogic = eagerLoadLogic;
 }
 internal UnidentifiedPropertyCollection(OGM parent)
 {
     Parent = (OGMImpl)parent;
 }
 public abstract void Load(OGM item);
 public EntityTimeCollection(OGM parent, Property property, Action <TEntity>?eagerLoadLogic = null) : base(parent, property, eagerLoadLogic)
 {
 }
 public abstract void Insert(OGM item);
 internal override RelationshipAction AddAction(OGM item, DateTime?moment)
 {
     return(new TimeDependentAddRelationshipAction(RelationshipPersistenceProvider, Relationship, InItem(item), OutItem(item), moment));
 }
 public abstract void Update(OGM item);
Example #27
0
 protected bool RelationshipExists(Property foreignProperty, OGM instance)
 {
     return(PersistenceProvider.NodePersistenceProvider.RelationshipExists(foreignProperty, instance));
 }
 public abstract void Delete(OGM item);
 internal TimeDependentRemoveRelationshipAction(RelationshipPersistenceProvider persistenceProvider, Relationship relationship, OGM inItem, OGM outItem, DateTime?moment)
     : base(persistenceProvider, relationship, inItem, outItem, moment)
 {
 }
 public abstract void ForceDelete(OGM item);