[jboss-cvs] jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset ...

Christian Bauer christian at hibernate.org
Tue Dec 18 23:29:25 EST 2007


  User: cbauer  
  Date: 07/12/18 23:29:25

  Modified:    examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset      
                        NestedSetTests.java
  Added:       examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset      
                        TestItem.java TestDirectory.java TestFile.java
  Removed:     examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset      
                        Item.java ItemData.xml
  Log:
  Major rewrite of the most of the application
  
  Revision  Changes    Path
  1.7       +124 -314  jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset/NestedSetTests.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: NestedSetTests.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset/NestedSetTests.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- NestedSetTests.java	9 Nov 2007 15:18:13 -0000	1.6
  +++ NestedSetTests.java	19 Dec 2007 04:29:25 -0000	1.7
  @@ -6,16 +6,17 @@
    */
   package org.jboss.seam.wiki.test.nestedset;
   
  -import org.hibernate.Query;
  -import org.hibernate.StatelessSession;
  -import org.hibernate.ejb.HibernateEntityManagerFactory;
   import org.jboss.seam.log.Log;
   import org.jboss.seam.log.Logging;
  -import org.jboss.seam.wiki.core.nestedset.NestedSetNodeWrapper;
  -import org.jboss.seam.wiki.core.nestedset.NestedSetResultTransformer;
   import org.jboss.seam.wiki.test.util.DBUnitSeamTest;
  +import org.jboss.seam.wiki.core.nestedset.NestedSetNode;
  +import org.jboss.seam.wiki.core.nestedset.query.NestedSetQueryBuilder;
  +import org.jboss.seam.wiki.core.nestedset.query.NestedSetNodeWrapper;
  +import org.jboss.seam.wiki.core.nestedset.query.NestedSetResultTransformer;
   import org.testng.annotations.Test;
  -import org.dbunit.operation.DatabaseOperation;
  +import org.hibernate.Session;
  +import org.hibernate.Query;
  +import org.hibernate.ejb.HibernateEntityManagerFactory;
   
   import javax.persistence.EntityManager;
   import java.util.Comparator;
  @@ -25,13 +26,11 @@
       private Log log = Logging.getLog(NestedSetTests.class);
   
       protected void prepareDBUnitOperations() {
  -        beforeTestOperations.add(
  -                new DataSetOperation("org/jboss/seam/wiki/test/nestedset/ItemData.xml", DatabaseOperation.CLEAN_INSERT)
  -        );
  +        // Don't need any datasets
       }
   
       @Test
  -    public void createTree() throws Exception {
  +    public void insertDeleteOnTree() throws Exception {
   
           new FacesRequest("/") {
   
  @@ -44,384 +43,195 @@
                        / \
                       B   C
                          / \
  -                      D   E
  -                     /\
  -                    F  G
  +                      F1  F2
  +                     /  \
  +                 F1Sub F1DirA
  +                         |
  +                       F1DirB
                    */
  -                Item a = new Item("A");
  -                Item b = new Item("B");
  -                Item c = new Item("C");
  -                Item d = new Item("D");
  -                Item e = new Item("E");
  -                Item f = new Item("F");
  -                Item g = new Item("G");
  +                TestDirectory a = new TestDirectory("A");
  +                TestDirectory b = new TestDirectory("B");
  +                TestDirectory c = new TestDirectory("C");
   
                   a.addChild(b);
                   a.addChild(c);
   
  -                c.addChild(d);
  -                c.addChild(e);
  -
  -                c.addChild(d);
  -
  -                d.addChild(f);
  -                d.addChild(g);
  -
  -                // Cascading persist for children collection!
                   em.persist(a);
  +                em.persist(b);
  +                em.persist(c);
   
  -                getUserTransaction().commit();
  -                em.clear();
  -
  -                assert checkNestedSetNodeInMemory(a, a.getId(), 1, 14);
  -                assert checkNestedSetChildNodeInMemory(a, b);
  -                assert checkNestedSetChildNodeInMemory(a, c);
  -                assert checkNestedSetChildNodeInMemory(c, d);
  -                assert checkNestedSetChildNodeInMemory(c, e);
  -                assert checkNestedSetChildNodeInMemory(d, f);
  -                assert checkNestedSetChildNodeInMemory(d, g);
  -
  -                assert checkNestedSetNodeInDatabase("A", a.getId(), 1, 14);
  -                assert checkNestedSetChildNodeInDatabase("A", "B");
  -                assert checkNestedSetChildNodeInDatabase("A", "C");
  -                assert checkNestedSetChildNodeInDatabase("C", "D");
  -                assert checkNestedSetChildNodeInDatabase("C", "E");
  -                assert checkNestedSetChildNodeInDatabase("D", "F");
  -                assert checkNestedSetChildNodeInDatabase("D", "G");
  -
  -                displayNodeTree(getItemFromDatabase("A"));
  -            }
  -        }.run();
  -    }
  -
  -    @Test
  -    public void insertNode() throws Exception {
  +                em.flush();
   
  -        new FacesRequest("/") {
  +                TestFile f1 = new TestFile("F1");
  +                f1.setFilename("file1.txt");
  +                TestFile f2 = new TestFile("F2");
  +                f2.setFilename("file2.txt");
   
  -            protected void invokeApplication() throws Exception {
  +                b.addChild(f1);
  +                b.addChild(f2);
   
  -                EntityManager em = (EntityManager)getValue("#{entityManager}");
  +                em.persist(f1);
  +                em.persist(f2);
   
  -                /* Tree:
  -                      A
  -                     / \
  -                    B   C
  -                       / \
  -                      D   E
  -                     /\
  -                    F  G
  -                 */
  -                Item a = new Item("A");
  -                Item b = new Item("B");
  -                Item c = new Item("C");
  -                Item d = new Item("D");
  -                Item e = new Item("E");
  -                Item f = new Item("F");
  -                Item g = new Item("G");
  -
  -                a.addChild(b);
  -                a.addChild(c);
  +                em.flush();
   
  -                c.addChild(d);
  -                c.addChild(e);
  +                TestFile f1Subitem = new TestFile("F1Sub");
  +                f1Subitem.setFilename("f1subfile.txt");
  +                f1.addChild(f1Subitem);
  +                em.persist(f1Subitem);
   
  -                c.addChild(d);
  +                TestDirectory f1DirA = new TestDirectory("F1DirA");
  +                f1.addChild(f1DirA);
  +                em.persist(f1DirA);
   
  -                d.addChild(f);
  -                d.addChild(g);
  -
  -                // Cascading persist for children collection!
  -                em.persist(a);
  -
  -                getUserTransaction().commit();
  -                getUserTransaction().begin();
  -                em.joinTransaction();
  -
  -                /* Tree:
  -                      A
  -                     / \
  -                    B   C
  -                       / \
  -                      D   E
  -                     /\   |
  -                    F  G  H
  -                 */
  -
  -                Item h = new Item("H");
  -                e.addChild(h);
  -                em.persist(h);
  +                TestDirectory f1DirB = new TestDirectory("F1DirB");
  +                f1DirA.addChild(f1DirB);
  +                em.persist(f1DirB);
   
                   getUserTransaction().commit();
                   em.clear();
   
  -                assert checkNestedSetNodeInMemory(a, a.getId(), 1, 16);
  -                assert checkNestedSetChildNodeInMemory(a, b);
  -                assert checkNestedSetChildNodeInMemory(a, c);
  -                assert checkNestedSetChildNodeInMemory(c, d);
  -                assert checkNestedSetChildNodeInMemory(c, e);
  -                assert checkNestedSetChildNodeInMemory(d, f);
  -                assert checkNestedSetChildNodeInMemory(d, g);
  -                assert checkNestedSetChildNodeInMemory(e, h);
  -
  -                assert checkNestedSetNodeInDatabase("A", a.getId(), 1, 16);
  -                assert checkNestedSetChildNodeInDatabase("A", "B");
  -                assert checkNestedSetChildNodeInDatabase("A", "C");
  -                assert checkNestedSetChildNodeInDatabase("C", "D");
  -                assert checkNestedSetChildNodeInDatabase("C", "E");
  -                assert checkNestedSetChildNodeInDatabase("D", "F");
  -                assert checkNestedSetChildNodeInDatabase("D", "G");
  -                assert checkNestedSetChildNodeInDatabase("E", "H");
  +                showDirTree("A");
  +                long firstThread = a.getNodeInfo().getNsThread();
  +                assert checkTestDirectoryInDatabase("A", firstThread, 1, 6);
  +                assert checkTestDirectoryInDatabase("B", firstThread, 2, 3);
  +                assert checkTestDirectoryInDatabase("C", firstThread, 4, 5);
   
  -                displayNodeTree(getItemFromDatabase("A"));
  -            }
  -        }.run();
  -    }
  -
  -    @Test
  -    public void deleteNode() throws Exception {
  -
  -        new FacesRequest("/") {
  -
  -            protected void invokeApplication() throws Exception {
  -
  -                EntityManager em = (EntityManager)getValue("#{entityManager}");
  +                showDirTree("F1DirA");
  +                long secondThread = f1DirA.getNodeInfo().getNsThread();
  +                assert checkTestDirectoryInDatabase("F1DirA", secondThread, 1, 4);
  +                assert checkTestDirectoryInDatabase("F1DirB", secondThread, 2, 3);
   
                   /* Tree:
                         A
  +                         /
  +                        B
                        / \
  -                    B   C
  +                      F1  F2
                          / \
  -                      D   E
  -                     /\
  -                    F  G
  +                 F1Sub F1DirA
  +                         |
  +                       F1DirB
                    */
  -                Item a = new Item("A");
  -                Item b = new Item("B");
  -                Item c = new Item("C");
  -                Item d = new Item("D");
  -                Item e = new Item("E");
  -                Item f = new Item("F");
  -                Item g = new Item("G");
  -
  -                a.addChild(b);
  -                a.addChild(c);
  -
  -                c.addChild(d);
  -                c.addChild(e);
  -
  -                c.addChild(d);
  -
  -                d.addChild(f);
  -                d.addChild(g);
  -
  -                // Cascading persist for children collection!
  -                em.persist(a);
  -
  -                getUserTransaction().commit();
                   getUserTransaction().begin();
                   em.joinTransaction();
   
  -                /* Tree:
  -                      A
  -                     / \
  -                    B   C
  -                        |
  -                        E
  -                 */
  +                TestDirectory dirToDelete = getTestDirectory( (Session)em.getDelegate(), "C");
   
  -                c.removeChild(d);
  -                em.remove(d);
  +                em.remove(dirToDelete);
   
                   getUserTransaction().commit();
                   em.clear();
   
  -                assert checkNestedSetNodeInMemory(a, a.getId(), 1, 8);
  -                assert checkNestedSetChildNodeInMemory(a, b);
  -                assert checkNestedSetChildNodeInMemory(a, c);
  -                assert checkNestedSetChildNodeInMemory(c, e);
  -
  -                assert checkNestedSetNodeInDatabase("A", a.getId(), 1, 8);
  -                assert checkNestedSetChildNodeInDatabase("A", "B");
  -                assert checkNestedSetChildNodeInDatabase("A", "C");
  -                assert checkNestedSetChildNodeInDatabase("C", "E");
  -
  -                displayNodeTree(getItemFromDatabase("A"));
  -            }
  -        }.run();
  -    }
  -
  -    @Test
  -    public void deleteInsertNode() throws Exception {
  -
  -        new FacesRequest("/") {
  -
  -            protected void invokeApplication() throws Exception {
  -
  -                EntityManager em = (EntityManager)getValue("#{entityManager}");
  +                showDirTree("A");
  +                long thread = a.getNodeInfo().getNsThread();
  +                assert checkTestDirectoryInDatabase("A", thread, 1, 4);
  +                assert checkTestDirectoryInDatabase("B", thread, 2, 3);
   
                   /* Tree:
                         A
  -                     / \
  -                    B   C
  -                       / \
  -                      D   E
  -                     /\
  -                    F  G
  +                          |
  +                          B
  +                          |
  +                          F2
                    */
  -                Item a = new Item("A");
  -                Item b = new Item("B");
  -                Item c = new Item("C");
  -                Item d = new Item("D");
  -                Item e = new Item("E");
  -                Item f = new Item("F");
  -                Item g = new Item("G");
  -
  -                a.addChild(b);
  -                a.addChild(c);
  -
  -                c.addChild(d);
  -                c.addChild(e);
  -
  -                d.addChild(f);
  -                d.addChild(g);
  -
  -                // Cascading persist for children collection!
  -                em.persist(a);
   
  -                getUserTransaction().commit();
                   getUserTransaction().begin();
                   em.joinTransaction();
   
  -                /* Tree:
  -                      A
  -                     / \
  -                    B   C
  -                       / \
  -                      E   H
  -                 */
  +                TestFile fileToDelete = em.find(TestFile.class, f1.getId());
   
  -                c.removeChild(d);
  -                em.remove(d);
  -
  -                Item h = new Item("H");
  -                c.addChild(h);
  -                em.persist(h);
  +                em.remove(fileToDelete);
   
                   getUserTransaction().commit();
                   em.clear();
   
  -                assert checkNestedSetNodeInMemory(a, a.getId(), 1, 10);
  -                assert checkNestedSetChildNodeInMemory(a, b);
  -                assert checkNestedSetChildNodeInMemory(a, c);
  -                assert checkNestedSetChildNodeInMemory(c, e);
  -                assert checkNestedSetChildNodeInMemory(c, h);
  -
  -                assert checkNestedSetNodeInDatabase("A", a.getId(), 1, 10);
  -                assert checkNestedSetChildNodeInDatabase("A", "B");
  -                assert checkNestedSetChildNodeInDatabase("A", "C");
  -                assert checkNestedSetChildNodeInDatabase("C", "E");
  -                assert checkNestedSetChildNodeInDatabase("C", "H");
  +                assert getTestDirectory("F1DirA") == null;
  +                assert getTestDirectory("F1DirB") == null;
   
  -                displayNodeTree(getItemFromDatabase("A"));
               }
           }.run();
  -    }
  -
  -    /* ############################################################################################################## */
   
  -    private boolean checkNestedSetNodeInMemory(Item node, long thread, long left, long right) throws Exception {
  -        return node.getNsThread() == thread && node.getNsLeft() == left && node.getNsRight() == right;
       }
   
  -    private boolean checkNestedSetChildNodeInMemory(Item parent, Item node) throws Exception {
  -        return node.getNsThread().equals(parent.getNsThread()) && node.getNsLeft() > parent.getNsLeft() && node.getNsRight() < parent.getNsRight();
  -    }
  +    /* ############################################################################################################## */
   
  -    private boolean checkNestedSetNodeInDatabase(String itemName, long thread, long left, long right) throws Exception {
  -        return checkNestedSetNodeInMemory( getItemFromDatabase(itemName), thread, left, right);
  +    private boolean checkNestedSetNodeInMemory(NestedSetNode node, long thread, long left, long right) throws Exception {
  +        return node.getNodeInfo().getNsThread() == thread
  +                && node.getNodeInfo().getNsLeft() == left
  +                && node.getNodeInfo().getNsRight() == right;
       }
   
  -    private boolean checkNestedSetChildNodeInDatabase(String parentName, String itemName) throws Exception {
  -        return checkNestedSetChildNodeInMemory( getItemFromDatabase(parentName), getItemFromDatabase(itemName));
  +    private boolean checkTestDirectoryInDatabase(String dirName, long thread, long left, long right) throws Exception {
  +        return checkNestedSetNodeInMemory( getTestDirectory(dirName), thread, left, right);
       }
   
  -    private StatelessSession getStatelessSession() throws Exception {
  -        org.jboss.ejb3.entity.InjectedEntityManagerFactory jbossEMF =
  -                (org.jboss.ejb3.entity.InjectedEntityManagerFactory) getInitialContext().lookup("java:/entityManagerFactories/wiki");
  -        return ((HibernateEntityManagerFactory) jbossEMF.getDelegate()).getSessionFactory().openStatelessSession();
  +    private TestDirectory getTestDirectory(String dirName) throws Exception {
  +        Session session = getHibernateSession();
  +        TestDirectory dir = getTestDirectory(session, dirName);
  +        session.close();
  +        return dir;
       }
   
  -    private Item getItemFromDatabase(String itemName) throws Exception {
  -        StatelessSession ss = getStatelessSession();
  -        // TODO: EAGER loading of parent doesn't work with StatelessSession, only if I do it in the query...
  -        Item item = (Item) ss.createQuery("select i from Item i left join fetch i.parent where i.name = :name").setParameter("name", itemName).uniqueResult();
  -        ss.close();
  -        return item;
  +    private TestDirectory getTestDirectory(Session session, String dirName) throws Exception {
  +        return (TestDirectory) session
  +                .createQuery("select d from TestDirectory d where d.name = :name")
  +                .setParameter("name", dirName).uniqueResult();
       }
   
  -    private void displayNodeTree(Item startNode) throws Exception {
  +    private void showDirTree(String startDirName) throws Exception {
           if (log.isTraceEnabled()) {
   
  -            StatelessSession session = getStatelessSession();
  +            Session session = getHibernateSession();
   
  -            StringBuilder queryString = new StringBuilder();
  -
  -            queryString.append("select").append(" ");
  -            queryString.append("count(n1.id) as nestedSetNodeLevel").append(", ");
  -            queryString.append("n1 as nestedSetNode").append(" ");
  -            queryString.append("from ").append(startNode.getTreeSuperclassEntityName()).append(" n1, ");
  -            queryString.append(startNode.getTreeSuperclassEntityName()).append(" n2 ");
  -
  -            // TODO: EAGER loading of parent doesn't work with StatelessSession, only if I do it in the query...
  -            queryString.append("left join fetch n1.parent").append(" ");
  -
  -            queryString.append("where n1.nsThread = :thread and n2.nsThread = :thread").append(" ");
  -            queryString.append("and n1.nsLeft between n2.nsLeft and n2.nsRight").append(" ");
  -            queryString.append("and n2.nsLeft > :startLeft and n2.nsRight < :startRight").append(" ");
  -            queryString.append("group by").append(" ");
  -            for (int i = 0; i < startNode.getTreeSuperclassPropertiesForGrouping().length; i++) {
  -                queryString.append("n1.").append(startNode.getTreeSuperclassPropertiesForGrouping()[i]);
  -                if (i != startNode.getTreeSuperclassPropertiesForGrouping().length-1) queryString.append(", ");
  -            }
  -            queryString.append(" ");
  -            queryString.append("order by n1.nsLeft");
  -
  -            Query nestedSetQuery =  session.createQuery(queryString.toString());
  -            nestedSetQuery.setParameter("thread", startNode.getNsThread());
  -            nestedSetQuery.setParameter("startLeft", startNode.getNsLeft());
  -            nestedSetQuery.setParameter("startRight", startNode.getNsRight());
  -
  -            // This comparator sorts the Items by name!
  -            Comparator<NestedSetNodeWrapper<Item>> comp =
  -                new Comparator<NestedSetNodeWrapper<Item>>() {
  -                    public int compare(NestedSetNodeWrapper<Item> o, NestedSetNodeWrapper<Item> o2) {
  +            TestDirectory startDir = getTestDirectory(session, startDirName);
  +            if (startDir == null) {
  +                throw new RuntimeException("Could not find start dir with name: " + startDirName);
  +            }
  +
  +            NestedSetQueryBuilder nsQuery = new NestedSetQueryBuilder(startDir);
  +            Query nestedSetQuery =  session.createQuery(nsQuery.getSimpleQuery());
  +            nestedSetQuery.setParameter("nsThread", startDir.getNodeInfo().getNsThread());
  +            nestedSetQuery.setParameter("nsLeft", startDir.getNodeInfo().getNsLeft());
  +            nestedSetQuery.setParameter("nsRight", startDir.getNodeInfo().getNsRight());
  +
  +            // This comparator sorts the TestItems by name!
  +            Comparator<NestedSetNodeWrapper<TestDirectory>> comp =
  +                new Comparator<NestedSetNodeWrapper<TestDirectory>>() {
  +                    public int compare(NestedSetNodeWrapper<TestDirectory> o, NestedSetNodeWrapper<TestDirectory> o2) {
                           return o.getWrappedNode().getName().compareTo(o2.getWrappedNode().getName());
                       }
                   };
   
  -            NestedSetNodeWrapper<Item> startNodeWrapper = new NestedSetNodeWrapper<Item>(startNode, comp);
  -            nestedSetQuery.setResultTransformer( new NestedSetResultTransformer<Item>(startNodeWrapper) );
  +            NestedSetNodeWrapper<TestDirectory> startNodeWrapper
  +                    = new NestedSetNodeWrapper<TestDirectory>(startDir, comp);
  +            nestedSetQuery.setResultTransformer( new NestedSetResultTransformer<TestDirectory>(startNodeWrapper) );
   
               nestedSetQuery.list(); // Append all children hierarchically to the startNodeWrapper
   
               log.trace("######################################## TREE BEGIN #####################################################");
  -            displayNodes(startNodeWrapper);
  +            renderDirTree(startNodeWrapper);
               log.trace("######################################## TREE END   #####################################################");
   
               session.close();
           }
       }
  -    private void displayNodes(NestedSetNodeWrapper<Item> startNode) {
  +    private void renderDirTree(NestedSetNodeWrapper<TestDirectory> startNode) {
           StringBuilder levelMarkers = new StringBuilder();
           for (int i = 1; i <= startNode.getLevel(); i++) {
               levelMarkers.append("#");
           }
           log.trace(levelMarkers.toString() + " " + startNode);
  -        for (NestedSetNodeWrapper<Item> next : startNode.getWrappedChildren()) {
  -            displayNodes(next);
  +        for (NestedSetNodeWrapper<TestDirectory> next : startNode.getWrappedChildren()) {
  +            renderDirTree(next);
           }
       }
   
   
  +    private Session getHibernateSession() throws Exception {
  +        org.jboss.ejb3.entity.InjectedEntityManagerFactory jbossEMF =
  +                (org.jboss.ejb3.entity.InjectedEntityManagerFactory) getInitialContext().lookup("java:/entityManagerFactories/wiki");
  +        return ((HibernateEntityManagerFactory) jbossEMF.getDelegate()).getSessionFactory().openSession();
  +    }
  +
   }
  
  
  
  1.1      date: 2007/12/19 04:29:25;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset/TestItem.java
  
  Index: TestItem.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.nestedset;
  
  import javax.persistence.*;
  import java.util.HashSet;
  import java.util.Set;
  
  /**
   * Any subclass has parent or children. This is not really a composite pattern, because
   * even files can have children.
   *
   * @author Christian Bauer
   */
  @Entity
  @Table(name = "TEST_ITEM")
  @Inheritance(strategy = InheritanceType.JOINED)
  public abstract class TestItem {
  
      @Id
      @GeneratedValue(generator = "wikiSequenceGenerator")
      @Column(name = "ITEM_ID")
      private Long id;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "PARENT_ITEM_ID")
      @org.hibernate.annotations.ForeignKey(name = "TEST_FK_ITEM_PARENT_ITEM_ID") // Just a name for the FK constraint
      private TestItem parent;
  
      @OneToMany(mappedBy = "parent") // Don't cascade PERSIST here, updates of nested set nodes will be in the wrong order
      @org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
      private Set<TestItem> children = new HashSet<TestItem>();
  
      @Column(name = "ITEM_NAME", unique = true)
      private String name;
  
  
      public TestItem() {
          this(null);
      }
  
      public TestItem(String name) {
          this.name = name;
      }
  
      public Long getId() {
          return id;
      }
  
      public TestItem getParent() {
          return parent;
      }
  
      public Set<TestItem> getChildren() {
          return children;
      }
  
      public void addChild(TestItem child) {
          if (child.getParent() != null) {
              child.getParent().getChildren().remove(child);
          }
          getChildren().add(child);
          child.parent = this;
      }
  
      public TestItem removeChild(TestItem child) {
          getChildren().remove(child);
          child.parent = null;
          return child;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
  
      public String toString() {
          return "Item (" + getId() + "): " + getName();
      }
  
  }
  
  
  
  1.1      date: 2007/12/19 04:29:25;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset/TestDirectory.java
  
  Index: TestDirectory.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.nestedset;
  
  import org.jboss.seam.wiki.core.nestedset.*;
  
  import javax.persistence.*;
  import java.util.Date;
  
  @Entity
  @Table(name = "TEST_DIRECTORY")
  @org.hibernate.annotations.ForeignKey(name = "TEST_FK_DIRECTORY_ITEM_ID")
  @org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
  public class TestDirectory extends TestItem implements NestedSetNode<TestDirectory> {
  
      @Embedded
      private NestedSetNodeInfo<TestDirectory> nodeInfo;
  
      @Column(name = "JUST_A_DATE")
      private Date justADate = new Date();
  
      public TestDirectory() {
          super();
          nodeInfo = new NestedSetNodeInfo<TestDirectory>(this);
      }
  
      public TestDirectory(String name) {
          super(name);
          nodeInfo = new NestedSetNodeInfo<TestDirectory>(this);
      }
  
      public NestedSetNodeInfo<TestDirectory> getNodeInfo() {
          return nodeInfo;
      }
  
      public NestedSetNodeInfo<TestDirectory> getParentNodeInfo() {
          if (getParent() != null && TestDirectory.class.isAssignableFrom(getParent().getClass()))
              return ((TestDirectory)getParent()).getNodeInfo();
          return null;
      }
  
      public String[] getPropertiesForGroupingInQueries() {
          return new String[] { "parent", "name", "justADate"};
      }
  
      public String[] getLazyPropertiesForGroupingInQueries() {
          return new String[0];
      }
  
      public Date getJustADate() {
          return justADate;
      }
  
      public void setJustADate(Date justADate) {
          this.justADate = justADate;
      }
  }
  
  
  
  1.1      date: 2007/12/19 04:29:25;  author: cbauer;  state: Exp;jboss-seam/examples/wiki/src/test/org/jboss/seam/wiki/test/nestedset/TestFile.java
  
  Index: TestFile.java
  ===================================================================
  /*
   * JBoss, Home of Professional Open Source
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.seam.wiki.test.nestedset;
  
  import javax.persistence.Entity;
  import javax.persistence.Table;
  import javax.persistence.Column;
  
  @Entity
  @Table(name = "TEST_FILE")
  @org.hibernate.annotations.ForeignKey(name = "TEST_FK_FILE_ITEM_ID")
  @org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
  public class TestFile extends TestItem {
  
      public TestFile() {}
  
      public TestFile(String name) {
          super(name);
      }
  
      @Column(name = "FILENAME")
      private String filename;
  
      public String getFilename() {
          return filename;
      }
  
      public void setFilename(String filename) {
          this.filename = filename;
      }
  }
  
  
  



More information about the jboss-cvs-commits mailing list