コード例 #1
0
        private void TstStore()
        {
            StartReplication();
            Pilot    object1           = new Pilot("John Cleese", 42);
            IDrsUUID uuid              = new DrsUUIDImpl(new Db4oUUID(15, BSignatureBytes));
            IReplicationReference @ref = new ReplicationReferenceImpl("ignoredSinceInOtherProvider"
                                                                      , uuid, 1);

            A().Provider().ReferenceNewObject(object1, @ref, null, null);
            A().Provider().StoreReplica(object1);
            IReplicationReference reference = A().Provider().ProduceReferenceByUUID(uuid, object1
                                                                                    .GetType());

            Assert.AreEqual(reference, A().Provider().ProduceReference(object1, null, null));
            Assert.AreEqual(object1, reference.Object());
            CommitReplication();
            StartReplication();
            IEnumerator storedObjects = A().Provider().GetStoredObjects(typeof(Pilot)).GetEnumerator
                                            ();
            Pilot reloaded = (Pilot)Next(storedObjects);

            Assert.IsFalse(storedObjects.MoveNext());
            reference = A().Provider().ProduceReferenceByUUID(uuid, object1.GetType());
            Assert.AreEqual(reference, A().Provider().ProduceReference(reloaded, null, null));
            reloaded.SetName("i am updated");
            A().Provider().StoreReplica(reloaded);
            A().Provider().ClearAllReferences();
            CommitReplication();
            StartReplication();
            reference = A().Provider().ProduceReferenceByUUID(uuid, reloaded.GetType());
            Assert.AreEqual("i am updated", ((Pilot)reference.Object()).Name());
            CommitReplication();
            A().Provider().DeleteAllInstances(typeof(Pilot));
            A().Provider().Commit();
        }
コード例 #2
0
        private void TstRollback()
        {
            if (!A().Provider().SupportsRollback())
            {
                return;
            }
            if (!B().Provider().SupportsRollback())
            {
                return;
            }
            StartReplication();
            Pilot    object1           = new Pilot("Albert Kwan", 25);
            IDrsUUID uuid              = new DrsUUIDImpl(new Db4oUUID(5678, BSignatureBytes));
            IReplicationReference @ref = new ReplicationReferenceImpl(object1, uuid, 1);

            A().Provider().ReferenceNewObject(object1, @ref, null, null);
            A().Provider().StoreReplica(object1);
            Assert.IsFalse(A().Provider().WasModifiedSinceLastReplication(@ref));
            A().Provider().RollbackReplication();
            A().Provider().StartReplicationTransaction(BSignature);
            Assert.IsNull(A().Provider().ProduceReference(object1, null, null));
            IReplicationReference byUUID = A().Provider().ProduceReferenceByUUID(uuid, object1
                                                                                 .GetType());

            Assert.IsNull(byUUID);
            A().Provider().RollbackReplication();
            B().Provider().RollbackReplication();
        }