public static Db4objects.Drs.Db4o.ReplicationRecord QueryForReplicationRecord(ObjectContainerBase
                                                                               container, Transaction trans, Db4oDatabase younger, Db4oDatabase older)
 {
     container.ShowInternalClasses(true);
     try
     {
         IQuery q = container.Query(trans);
         q.Constrain(typeof(Db4objects.Drs.Db4o.ReplicationRecord));
         q.Descend("_youngerPeer").Constrain(younger).Identity();
         q.Descend("_olderPeer").Constrain(older).Identity();
         IObjectSet objectSet = q.Execute();
         if (objectSet.HasNext())
         {
             Db4objects.Drs.Db4o.ReplicationRecord replicationRecord = (Db4objects.Drs.Db4o.ReplicationRecord
                                                                        )objectSet.Next();
             container.Activate(replicationRecord, int.MaxValue);
             return(replicationRecord);
         }
         return(null);
     }
     finally
     {
         container.ShowInternalClasses(false);
     }
 }
Beispiel #2
0
        public static Db4objects.Drs.Db4o.ReplicationRecord BeginReplication(Transaction
                                                                             transA, Transaction transB)
        {
            ObjectContainerBase peerA = transA.Container();
            ObjectContainerBase peerB = transB.Container();
            Db4oDatabase        dbA   = ((IInternalObjectContainer)peerA).Identity();
            Db4oDatabase        dbB   = ((IInternalObjectContainer)peerB).Identity();

            dbB.Bind(transA);
            dbA.Bind(transB);
            Db4oDatabase younger = null;
            Db4oDatabase older   = null;

            if (dbA.IsOlderThan(dbB))
            {
                younger = dbB;
                older   = dbA;
            }
            else
            {
                younger = dbA;
                older   = dbB;
            }
            Db4objects.Drs.Db4o.ReplicationRecord rrA = QueryForReplicationRecord(peerA, transA
                                                                                  , younger, older);
            Db4objects.Drs.Db4o.ReplicationRecord rrB = QueryForReplicationRecord(peerB, transB
                                                                                  , younger, older);
            if (rrA == null)
            {
                if (rrB == null)
                {
                    return(new Db4objects.Drs.Db4o.ReplicationRecord(younger, older));
                }
                rrB.Store(peerA);
                return(rrB);
            }
            if (rrB == null)
            {
                rrA.Store(peerB);
                return(rrA);
            }
            if (rrA != rrB)
            {
                peerB.ShowInternalClasses(true);
                try
                {
                    int id = peerB.GetID(transB, rrB);
                    peerB.Bind(transB, rrA, id);
                }
                finally
                {
                    peerB.ShowInternalClasses(false);
                }
            }
            return(rrA);
        }