Ejemplo n.º 1
0
        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()));
            }
        }
Ejemplo n.º 2
0
        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()));
            }
        }
Ejemplo n.º 3
0
        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()));
            }
        }