Example #1
0
        protected override void SynchronizeImpl()
        {
            ISerializableObject source = StateOwner.SourceObject;
            ISerializableObject sink   = StateOwner.SinkObject;

            CopyUtils.PlainCopy(StateOwner.SinkSerializer, KeyCarrier, sink, _fieldLock, true);
            CopyUtils.PlainCopy(StateOwner.SinkSerializer, source, sink, _fieldLock, false);

            StateOwner.SinkSerializer.Connector.UpdatePlain(sink);

            _sourceSyncItem.Hashcode = SyncContainer.ComputeHashCode(StateOwner.SourceSerializer.Target, source);
            StateOwner.SyncSerializer.Connector.Save(_sourceSyncItem);
            SyncItem sinkSyncItem = _sourceSyncItem.CounterPart;

            sinkSyncItem.Hashcode = SyncContainer.ComputeHashCode(StateOwner.SinkSerializer.Target, sink);
            StateOwner.SyncSerializer.Connector.Save(sinkSyncItem);

            StateOwner.UpdateFieldStates(StateOwner.SourceSerializer.Target, _sourceSyncItem, source);
            StateOwner.UpdateFieldStates(StateOwner.SinkSerializer.Target, sinkSyncItem, sink);
        }
Example #2
0
        internal void Analyze()
        {
            SyncItem            sourceSyncItem = FetchSyncItem(_sourceGuid);
            SyncItem            sinkSyncItem;
            ISerializableObject source = FetchObject(_sourceSerializer, _sourceGuid);


            if (sourceSyncItem == null)//In der Synchronisationstabelle gibt es keinen korrepondierenden Eintrag
            {
                #if DEBUG
                logger.Debug(source.GetType().Name + ", guid=" + AttributeWorker.RowGuid(source) + " is not synchronized and will be inserted");
                #endif

                SyncState = new InsertState(this);
            }
            else //in der Synchronisationstabelle ist ein Eintrag vorhanden
            {
                sinkSyncItem = sourceSyncItem.CounterPart;
                _sinkGuid    = sinkSyncItem.SyncGuid;

                ISerializableObject sink = FetchObject(_sinkSerializer, _sinkGuid); //Das korrepondierende Objekt wird aus der Zieldatenbankgeholt

                if (sink == null)                                                   //Wenn es nicht vorhanden ist wurde es gelöscht
                {
                    #if DEBUG
                    logger.Debug(sourceSyncItem.ClassID + ", guid=" + AttributeWorker.RowGuid(source) + " does not exist, the conflict has to be resolved");
                    #endif

                    SyncState = new DeletedState(this, sourceSyncItem);
                }
                else
                {
                    String h1           = sinkSyncItem.Hashcode;
                    String sinkHashCode = ComputeHashCode(_sinkSerializer.Target, sink);


                    if (h1 != sinkHashCode)//Änderung der Daten in der Zieldatenbank--warum ist das schon ein Konflikt?
                    {
                        #if DEBUG
                        logger.Debug(sourceSyncItem.ClassID + ", guid=" + AttributeWorker.RowGuid(source) + " is involved in a conflict, which has to be resolved");
                        #endif
                        SyncState = new ConflictState(this, sourceSyncItem);
                    }
                    else //zieldatenbank unverändert
                    {
                        String sourceHashCode = ComputeHashCode(SourceSerializer.Target, source);

                        if (sourceHashCode == sourceSyncItem.Hashcode)//Quelldatenbank unverändert
                        {
                            #if DEBUG
                            logger.Debug(sourceSyncItem.ClassID + ", guid=" + AttributeWorker.RowGuid(source) + " has not changed and will not be synchronized");
                            #endif
                            SyncState = new IgnoreState(this);
                        }
                        else//Quelldatenbank verändert-Zieldatenbank unverändert ->update
                        {
                            #if DEBUG
                            logger.Debug(sourceSyncItem.ClassID + ", guid=" + AttributeWorker.RowGuid(source) + " has changed on the sourceside and will be updated");
                            #endif
                            SyncState = new UpdateState(this, sourceSyncItem);
                        }
                    }
                }
            }

            AttributeWorker   w   = AttributeWorker.GetInstance(_sinkSerializer.Target);
            IList <FieldInfo> fis = w.GetFieldByAttribute <CheckForeingKeyConstraintAttribute>(_synchronizedType);


            foreach (FieldInfo fi in fis)
            {
                Object val = fi.GetValue(source);
                if (val == null)
                {
                    continue;
                }

                CheckForeingKeyConstraintAttribute attr = w.GetAttribute <CheckForeingKeyConstraintAttribute>(fi);
                String table  = attr.UnmappedTable;
                String column = attr.ExternColumn;
                if (column == null)
                {
                    column = w.GetColumnMapping(fi);
                }

                if (!_sinkSerializer.Connector.Exists(column, val, table))
                {
                    //Hier kann man einen neuen Status einführen, der dieses Problem abfängt
                    throw new InvalidOperationException("Insertion of " + _synchronizedType.Name + " will fail. Unmapped foreign key " + column + "=" + val + " does not exist in target database!");
                }
            }
        }
