/// <summary> /// Gets the items with specified <paramref name="state"/>. /// </summary> /// <param name="state">The state of items to get.</param> /// <returns>The sequence of items with specified state.</returns> public IEnumerable <EntityState> GetItems(PersistenceState state) { foreach (var item in GetContainer(state)) { yield return(item); } }
public Client(PersistenceState persistenceState) { Id = new Id(persistenceState.Id); Name = new Name(persistenceState.Name); PhoneNumber = new PhoneNumber(persistenceState.PhoneNumber); Email = new Email(persistenceState.Email); }
public Product(PersistenceState persistenceState) { Id = new Id(persistenceState.Id); Link = new Link(persistenceState.Link); Units = new Units(persistenceState.Units); AdditionalInformation = persistenceState.AdditionalInformation.Map(x => new AdditionalInformation(x)); PromotionCode = persistenceState.PromotionCode.Map(x => new PromotionCode(x)); }
private void ProcessRegistry(PersistenceState persistenceState) { foreach (var item in activeRegistry.GetItems(persistenceState)) { if (IsPinned(item)) { PinnedItems.Register(item); } else { PersistableItems.Register(item); } } }
/// <exception cref="ArgumentOutOfRangeException"><paramref name="state"/> is out of range.</exception> private HashSet <EntityState> GetContainer(PersistenceState state) { switch (state) { case PersistenceState.New: return(@new); case PersistenceState.Modified: return(modified); case PersistenceState.Removed: return(removed); default: throw new ArgumentOutOfRangeException("state"); } }
/// <summary> /// Gets entities that were changed in the current session, but were not /// saved to the database yet. /// </summary> /// <param name="persistenceState">Type of entity change.</param> /// <returns><see cref="EntityState"/>s with the specified <paramref name="persistenceState"/>.</returns> public IEnumerable <EntityState> GetChangedEntities(PersistenceState persistenceState) { return(Session.EntityChangeRegistry.GetItems(persistenceState)); }
void OGM.Save() { switch (PersistenceState) { case PersistenceState.New: throw new NotSupportedException(string.Format("You created an instance of {0}, but inside this transaction but did not set any properties. If you did this intentionally, you can call the method 'SetChanged' on the instance before committing the transaction.", GetEntity().Name)); case PersistenceState.HasUid: case PersistenceState.Loaded: break; case PersistenceState.NewAndChanged: PersistenceProvider.NodePersistenceProvider.Insert(this); PersistenceState = PersistenceState.Persisted; break; case PersistenceState.LoadedAndChanged: PersistenceProvider.NodePersistenceProvider.Update(this); PersistenceState = PersistenceState.Persisted; break; case PersistenceState.Persisted: break; case PersistenceState.Delete: PersistenceProvider.NodePersistenceProvider.Delete(this); PersistenceState = PersistenceState.Deleted; return; case PersistenceState.ForceDelete: PersistenceProvider.NodePersistenceProvider.ForceDelete(this); PersistenceState = PersistenceState.Deleted; return; case PersistenceState.OutOfScope: case PersistenceState.Error: throw new InvalidOperationException(string.Format("The {0} with key '{1}' cannot be saved because it's state was {2}.", GetEntity().Name, GetKey() ?? "<null>", PersistenceState.ToString())); case PersistenceState.DoesntExist: throw new InvalidOperationException($"{GetEntity().Name} with key {GetKey()?.ToString() ?? "<NULL>"} couldn't be loaded from the database."); default: throw new NotImplementedException(string.Format("The {0} with key '{1}' has an invalid/unknown state {2}.", GetEntity().Name, GetKey() ?? "<null>", PersistenceState.ToString())); } }
public void Delete() { switch (PersistenceState) { case PersistenceState.New: case PersistenceState.NewAndChanged: PersistenceState = PersistenceState.Deleted; ExecuteAction(new ClearRelationshipsAction(RunningTransaction.RelationshipPersistenceProvider, null, this, this)); break; case PersistenceState.HasUid: case PersistenceState.Loaded: case PersistenceState.LoadedAndChanged: PersistenceState = PersistenceState.Delete; ExecuteAction(new ClearRelationshipsAction(RunningTransaction.RelationshipPersistenceProvider, null, this, this)); break; case PersistenceState.Delete: case PersistenceState.ForceDelete: break; case PersistenceState.OutOfScope: throw new InvalidOperationException("The transaction for this object has already ended."); case PersistenceState.Persisted: if (DbTransaction != Transaction.RunningTransaction) { throw new InvalidOperationException("This object was already flushed to the data store."); } break; case PersistenceState.Error: throw new InvalidOperationException("The object suffered an unexpected failure."); case PersistenceState.DoesntExist: throw new InvalidOperationException($"{GetEntity().Name} with key {GetKey()?.ToString() ?? "<NULL>"} couldn't be loaded from the database."); default: throw new NotImplementedException(string.Format("The PersistenceState '{0}' is not yet implemented.", PersistenceState.ToString())); } }
private List <T> Load <T>(Entity entity, NodeEventArgs args, RawResult result, Transaction trans) where T : class, OGM { IReadOnlyList <Entity> concretes = entity.GetConcreteClasses(); List <T> items = new List <T>(); foreach (var record in result) { var node = record[0].As <RawNode>(); if (node == null) { continue; } var key = node.Properties[entity.Key.Name]; Entity?concrete = null; if (entity.IsAbstract) { if (entity.NodeType != null) { string label = node.Properties[entity.NodeTypeName].As <string>(); concrete = concretes.FirstOrDefault(item => item.Label.Name == label); } if (concrete == null) { concrete = GetEntity(entity.Parent, node.Labels); } if (concrete == null) { throw new KeyNotFoundException($"Unable to find the concrete class for entity {entity.Name}, labels in DB are: {string.Join(", ", node.Labels)}."); } } else { concrete = entity; } T?wrapper = (T?)Transaction.RunningTransaction.GetEntityByKey(concrete.Name, key); if (wrapper == null) { wrapper = Activator <T>(concrete); wrapper.SetKey(key); args.Sender = wrapper; args = entity.RaiseOnNodeLoaded(trans, args, node.Id, node.Labels, (Dictionary <string, object?>)node.Properties); wrapper.SetData(args.Properties !); wrapper.PersistenceState = PersistenceState.Loaded; } else { args.Sender = wrapper; args = entity.RaiseOnNodeLoaded(trans, args, node.Id, node.Labels, (Dictionary <string, object?>)node.Properties); PersistenceState tmp = wrapper.PersistenceState; if (tmp == PersistenceState.HasUid || tmp == PersistenceState.Loaded || tmp == PersistenceState.Persisted) { wrapper.SetData(args.Properties !); wrapper.PersistenceState = PersistenceState.Loaded; } } items.Add(wrapper); } entity.RaiseOnBatchFinished(trans, args); return(items); }
/// <inheritdoc/> protected override void Invalidate() { persistenceState = PersistenceState.Synchronized; isVersionInfoUpdated = false; base.Invalidate(); }
/// <inheritdoc/> protected override void Refresh() { persistenceState = PersistenceState.Synchronized; Tuple = null; Session.Handler.FetchEntityState(key); }
internal void SetPersistenceState(PersistenceState newState) { persistenceState = newState; }
private void LazyGet() { switch (PersistenceState) { case PersistenceState.New: case PersistenceState.NewAndChanged: break; case PersistenceState.HasUid: RunningTransaction.NodePersistenceProvider.Load(this); break; case PersistenceState.Loaded: case PersistenceState.LoadedAndChanged: case PersistenceState.OutOfScope: case PersistenceState.Persisted: case PersistenceState.Delete: case PersistenceState.ForceDelete: break; case PersistenceState.Deleted: throw new InvalidOperationException("The object has been deleted, you cannot make changes to it anymore."); case PersistenceState.Error: throw new InvalidOperationException("The object suffered an unexpected failure."); case PersistenceState.DoesntExist: throw new InvalidOperationException($"{GetEntity().Name} with key {GetKey()?.ToString() ?? "<NULL>"} couldn't be loaded from the database."); default: throw new NotImplementedException(string.Format("The PersistenceState '{0}' is not yet implemented.", PersistenceState.ToString())); } }
public Rejection(PersistenceState persistenceState) { dateTime = persistenceState.DateTime; reason = new RejectionReason(persistenceState.Reason);; }