From 2e7912869b0769b7175f6476a49dc3406a9176cc Mon Sep 17 00:00:00 2001 From: David Dykstal Date: Thu, 14 Sep 2006 18:57:10 +0000 Subject: [PATCH] bug 142743 - Problem was located in Host. It was not tagging itself as dirty for certain attribute changes. Moreover, it must also tag the containing SystemHostPool. The persistence framework has been fixed to allow changes in one object to propagate to another and Host now takes advantage of this. --- .../rse/core/model/RSEModelObject.java | 28 ++++++++++++++++- .../persistance/IRSEPersistableContainer.java | 31 +++++++++++++++++++ .../org/eclipse/rse/internal/model/Host.java | 20 +++++++++++- .../rse/internal/model/SystemHostPool.java | 2 -- 4 files changed, 77 insertions(+), 4 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEModelObject.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEModelObject.java index a9b14ff2276..60266973248 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEModelObject.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/model/RSEModelObject.java @@ -29,15 +29,23 @@ public abstract class RSEModelObject extends PropertySetContainer implements IRS protected boolean _wasRestored = false; + /* (non-Javadoc) + * @see org.eclipse.rse.core.persistance.IRSEPersistableContainer#isDirty() + */ public final boolean isDirty() { return _isDirty; } - public final void setDirty(boolean flag) + /* (non-Javadoc) + * @see org.eclipse.rse.core.persistance.IRSEPersistableContainer#setDirty(boolean) + */ + public void setDirty(boolean flag) { _isDirty = flag; } + + public final boolean wasRestored() @@ -54,4 +62,22 @@ public abstract class RSEModelObject extends PropertySetContainer implements IRS { return RSEModelResources.RESID_MODELOBJECTS_MODELOBJECT_DESCRIPTION; } + + /** + * Does a null-aware string comparison. Two strings that are + * null will compare equal. Otherwise the result is + * the same as s1.equals(s2), if s1 is not null. + * @param s1 The first string to compare + * @param s2 the second string + * @return true if the strings are equal or both null. + */ + protected boolean compareStrings(String s1, String s2) { + boolean result = false; + if (s1 == null) { + result = s1 == null; + } else { + result = s1.equals(s2); + } + return result; + } } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/persistance/IRSEPersistableContainer.java b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/persistance/IRSEPersistableContainer.java index 55115849526..b9df036c574 100644 --- a/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/persistance/IRSEPersistableContainer.java +++ b/rse/plugins/org.eclipse.rse.core/src/org/eclipse/rse/core/persistance/IRSEPersistableContainer.java @@ -18,11 +18,42 @@ package org.eclipse.rse.core.persistance; public interface IRSEPersistableContainer { + /** + * An object is dirty if a change has been made to it that requires + * it to be persisted. + * @return true if the object is dirty + */ public boolean isDirty(); + + /** + * An object is dirty if a change has been made to it that requires + * it to be persisted. Objects should usually mark themselves dirty + * when a persistable change is made. However, there may be a need + * to mark related objects dirty as well. + * Setting this value to false should be done only in the persistence + * manager after the object has been written to the DOM. + * @param flag true if the object must be persisted. + */ public void setDirty(boolean flag); + /** + * Request a persistence manager to persist this object. + * @return true if the object was persisted. + */ public boolean commit(); + /** + * An object was restored if it originated from a persistent form. + * @return true if the object was created from its persistent form, + * false if the object has never been persisted. + */ public boolean wasRestored(); + + /** + * The the "restored" state of the object. Only persistence managers + * should do this. + * @param flag true if the object was restored. + */ public void setWasRestored(boolean flag); + } \ No newline at end of file diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/Host.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/Host.java index 04c8aac9aa7..d2c1feb0df6 100644 --- a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/Host.java +++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/Host.java @@ -323,7 +323,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable newId = newId.toUpperCase(); if ((newId == null) || (newId.length()==0)) // a "clear" request? - { + { clearLocalDefaultUserId(); } else @@ -543,6 +543,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable */ public void setDescription(String newDescription) { + setDirty(!compareStrings(description, newDescription)); description = newDescription; } @@ -559,6 +560,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable */ public void setPromptable(boolean newPromptable) { + setDirty(promptable != newPromptable); promptable = newPromptable; } @@ -583,6 +585,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable */ public void setOffline(boolean newOffline) { + setDirty(offline != newOffline); offline = newOffline; } @@ -591,6 +594,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable */ public void setSystemTypeGen(String newSystemType) { + setDirty(!compareStrings(systemType, newSystemType)); systemType = newSystemType; } @@ -599,6 +603,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable */ public void setAliasNameGen(String newAliasName) { + setDirty(!compareStrings(aliasName, newAliasName)); aliasName = newAliasName; } @@ -607,6 +612,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable */ public void setHostNameGen(String newHostName) { + setDirty(!compareStrings(hostName, newHostName)); hostName = newHostName; } @@ -623,6 +629,7 @@ public class Host extends RSEModelObject implements IHost, IAdaptable */ public void setDefaultUserIdGen(String newDefaultUserId) { + setDirty(!compareStrings(defaultUserId, newDefaultUserId)); defaultUserId = newDefaultUserId; } @@ -650,6 +657,17 @@ public class Host extends RSEModelObject implements IHost, IAdaptable return result.toString(); } + /* (non-Javadoc) + * @see org.eclipse.rse.core.model.RSEModelObject#setDirty(boolean) + */ + public void setDirty(boolean flag) { + super.setDirty(flag); + ISystemHostPool myPool = getHostPool(); + if (myPool != null && flag) { + myPool.setDirty(true); + } + }; + public boolean commit() { return RSEUIPlugin.getThePersistenceManager().commit(this); diff --git a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java index 68ed7b4e0a2..421e61c31bd 100644 --- a/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java +++ b/rse/plugins/org.eclipse.rse.ui/model/org/eclipse/rse/internal/model/SystemHostPool.java @@ -387,7 +387,6 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool public void deleteHost(IHost conn) { conn.deletingHost(); // let connection do any necessary cleanup - getHostList().remove(conn); setDirty(true); RSEUIPlugin.getThePersistenceManager().commit(conn.getSystemProfile()); @@ -409,7 +408,6 @@ public class SystemHostPool extends RSEModelObject implements ISystemHostPool { conn.setAliasName(newName); invalidateCache(); - conn.setDirty(true); commit(conn); }