Example #3
0
 public DeletedState(SyncContainer owner, SyncItem sourceSyncItem)
     : base(owner, sourceSyncItem)
 {
 }
Example #4
0
 public ConflictState(SyncContainer owner, SyncItem sourceSyncItem) : base(owner)
 {
     _sourceSyncItem = sourceSyncItem;
 }
Example #5
0
 internal ConflictResolvedState(SyncContainer owner, ISerializableObject resolved, SyncItem sourceSyncItem, SyncState previous)
     : base(owner, sourceSyncItem, previous)
 {
     _resolved = resolved;
 }
Example #6
0
 public ConflictResolvedState(SyncContainer owner, ISerializableObject resolved, SyncItem sourceSyncItem)
     : base(owner, sourceSyncItem)
 {
     _resolved = resolved;
 }
Example #7
0
 internal UpdateState(SyncContainer owner, SyncItem sourceSyncItem, SyncState previous)
     : base(owner, previous)
 {
     _sourceSyncItem = sourceSyncItem;
     _fieldLock      = new FieldLock(_sourceSyncItem.GetType());
 }
 public ConflictState(SyncContainer owner, SyncItem sourceSyncItem)
     : base(owner)
 {
     _sourceSyncItem = sourceSyncItem;
 }
Example #9
0
 public UpdateState(SyncContainer owner, SyncItem sourceSyncItem)
     : base(owner)
 {
     _sourceSyncItem = sourceSyncItem;
     _fieldLock      = new FieldLock(_sourceSyncItem.GetType());
 }
 internal UpdateState(SyncContainer owner, SyncItem sourceSyncItem, SyncState previous)
     : base(owner, previous)
 {
     _sourceSyncItem = sourceSyncItem;
     _fieldLock = new FieldLock(_sourceSyncItem.GetType());
 }
 public UpdateState(SyncContainer owner, SyncItem sourceSyncItem)
     : base(owner)
 {
     _sourceSyncItem = sourceSyncItem;
     _fieldLock = new FieldLock(_sourceSyncItem.GetType());
 }
 internal ConflictResolvedState(SyncContainer owner, ISerializableObject resolved, SyncItem sourceSyncItem, SyncState previous)
     : base(owner, sourceSyncItem, previous)
 {
     _resolved = resolved;
 }
 public ConflictResolvedState(SyncContainer owner, ISerializableObject resolved, SyncItem sourceSyncItem)
     : base(owner, sourceSyncItem)
 {
     _resolved = resolved;
 }
 public DeletedState(SyncContainer owner, SyncItem sourceSyncItem)
     : base(owner, sourceSyncItem)
 {
 }