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

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

            return(Parent);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 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);
                }
            }
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
 internal ClearRelationshipsAction(RelationshipPersistenceProvider persistenceProvider, OGM item)
     : base(persistenceProvider, null, item, item)
 {
 }
Ejemplo n.º 10
0
 internal TimeDependentRemoveUnmanagedRelationshipAction(RelationshipPersistenceProvider persistenceProvider, Relationship relationship, OGM inItem, OGM outItem, DateTime?startDate)
     : base(persistenceProvider, relationship, inItem, outItem, startDate)
 {
 }
Ejemplo n.º 11
0
 public abstract bool RelationshipExists(Property foreignProperty, OGM instance);
Ejemplo n.º 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));
 }
Ejemplo n.º 15
0
 internal AddRelationshipAction(RelationshipPersistenceProvider persistenceProvider, Relationship relationship, OGM inItem, OGM outItem)
     : base(persistenceProvider, relationship, inItem, outItem)
 {
 }
Ejemplo n.º 16
0
 internal override int[] IndexOf(OGM item)
 {
     return(InnerData.IndexOf((TEntity)item));
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 18
0
 internal abstract CollectionItem NewCollectionItem(OGM parent, OGM item, DateTime?startDate, DateTime?endDate);
Ejemplo n.º 19
0
 internal abstract RelationshipAction AddAction(OGM item, DateTime?moment);
Ejemplo n.º 20
0
 protected EntityCollectionBase(OGM parent, Property property, Action <TEntity>?eagerLoadLogic) : base(parent, property)
 {
     EagerLoadLogic = eagerLoadLogic;
 }
 internal UnidentifiedPropertyCollection(OGM parent)
 {
     Parent = (OGMImpl)parent;
 }
Ejemplo n.º 22
0
 public abstract void Load(OGM item);
 public EntityTimeCollection(OGM parent, Property property, Action <TEntity>?eagerLoadLogic = null) : base(parent, property, eagerLoadLogic)
 {
 }
Ejemplo n.º 24
0
 public abstract void Insert(OGM item);
 internal override RelationshipAction AddAction(OGM item, DateTime?moment)
 {
     return(new TimeDependentAddRelationshipAction(RelationshipPersistenceProvider, Relationship, InItem(item), OutItem(item), moment));
 }
Ejemplo n.º 26
0
 public abstract void Update(OGM item);
Ejemplo n.º 27
0
 protected bool RelationshipExists(Property foreignProperty, OGM instance)
 {
     return(PersistenceProvider.NodePersistenceProvider.RelationshipExists(foreignProperty, instance));
 }
Ejemplo n.º 28
0
 public abstract void Delete(OGM item);
 internal TimeDependentRemoveRelationshipAction(RelationshipPersistenceProvider persistenceProvider, Relationship relationship, OGM inItem, OGM outItem, DateTime?moment)
     : base(persistenceProvider, relationship, inItem, outItem, moment)
 {
 }
Ejemplo n.º 30
0
 public abstract void ForceDelete(OGM item);