[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao ...
Christian Bauer
christian at hibernate.org
Wed Jan 9 10:59:23 EST 2008
User: cbauer
Date: 08/01/09 10:59:23
Modified: examples/wiki/src/main/org/jboss/seam/wiki/core/dao
UserDAO.java WikiNodeFactory.java WikiNodeDAO.java
Log:
JBSEAM-2397 and JBSEAM-1883 - implemented trashcan feature and more reliable update of 2nd level cache and lucene index
Revision Changes Path
1.11 +4 -1 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UserDAO.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/UserDAO.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- UserDAO.java 19 Dec 2007 04:29:26 -0000 1.10
+++ UserDAO.java 9 Jan 2008 15:59:23 -0000 1.11
@@ -68,11 +68,14 @@
User adminUser = (User) Component.getInstance("adminUser");
- //TODO: This needs to do much more work now that we can't have the FK names anymore in the @MappedSuperclass WikiNode. Hibernate sucks. Shit.
entityManager.createQuery("update WikiNode n set n.createdBy = :admin where n.createdBy = :user")
.setParameter("admin", entityManager.merge(adminUser))
.setParameter("user", user)
.executeUpdate();
+ entityManager.createQuery("update WikiNode n set n.lastModifiedBy = :admin where n.lastModifiedBy = :user")
+ .setParameter("admin", entityManager.merge(adminUser))
+ .setParameter("user", user)
+ .executeUpdate();
}
1.16 +47 -0 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.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- WikiNodeFactory.java 30 Dec 2007 02:33:21 -0000 1.15
+++ WikiNodeFactory.java 9 Jan 2008 15:59:23 -0000 1.16
@@ -43,6 +43,7 @@
return (WikiDirectory) entityManager
.createQuery("select d from WikiDirectory d left join fetch d.feed where d.parent is null")
.setHint("org.hibernate.comment", "Loading wikiRoot")
+ .setHint("org.hibernate.cacheable", true)
.getSingleResult();
} catch (RuntimeException ex) {
throw new RuntimeException("You need to INSERT at least one parentless directory into the database", ex);
@@ -57,6 +58,7 @@
.createQuery("select d from WikiDocument d where d.id = :id")
.setParameter("id", wikiPreferences.getDefaultDocumentId())
.setHint("org.hibernate.comment", "Loading wikiStart")
+ .setHint("org.hibernate.cacheable", true)
.getSingleResult();
} catch (EntityNotFoundException ex) {
} catch (NoResultException ex) {
@@ -76,6 +78,7 @@
.createQuery("select d from WikiDirectory d left join fetch d.feed where d.id = :id")
.setParameter("id", wikiroot.getId())
.setHint("org.hibernate.comment", "Loading wikiRootRestricted")
+ .setHint("org.hibernate.cacheable", true)
.getSingleResult();
} catch (RuntimeException ex) {
throw new RuntimeException("You need to INSERT at least one parentless directory into the database", ex);
@@ -90,6 +93,7 @@
.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.comment", "Loading memberArea")
+ .setHint("org.hibernate.cacheable", true)
.getSingleResult();
} catch (RuntimeException ex) {
FacesMessages.instance().addFromResourceBundleOrDefault(
@@ -102,6 +106,48 @@
}
}
+ @Factory(value = "trashArea", scope = ScopeType.PAGE, autoCreate = true)
+ public WikiDirectory loadTrashArea() {
+ String trashAreaName = ((WikiPreferences)Preferences.getInstance("Wiki")).getTrashArea();
+ try {
+ return (WikiDirectory) entityManager
+ .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(trashAreaName) )
+ .setHint("org.hibernate.comment", "Loading trashArea")
+ .setHint("org.hibernate.cacheable", true)
+ .getSingleResult();
+ } catch (RuntimeException ex) {
+ FacesMessages.instance().addFromResourceBundleOrDefault(
+ FacesMessage.SEVERITY_ERROR,
+ "lacewiki.msg.TrashAreaNotFound",
+ "Could not find trash area with name {0} - your configuration is broken, please change it.",
+ trashAreaName
+ );
+ return null;
+ }
+ }
+
+ @Factory(value = "helpArea", scope = ScopeType.PAGE, autoCreate = true)
+ public WikiDirectory loadHelpArea() {
+ String helpAreaName = ((WikiPreferences)Preferences.getInstance("Wiki")).getHelpArea();
+ try {
+ return (WikiDirectory) entityManager
+ .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(helpAreaName) )
+ .setHint("org.hibernate.comment", "Loading trashArea")
+ .setHint("org.hibernate.cacheable", true)
+ .getSingleResult();
+ } catch (RuntimeException ex) {
+ FacesMessages.instance().addFromResourceBundleOrDefault(
+ FacesMessage.SEVERITY_ERROR,
+ "lacewiki.msg.HelpAreaNotFound",
+ "Could not find help area with name {0} - your configuration is broken, please change it.",
+ helpAreaName
+ );
+ return null;
+ }
+ }
+
@Factory(value = "linkProtocolMap", scope = ScopeType.CONVERSATION, autoCreate = true)
public Map<String, LinkProtocol> loadLinkProtocols() {
Map<String, LinkProtocol> linkProtocols = new TreeMap<String, LinkProtocol>();
@@ -109,6 +155,7 @@
List<Object[]> result = entityManager
.createQuery("select lp.prefix, lp from LinkProtocol lp order by lp.prefix asc")
.setHint("org.hibernate.comment", "Loading link protocols")
+ .setHint("org.hibernate.cacheable", true)
.getResultList();
for (Object[] objects : result) {
linkProtocols.put((String)objects[0], (LinkProtocol)objects[1]);
1.5 +75 -0 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.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- WikiNodeDAO.java 1 Jan 2008 13:00:44 -0000 1.4
+++ WikiNodeDAO.java 9 Jan 2008 15:59:23 -0000 1.5
@@ -54,6 +54,7 @@
.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) {
@@ -67,6 +68,7 @@
.createQuery("select n from WikiNode n where n.id in (:idList)")
.setParameter("idList", ids)
.setHint("org.hibernate.comment", "Find wikinodes by id list")
+ .setHint("org.hibernate.cacheable", true)
.getResultList();
}
@@ -81,6 +83,7 @@
.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) {
@@ -114,6 +117,7 @@
.createQuery(queryString.toString())
.setHint("org.hibernate.comment", "Find wikinode children order by "+orderByProperty)
.setParameter("parent", node)
+ .setHint("org.hibernate.cacheable", true)
.setFirstResult(firstResult)
.setMaxResults(maxResults)
.getResultList();
@@ -124,6 +128,7 @@
.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)
+ .setHint("org.hibernate.cacheable", true)
.getResultList();
}
@@ -133,6 +138,7 @@
.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) {
@@ -170,6 +176,7 @@
org.hibernate.Query nsQuery = getSession(true).createQuery(queryString.toString());
nsQuery.setParameter("doc", document);
nsQuery.setComment("Find wikicomments (tree)");
+ nsQuery.setCacheable(true);
nsQuery.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] objects, String[] aliases) {
@@ -186,12 +193,53 @@
return nsQuery.list();
}
+ public List<WikiComment> findWikiCommentSubtree(WikiComment root) {
+ return findWikiCommentSubtree(root, false);
+ }
+
+ public List<WikiComment> findWikiCommentSubtree(WikiComment root, boolean orderByLevelDescending) {
+ NestedSetQueryBuilder queryBuilder;
+ if (orderByLevelDescending) {
+ queryBuilder = new NestedSetQueryBuilder(new WikiComment(), false, false) {
+ public String getOrderByClause() {
+ StringBuilder clause = new StringBuilder();
+ clause.append("count(").append(NestedSetQueryBuilder.NODE_ALIAS).append(".id) desc");
+ return clause.toString();
+ }
+ };
+ } else {
+ queryBuilder = new NestedSetQueryBuilder(new WikiComment(), false, false);
+ }
+
+ org.hibernate.Query nsQuery = getSession(true).createQuery(queryBuilder.getSimpleQuery());
+ nsQuery.setParameter("nsThread", root.getNodeInfo().getNsThread());
+ nsQuery.setParameter("nsLeft", root.getNodeInfo().getNsLeft());
+ nsQuery.setParameter("nsRight", root.getNodeInfo().getNsRight());
+ nsQuery.setComment("Find wikicomments subtree");
+ nsQuery.setCacheable(true);
+ nsQuery.setResultTransformer(
+ new ResultTransformer() {
+ public Object transformTuple(Object[] objects, String[] aliases) {
+ Long level = (Long)objects[0];
+ WikiComment c = (WikiComment)objects[1];
+ c.setLevel(level);
+ return c;
+ }
+ public List transformList(List list) {
+ return list;
+ }
+ }
+ );
+ return nsQuery.list();
+ }
+
public WikiFile findWikiFile(Long fileId) {
try {
return (WikiFile) restrictedEntityManager
.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) {
@@ -210,6 +258,7 @@
.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) {
@@ -223,6 +272,7 @@
.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) {
@@ -238,6 +288,7 @@
.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) {
@@ -252,6 +303,7 @@
.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) {
@@ -263,6 +315,7 @@
return restrictedEntityManager.createQuery("select d from WikiDocument d where d.parent = :dir order by d.createdOn asc")
.setParameter("dir", directory)
.setHint("org.hibernate.comment", "Find documents of directory")
+ .setHint("org.hibernate.cacheable", true)
.getResultList();
}
@@ -277,6 +330,7 @@
.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) {
@@ -289,6 +343,7 @@
return (List<WikiDocument>)restrictedEntityManager
.createQuery("select d from WikiDocument d where d.lastModifiedOn is not null order by d.lastModifiedOn desc")
.setHint("org.hibernate.comment", "Find documents order by lastModified")
+ .setHint("org.hibernate.cacheable", true)
.setMaxResults(maxResults)
.getResultList();
}
@@ -301,6 +356,7 @@
" where sibling.parent = current.parent and current = :current and not sibling = :current" +
" and sibling."+ byProperty + " " + (previousOrNext ? "<=" : ">=") + "current."+byProperty +
" order by sibling." +byProperty + " " + (previousOrNext ? "desc" : "asc") )
+ .setHint("org.hibernate.cacheable", true)
.setMaxResults(1)
.setParameter("current", currentDocument)
.getSingleResult();
@@ -316,6 +372,7 @@
.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) {
@@ -327,6 +384,7 @@
return restrictedEntityManager.createQuery("select u from WikiUpload u where u.parent = :dir order by u.createdOn asc")
.setParameter("dir", directory)
.setHint("org.hibernate.comment", "Find uploads of directory")
+ .setHint("org.hibernate.cacheable", true)
.getResultList();
}
@@ -336,6 +394,20 @@
.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) {
+ }
+ return null;
+ }
+
+ public User findWikiDirectoryMemberHome(Long directoryId) {
+ try {
+ return (User) restrictedEntityManager
+ .createQuery("select u from User u where u.memberHome.id = :id")
+ .setParameter("id", directoryId)
+ .setHint("org.hibernate.comment", "Find user for directory member home by id")
.getSingleResult();
} catch (EntityNotFoundException ex) {
} catch (NoResultException ex) {
@@ -354,6 +426,7 @@
.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) {
@@ -367,6 +440,7 @@
.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) {
@@ -380,6 +454,7 @@
.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) {
More information about the jboss-cvs-commits
mailing list