[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao ...

Christian Bauer christian at hibernate.org
Sat Dec 29 21:33:21 EST 2007


  User: cbauer  
  Date: 07/12/29 21:33:21

  Modified:    examples/wiki/src/main/org/jboss/seam/wiki/core/dao   
                        WikiNodeFactory.java UserRoleAccessFactory.java
                        WikiNodeDAO.java
  Log:
  Complete overhaul of the preferences system
  
  Revision  Changes    Path
  1.15      +11 -10    jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/WikiNodeFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WikiNodeFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/WikiNodeFactory.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -b -r1.14 -r1.15
  --- WikiNodeFactory.java	19 Dec 2007 04:29:26 -0000	1.14
  +++ WikiNodeFactory.java	30 Dec 2007 02:33:21 -0000	1.15
  @@ -17,6 +17,7 @@
   import org.jboss.seam.wiki.core.model.WikiDirectory;
   import org.jboss.seam.wiki.core.model.WikiDocument;
   import org.jboss.seam.wiki.util.WikiUtil;
  +import org.jboss.seam.wiki.preferences.Preferences;
   
   import javax.faces.application.FacesMessage;
   import javax.persistence.EntityManager;
  @@ -40,8 +41,8 @@
       public WikiDirectory loadWikiRoot() {
           try {
               return (WikiDirectory) entityManager
  -                    .createQuery("select d from WikiDirectory d where d.parent is null")
  -                    .setHint("org.hibernate.cacheable", true)
  +                    .createQuery("select d from WikiDirectory d left join fetch d.feed where d.parent is null")
  +                    .setHint("org.hibernate.comment", "Loading wikiRoot")
                       .getSingleResult();
           } catch (RuntimeException ex) {
               throw new RuntimeException("You need to INSERT at least one parentless directory into the database", ex);
  @@ -50,12 +51,12 @@
   
       @Factory(value = "wikiStart", scope = ScopeType.PAGE, autoCreate = true)
       public WikiDocument loadWikiStart() {
  -        WikiPreferences wikiPreferences = (WikiPreferences) Component.getInstance("wikiPreferences");
  +        WikiPreferences wikiPreferences = (WikiPreferences) Preferences.getInstance("Wiki");
           try {
               return (WikiDocument) restrictedEntityManager
                       .createQuery("select d from WikiDocument d where d.id = :id")
                       .setParameter("id", wikiPreferences.getDefaultDocumentId())
  -                    .setHint("org.hibernate.cacheable", true)
  +                    .setHint("org.hibernate.comment", "Loading wikiStart")
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -72,9 +73,9 @@
   
           try {
               return (WikiDirectory) restrictedEntityManager
  -                    .createQuery("select d from WikiDirectory d where d.id = :id")
  +                    .createQuery("select d from WikiDirectory d left join fetch d.feed where d.id = :id")
                       .setParameter("id", wikiroot.getId())
  -                    .setHint("org.hibernate.cacheable", true)
  +                    .setHint("org.hibernate.comment", "Loading wikiRootRestricted")
                       .getSingleResult();
           } catch (RuntimeException ex) {
               throw new RuntimeException("You need to INSERT at least one parentless directory into the database", ex);
  @@ -83,12 +84,12 @@
   
       @Factory(value = "memberArea", scope = ScopeType.PAGE, autoCreate = true)
       public WikiDirectory loadMemberArea() {
  -        String memberAreaName = ((WikiPreferences)Component.getInstance("wikiPreferences")).getMemberArea();
  +        String memberAreaName = ((WikiPreferences)Preferences.getInstance("Wiki")).getMemberArea();
           try {
               return (WikiDirectory) entityManager
  -                    .createQuery("select d from WikiDirectory d where d.wikiname = :name and d.parent.parent is null")
  +                    .createQuery("select d from WikiDirectory d left join fetch d.feed where d.wikiname = :name and d.parent.parent is null")
                       .setParameter("name", WikiUtil.convertToWikiName(memberAreaName) )
  -                    .setHint("org.hibernate.cacheable", true)
  +                    .setHint("org.hibernate.comment", "Loading memberArea")
                       .getSingleResult();
           } catch (RuntimeException ex) {
               FacesMessages.instance().addFromResourceBundleOrDefault(
  @@ -107,7 +108,7 @@
           //noinspection unchecked
           List<Object[]> result = entityManager
                   .createQuery("select lp.prefix, lp from LinkProtocol lp order by lp.prefix asc")
  -                .setHint("org.hibernate.cacheable", true)
  +                .setHint("org.hibernate.comment", "Loading link protocols")
                   .getResultList();
           for (Object[] objects : result) {
               linkProtocols.put((String)objects[0], (LinkProtocol)objects[1]);
  
  
  
  1.8       +16 -9     jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserRoleAccessFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: UserRoleAccessFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserRoleAccessFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- UserRoleAccessFactory.java	19 Dec 2007 04:29:26 -0000	1.7
  +++ UserRoleAccessFactory.java	30 Dec 2007 02:33:21 -0000	1.8
  @@ -1,16 +1,17 @@
   package org.jboss.seam.wiki.core.dao;
   
   import org.jboss.seam.ScopeType;
  -import org.jboss.seam.Component;
  +import org.jboss.seam.annotations.*;
  +import org.jboss.seam.wiki.core.action.prefs.UserManagementPreferences;
   import org.jboss.seam.wiki.core.model.Role;
   import org.jboss.seam.wiki.core.model.User;
  -import org.jboss.seam.wiki.core.action.prefs.UserManagementPreferences;
  -import org.jboss.seam.annotations.*;
  +import org.jboss.seam.wiki.preferences.Preferences;
   
   import javax.persistence.EntityManager;
   import javax.persistence.NoResultException;
   import java.io.Serializable;
  -import java.util.*;
  +import java.util.ArrayList;
  +import java.util.List;
   
   @Name("userRoleAccessFactory")
   public class UserRoleAccessFactory implements Serializable {
  @@ -24,6 +25,7 @@
               User guestUser =
                       (User) entityManager
                               .createQuery("select u from User u left join fetch u.roles where u.username = '"+User.GUEST_USERNAME+"'")
  +                            .setHint("org.hibernate.cacheable", true)
                               .getSingleResult();
               if (guestUser.getRoles().size() > 1 || guestUser.getRoles().size() == 0) {
                   throw new RuntimeException("Your '"+User.GUEST_USERNAME+"' user has none or more than one role assigned, illegal database state");
  @@ -44,6 +46,7 @@
               User adminUser =
                       (User) entityManager
                               .createQuery("select u from User u left join fetch u.roles where u.username = '"+User.ADMIN_USERNAME+"'")
  +                            .setHint("org.hibernate.cacheable", true)
                               .getSingleResult();
               if (adminUser.getRoles().size() > 1 || adminUser.getRoles().size() == 0) {
                   throw new RuntimeException("Your '"+User.ADMIN_USERNAME+"' user has none or more than one role assigned, illegal database state");
  @@ -62,6 +65,7 @@
           try {
               return (Role) entityManager
                       .createQuery("select r from Role r where r.accessLevel = '"+Role.GUESTROLE_ACCESSLEVEL+"'")
  +                    .setHint("org.hibernate.cacheable", true)
                               .getSingleResult();
           } catch (NoResultException ex) {
               throw new RuntimeException("You need to INSERT a role with accesslevel '"+Role.GUESTROLE_ACCESSLEVEL+"' (the guest role) into the database");
  @@ -73,6 +77,7 @@
           try {
               return (Role) entityManager
                       .createQuery("select r from Role r where r.accessLevel = '"+Role.ADMINROLE_ACCESSLEVEL+"'")
  +                    .setHint("org.hibernate.cacheable", true)
                               .getSingleResult();
           } catch (NoResultException ex) {
               throw new RuntimeException("You need to INSERT a role with accesslevel '"+Role.ADMINROLE_ACCESSLEVEL+"' (the admin role) into the database");
  @@ -81,10 +86,11 @@
   
       @Factory(value = "newUserDefaultRole", scope = ScopeType.SESSION)
       public Role getDefaultRole() {
  -        UserManagementPreferences userPrefs = (UserManagementPreferences) Component.getInstance("userManagementPreferences");
  +        UserManagementPreferences userPrefs = (UserManagementPreferences) Preferences.getInstance("UserManagement");
           try {
               return (Role) entityManager
                       .createQuery("select r from Role r where r.name = '"+userPrefs.getNewUserInRole()+"'")
  +                    .setHint("org.hibernate.cacheable", true)
                               .getSingleResult();
           } catch (NoResultException ex) {
               throw new RuntimeException("Configured default role for new users '"+userPrefs.getNewUserInRole()+"' not found");
  @@ -110,6 +116,7 @@
               if (roles == null) {
                   roles = (List<Role>) entityManager
                           .createQuery("select r from Role r order by r.accessLevel desc, r.displayName asc")
  +                        .setHint("org.hibernate.cacheable", true)
                               .getResultList();
                   if (roles.size() < 2)
                       throw new RuntimeException("You need to INSERT at least two roles into the database, " +
  
  
  
  1.3       +10 -24    jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/WikiNodeDAO.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WikiNodeDAO.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/WikiNodeDAO.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- WikiNodeDAO.java	20 Dec 2007 12:23:05 -0000	1.2
  +++ WikiNodeDAO.java	30 Dec 2007 02:33:21 -0000	1.3
  @@ -54,7 +54,6 @@
                       .createQuery("select n from WikiNode n where n.id = :id")
                       .setParameter("id", nodeId)
                       .setHint("org.hibernate.comment", "Find wikinode by id")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -82,7 +81,6 @@
                       .setParameter("areaNumber", areaNumber)
                       .setParameter("wikiname", wikiname)
                       .setHint("org.hibernate.comment", "Find node in area")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -104,7 +102,7 @@
           return null;
       }
   
  -    public List<WikiNode> findChildren(WikiNode node, String orderByProperty, boolean orderAscending, long firstResult, long maxResults) {
  +    public List<WikiNode> findChildren(WikiNode node, String orderByProperty, boolean orderAscending, int firstResult, int maxResults) {
           // Sanitize input
           orderByProperty = orderByProperty.replaceAll("[^a-zA-Z0-9]", "");
   
  @@ -116,14 +114,14 @@
                   .createQuery(queryString.toString())
                   .setHint("org.hibernate.comment", "Find wikinode children order by "+orderByProperty)
                   .setParameter("parent", node)
  -                .setFirstResult(new Long(firstResult).intValue())
  -                .setMaxResults(new Long(maxResults).intValue())
  +                .setFirstResult(firstResult)
  +                .setMaxResults(maxResults)
                   .getResultList();
       }
   
       public List<WikiDirectory> findChildWikiDirectories(WikiDirectory dir) {
           return restrictedEntityManager
  -                .createQuery("select d from WikiDirectory d where d.parent = :parent")
  +                .createQuery("select d from WikiDirectory d left join fetch d.feed where d.parent = :parent")
                   .setHint("org.hibernate.comment", "Find wikinode children directories")
                   .setParameter("parent", dir)
                   .getResultList();
  @@ -135,7 +133,6 @@
                       .createQuery("select c from WikiComment c where c.id = :id")
                       .setParameter("id", commentId)
                       .setHint("org.hibernate.comment", "Find comment by id")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -148,7 +145,7 @@
       }
   
       public List<WikiComment> findWikiCommentsFlat(WikiDocument document, boolean orderbyDateAscending) {
  -        return findWikiComments(document, false, true);
  +        return findWikiComments(document, false, orderbyDateAscending);
       }
   
       private List<WikiComment> findWikiComments(WikiDocument document, final boolean threaded, boolean unthreadedAscending) {
  @@ -195,7 +192,6 @@
                       .createQuery("select f from WikiFile f where f.id = :id")
                       .setParameter("id", fileId)
                       .setHint("org.hibernate.comment", "Find wikifile by id")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -214,7 +210,6 @@
                       .setParameter("areaNumber", areaNumber)
                       .setParameter("wikiname", wikiname)
                       .setHint("org.hibernate.comment", "Find wikifile in area")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -228,7 +223,6 @@
                       .createQuery("select d from WikiDocument d where d.id = :id")
                       .setParameter("id", documentId)
                       .setHint("org.hibernate.comment", "Find document by id")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -244,7 +238,6 @@
                       .createQuery("select d.defaultFile from WikiDirectory d where d = :dir")
                       .setParameter("dir", directory)
                       .setHint("org.hibernate.comment", "Find default file")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -259,7 +252,6 @@
                       .createQuery("select doc from WikiDocument doc, WikiDirectory d where d = :dir and doc.id = d.defaultFile.id")
                       .setParameter("dir", directory)
                       .setHint("org.hibernate.comment", "Find default doc")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -285,7 +277,6 @@
                       .setParameter("areaNumber", areaNumber)
                       .setParameter("wikiname", wikiname)
                       .setHint("org.hibernate.comment", "Find document in area")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -308,7 +299,6 @@
                       .createQuery("select u from WikiUpload u where u.id = :id")
                       .setParameter("id", uploadId)
                       .setHint("org.hibernate.comment", "Find upload by id")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -326,10 +316,9 @@
       public WikiDirectory findWikiDirectory(Long directoryId) {
           try {
               return (WikiDirectory) restrictedEntityManager
  -                    .createQuery("select d from WikiDirectory d where d.id = :id")
  +                    .createQuery("select d from WikiDirectory d left join fetch d.feed where d.id = :id")
                       .setParameter("id", directoryId)
                       .setHint("org.hibernate.comment", "Find directory by id")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -344,11 +333,10 @@
       public WikiDirectory findWikiDirectoryInArea(Long areaNumber, String wikiname, EntityManager em) {
           try {
               return (WikiDirectory) em
  -                    .createQuery("select d from WikiDirectory d where d.areaNumber = :areaNumber and d.wikiname = :wikiname")
  +                    .createQuery("select d from WikiDirectory d left join fetch d.feed where d.areaNumber = :areaNumber and d.wikiname = :wikiname")
                       .setParameter("areaNumber", areaNumber)
                       .setParameter("wikiname", wikiname)
                       .setHint("org.hibernate.comment", "Find directory in area")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -359,10 +347,9 @@
       public WikiDirectory findArea(String wikiname) {
           try {
               return (WikiDirectory) restrictedEntityManager
  -                    .createQuery("select d from WikiDirectory d, WikiDirectory r where r.parent is null and d.parent = r and d.wikiname = :wikiname")
  +                    .createQuery("select d from WikiDirectory d left join fetch d.feed, WikiDirectory r where r.parent is null and d.parent = r and d.wikiname = :wikiname")
                       .setParameter("wikiname", wikiname)
                       .setHint("org.hibernate.comment", "Find area by wikiname")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -373,10 +360,9 @@
       public WikiDirectory findArea(Long areaNumber) {
           try {
               return (WikiDirectory) restrictedEntityManager
  -                    .createQuery("select d from WikiDirectory d, WikiDirectory r where r.parent is null and d.parent = r and d.areaNumber = :areaNumber")
  +                    .createQuery("select d from WikiDirectory d left join fetch d.feed, WikiDirectory r where r.parent is null and d.parent = r and d.areaNumber = :areaNumber")
                       .setParameter("areaNumber", areaNumber)
                       .setHint("org.hibernate.comment", "Find area by area number")
  -                    .setHint("org.hibernate.cacheable", true)
                       .getSingleResult();
           } catch (EntityNotFoundException ex) {
           } catch (NoResultException ex) {
  @@ -402,6 +388,7 @@
           if (file == null || file.getId() == null) return 0l;
           return (Long)getSession(true).createQuery("select count(f) from " + file.getHistoricalEntityName() + " f where f.id = :fileId")
                                     .setParameter("fileId", file.getId())
  +                                  .setCacheable(true)
                                     .uniqueResult();
       }
   
  @@ -526,7 +513,6 @@
           if (maxDepth != null) nestedSetQuery.setParameter("maxDepth", maxDepth);
   
           nestedSetQuery.setComment("Appending nested set nodes to startnode: " + startNode.getId());
  -        nestedSetQuery.setCacheable(true);
   
           nestedSetQuery.setResultTransformer(transformer);
           nestedSetQuery.list(); // Append all children hierarchically to the transformers rootWrapper
  
  
  



More information about the jboss-cvs-commits mailing list