From portal-commits at lists.jboss.org Fri Dec 28 16:57:29 2007 Content-Type: multipart/mixed; boundary="===============3368372198479478654==" MIME-Version: 1.0 From: portal-commits at lists.jboss.org To: portal-commits at lists.jboss.org Subject: [portal-commits] JBoss Portal SVN: r9400 - in branches/presentation/presentation/src/main/org/jboss/portal/presentation: test/model and 1 other directory. Date: Fri, 28 Dec 2007 16:57:29 -0500 Message-ID: --===============3368372198479478654== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: julien(a)jboss.com Date: 2007-12-28 16:57:29 -0500 (Fri, 28 Dec 2007) New Revision: 9400 Modified: branches/presentation/presentation/src/main/org/jboss/portal/presentatio= n/impl/model/container/AssociationContext.java branches/presentation/presentation/src/main/org/jboss/portal/presentatio= n/impl/model/container/UIObjectContainer.java branches/presentation/presentation/src/main/org/jboss/portal/presentatio= n/test/model/ModelTestCase.java Log: - test a bit more the refresh operation and improve its implementation Modified: branches/presentation/presentation/src/main/org/jboss/portal/pres= entation/impl/model/container/AssociationContext.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/impl/model/container/AssociationContext.java 2007-12-28 00:39:56 UTC (re= v 9399) +++ branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/impl/model/container/AssociationContext.java 2007-12-28 21:57:29 UTC (re= v 9400) @@ -32,6 +32,7 @@ import java.util.HashSet; import java.util.Collection; import java.util.AbstractSet; +import java.util.ArrayList; = /** * @author Julien Viet @@ -86,16 +87,21 @@ /** . */ private UIContainerObject related; = - /** . */ - private UIContainerObject ref; + /** The context pointing at us via a OneToMany. */ + private Set refs; = private ManyToOne() { this.loaded =3D false; this.related =3D null; - this.ref =3D null; + this.refs =3D new HashSet(); } = + Set getReferences() + { + return refs; + } + boolean isLoaded() { return loaded; @@ -296,7 +302,7 @@ /** . */ private Set relateds; = - /** . */ + /** The contexts pointing at us via a ManyToOne. */ private Set refs; = private OneToMany() @@ -322,6 +328,8 @@ { throw new IllegalArgumentException("No null child accepted"); } + + // for (UIContainerObject r : relateds) { if (related.getId().equals(r.getId())) @@ -329,7 +337,9 @@ throw new IllegalStateException("Cannot add duplicate"); } } - relateds.add(related); + + // + attach(related); } = void setLoadedRelateds(Set relateds) @@ -338,10 +348,21 @@ { throw new IllegalStateException("Not loaded"); } - this.relateds =3D relateds; + + // + for (UIContainerObject related : new ArrayList= (this.relateds)) + { + detach(related); + } + + // + for (UIContainerObject related : relateds) + { + attach(related); + } } = - void removeLoadedRelated(String relatedId) + UIContainerObject removeLoadedRelated(String relatedId) { if (!isLoaded()) { @@ -351,17 +372,19 @@ { throw new IllegalArgumentException(); } - for (Iterator i =3D relateds.iterator();i.hasN= ext();) + + // + for (UIContainerObject related : relateds) { - UIContainerObject child =3D i.next(); - - // - if (relatedId.equals(child.getId())) + if (relatedId.equals(related.getId())) { - i.remove(); - break; + detach(related); + return related; } } + + // + throw new AssertionError("BUG"); } = Collection getRelateds() @@ -369,6 +392,11 @@ return list; } = + Set getReferences() + { + return refs; + } + /** * Load the related side. * @@ -381,6 +409,42 @@ = protected abstract ManyToOne getManyToOne(UIContainerObject related); = + private void detach(UIContainerObject related) + { + ManyToOne manyToOne =3D getManyToOne(related); + + // + ObjectContext owner =3D getOwner(); + + // + if (!manyToOne.refs.contains(owner)) + { + throw new AssertionError("BUG"); + } + + // + manyToOne.refs.remove(owner); + relateds.remove(related); + } + + private void attach(UIContainerObject related) + { + ManyToOne manyToOne =3D getManyToOne(related); + + // + ObjectContext owner =3D getOwner(); + + // + if (manyToOne.refs.contains(owner)) + { + throw new AssertionError("Context already referenced by the pr= ovided object"); + } + + // + manyToOne.refs.add(owner); + relateds.add(related); + } + private void load() { ObjectContext owner =3D getOwner(); @@ -388,9 +452,6 @@ // try { - Set relateds =3D new HashSet(); - - // for (StructuralObject relatedSO : doLoad()) { UIContainerObject related =3D owner.container.get(relatedSO= ); @@ -415,11 +476,10 @@ } = // - relateds.add(related); + attach(related); } = // - this.relateds =3D relateds; this.loaded =3D true; } catch (StateException e) Modified: branches/presentation/presentation/src/main/org/jboss/portal/pres= entation/impl/model/container/UIObjectContainer.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/impl/model/container/UIObjectContainer.java 2007-12-28 00:39:56 UTC (rev= 9399) +++ branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/impl/model/container/UIObjectContainer.java 2007-12-28 21:57:29 UTC (rev= 9400) @@ -402,117 +402,99 @@ ObjectContext context =3D (ObjectContext)object.getContext(); = // - switch (context.status) + if (context.status =3D=3D UIObject.Status.INVALID) { - case VALID: - case STALE: - try + return; + } + + // + StructuralObject.Refresh refresh =3D null; + try + { + refresh =3D structuralStateContext.refresh(context.structuralO= bject); + } + catch (NoSuchStateException e) + { + context.status =3D UIObject.Status.INVALID; + return; + } + + // + boolean loaded =3D context.associationContext.children.isLoaded(); + boolean refreshChildren =3D scope.enterChildren(object, loaded); + + // Update the structural state + if (!context.structuralObject.compareTo(refresh.getObject())) + { + if (loaded) + { + // Take care of the added children + for (StructuralObject addedSO : refresh.getAddedChildren()) { - StructuralObject.Refresh refresh =3D structuralStateCont= ext.refresh(context.structuralObject); + UIContainerObject added =3D get(addedSO); = - // Update the structural state - if (!context.structuralObject.compareTo(refresh.getObjec= t())) + // + if (added !=3D null) { - boolean loaded =3D context.associationContext.childre= n.isLoaded(); + ObjectContext addedContext =3D (ObjectContext)added.g= etContext(); = - // - if (loaded) + // Find parent pointing at us and set as dirty + for (ObjectContext addedParentContext : addedContext.= associationContext.parent.getReferences()) { - boolean refreshChildren =3D scope.enterChildren(ob= ject, loaded); + addedParentContext.status =3D UIObject.Status.STAL= E; + } = - // The new list of children - Set children =3D new HashSet(); + // Update parent if it was loaded + if (addedContext.associationContext.parent.isLoaded()) + { + addedContext.associationContext.parent.setLoadedRe= lated(object); + } + } + else + { + added =3D create(addedSO); = - // Take care of the added children - for (StructuralObject addedSO : refresh.getAddedCh= ildren()) - { - UIContainerObject added =3D get(addedSO); + // + attach(added); + } = - // - if (added !=3D null) - { - ObjectContext addedContext =3D (ObjectContex= t)added.getContext(); + // + context.associationContext.children.addLoadedRelated(add= ed); + } = - // Set the parent as stale if needed - if (addedContext.associationContext.parent.i= sLoaded()) - { - ObjectContext addedParentContext =3D (Obj= ectContext)addedContext.associationContext.parent.getLoadedRelated().getCon= text(); + // + for (StructuralObject staleSO : refresh.getStaleChildren().= values()) + { + UIContainerObject stale =3D get(staleSO); = - // Mark the parent as stale - addedParentContext.status =3D UIObject.St= atus.STALE; + // It must be here as it is loaded + ObjectContext staleContext =3D (ObjectContext)stale.getC= ontext(); = - // - addedParentContext.associationContext.par= ent.setLoadedRelated(get(context.structuralObject)); - } - } - else - { - added =3D create(addedSO); - - // - attach(added); - } - - // - children.add(added); - } - - // - for (String validId : refresh.getValidChildren()) - { - UIContainerObject valid =3D get(validId); - - // It must be here... - children.add(valid); - } - - - // - for (StructuralObject staleSO : refresh.getStaleCh= ildren().values()) - { - UIContainerObject stale =3D get(staleSO); - - // - ObjectContext staleContext =3D (ObjectContext)s= tale.getContext(); - - // Mark as stale - staleContext.status =3D UIObject.Status.STALE; - - // - children.add(stale); - } - - // Removals - for (String removedId : refresh.getRemovedChildren= ()) - { - UIContainerObject removed =3D get(removedId); - - // - if (removed !=3D null) - { - // We should try to now if it is somehow ref= erenced by someone that is not us - // i.e it has been already be moved somewher= e else - throw new NotYetImplemented(); - } - } - - // Update state - context.structuralObject =3D refresh.getObject(); - context.status =3D UIObject.Status.VALID; - context.associationContext.children.setLoadedRelat= eds(children); - } - } + // Mark as stale + staleContext.status =3D UIObject.Status.STALE; } - catch (NoSuchStateException e) + + // Removals + for (String removedId : refresh.getRemovedChildren()) { - context.status =3D UIObject.Status.INVALID; + UIContainerObject removed =3D context.associationContext= .children.removeLoadedRelated(removedId); } = - // - break; - case INVALID: + // Update state + context.structuralObject =3D refresh.getObject(); + context.status =3D UIObject.Status.VALID; + } } = + // Recursively refresh children + if (refreshChildren) + { + for (UIContainerObject child : context.associationContext.chil= dren.getRelateds()) + { + refresh(child, scope); + } + } + // = // Modified: branches/presentation/presentation/src/main/org/jboss/portal/pres= entation/test/model/ModelTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/test/model/ModelTestCase.java 2007-12-28 00:39:56 UTC (rev 9399) +++ branches/presentation/presentation/src/main/org/jboss/portal/presentati= on/test/model/ModelTestCase.java 2007-12-28 21:57:29 UTC (rev 9400) @@ -781,7 +781,7 @@ = // Load fully the context 1 UIContext context1 =3D createContext(); - loadDescendants(context1); + loadSubTree(context1); = // Concurrent move UIContext context2 =3D createContext(); @@ -791,11 +791,86 @@ context1.getChild("bar").refresh(); } = - private void loadDescendants(UIObject object) + public void testRefreshAfterConcurrentMove2() throws Exception { + MockObject mockRoot =3D model.getRoot(); + + MockObject mockFoo =3D mockRoot.addChild("foo", MockObject.Type.PORT= AL); + MockObject mockBar =3D mockRoot.addChild("bar", MockObject.Type.PORT= AL); + + MockObject mockFooJuu =3D mockFoo.addChild("juu", MockObject.Type.PA= GE); + MockObject mockFooDaa =3D mockFoo.addChild("daa", MockObject.Type.PA= GE); + + MockObject mockBarDaa =3D mockBar.addChild("daa", MockObject.Type.PA= GE); + + // Load fully the context 1 + UIContext context1 =3D createContext(); + loadSubTree(context1); + + // Concurrent move + UIContext context2 =3D createContext(); + context2.getChild("foo").getChild("juu").move(context2.getChild("bar= ")); + + // + context1.getChild("foo").refresh(); + } + + public void testPartialRefreshAfterConcurrentMove() throws Exception + { + MockObject mockRoot =3D model.getRoot(); + + MockObject mockFoo =3D mockRoot.addChild("foo", MockObject.Type.PORT= AL); + MockObject mockBar =3D mockRoot.addChild("bar", MockObject.Type.PORT= AL); + MockObject mockJuu =3D mockFoo.addChild("juu", MockObject.Type.PAGE); + + // Load fully the context 1 + UIContext context1 =3D createContext(); + loadSubTree(context1); + UIObject foo1 =3D context1.getChild("foo"); + UIObject juu1 =3D foo1.getChild("juu"); + UIObject bar1 =3D context1.getChild("bar"); + + // Load fully the context 2 + UIContext context2 =3D createContext(); + loadSubTree(context2); + UIObject foo2 =3D context2.getChild("foo"); + UIObject juu2 =3D foo2.getChild("juu"); + UIObject bar2 =3D context2.getChild("bar"); + + // Load fully the context 3 + UIContext context3 =3D createContext(); + loadSubTree(context3); + UIObject foo3 =3D context3.getChild("foo"); + UIObject juu3 =3D foo3.getChild("juu"); + UIObject bar3 =3D context3.getChild("bar"); + + // Concurrent move + UIContext context =3D createContext(); + context.getChild("foo").getChild("juu").move(context.getChild("bar")= ); + + // + foo1.refresh(CRAWLER); + assertEquals(UIObject.Status.VALID, foo1.getStatus()); + assertEquals(0, foo1.getChildren().size()); + + // + bar2.refresh(CRAWLER); + assertEquals(UIObject.Status.STALE, foo2.getStatus()); + assertEquals(UIObject.Status.VALID, bar2.getStatus()); + assertEquals(Tools.toSet(juu2), new HashSet(bar2.getChildr= en())); + + // + context3.refresh(CRAWLER); + assertEquals(UIObject.Status.VALID, foo3.getStatus()); + assertEquals(UIObject.Status.VALID, bar3.getStatus()); + assertEquals(Tools.toSet(juu3), new HashSet(bar3.getChildr= en())); + } + + private void loadSubTree(UIObject object) + { for (UIObject child : object.getChildren()) { - loadDescendants(child); + loadSubTree(child); } } = @@ -831,4 +906,22 @@ assertEquals(Collections.singleton(fooDaa), new HashSet(fo= oChildren)); assertEquals(Tools.toSet(barDaa, fooJuu), new HashSet(barC= hildren)); } + + private static final UIObject.Visitor CRAWLER =3D new UIObject.Visitor() + { + public boolean enterObject(UIObject object) + { + return true; + } + + public void leaveObject(UIObject object) + { + } + + public boolean enterChildren(UIObject object, boolean loaded) + { + return loaded; + } + }; + } --===============3368372198479478654==--