[jboss-svn-commits] JBL Code SVN: r12474 - in labs/jbossforums/branches/forums110P26/forums/src: resources/portal-forums-sar and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 11 18:21:21 EDT 2007


Author: unibrew
Date: 2007-06-11 18:21:21 -0400 (Mon, 11 Jun 2007)
New Revision: 12474

Added:
   labs/jbossforums/branches/forums110P26/forums/src/resources/portal-forums-sar/ehcache.xml
Modified:
   labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/CategoryImpl.java
   labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/ForumImpl.java
   labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
   labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/PostImpl.java
   labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/PosterImpl.java
   labs/jbossforums/branches/forums110P26/forums/src/resources/portal-forums-sar/conf/hibernate/hibernate.cfg.xml
Log:
[JBFORUMS-140] Configuring secondary level cache and query cache for Forums.

Modified: labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/CategoryImpl.java
===================================================================
--- labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/CategoryImpl.java	2007-06-11 22:18:41 UTC (rev 12473)
+++ labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/CategoryImpl.java	2007-06-11 22:21:21 UTC (rev 12474)
@@ -25,6 +25,7 @@
  * @author <a href="mailto:boleslaw.dawidowicz at jboss.com">Boleslaw Dawidowicz</a>
  * @version $Revision: 916 $
  * @hibernate.class table="jbp_forums_categories"
+ * @hibernate.cache usage="read-write"
  */
 public class CategoryImpl
    implements Serializable,
@@ -51,6 +52,7 @@
     * table="jbp_forums_forums"
     * @hibernate.collection-key column="jbp_category_id"
     * @hibernate.collection-one-to-many class="org.jboss.portlet.forums.impl.ForumImpl"
+	* @hibernate.collection-cache usage="read-write"
     */
    public List getForums()
    {

Modified: labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/ForumImpl.java
===================================================================
--- labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/ForumImpl.java	2007-06-11 22:18:41 UTC (rev 12473)
+++ labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/ForumImpl.java	2007-06-11 22:21:21 UTC (rev 12474)
@@ -38,6 +38,7 @@
  * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
  * @version $Revision: 1124 $
  * @hibernate.class table="jbp_forums_forums"
+ * @hibernate.cache usage="read-write"
  */
 public class ForumImpl
    implements Serializable,

Modified: labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java
===================================================================
--- labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java	2007-06-11 22:18:41 UTC (rev 12473)
+++ labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/ForumsModuleImpl.java	2007-06-11 22:21:21 UTC (rev 12474)
@@ -344,6 +344,7 @@
       {
          Session session = getSession();
          Query query = session.createQuery("from CategoryImpl as c order by c.order asc");
+		 query.setCacheable(true);
          return query.list();
       }
       catch (HibernateException e)
@@ -364,6 +365,7 @@
                                             " from CategoryImpl as c " +
                                             " left outer join fetch c.forums " +
                                             " order by c.order asc");
+		  query.setCacheable(true);
           List categoriesWithDuplicates = query.list();
           Iterator it = categoriesWithDuplicates.iterator();
           List categories = new LinkedList();
@@ -1542,6 +1544,7 @@
               session.createQuery("select MAX(topic.lastPostDate) as maxDate , topic.forum.id " + 
                                   "from TopicImpl as topic " +
                                   "group by topic.forum.id ");
+		  query.setCacheable(true);
           List createDates = query.list();
           Iterator it = createDates.iterator();
           List dates = new LinkedList();
@@ -1559,7 +1562,8 @@
                                       "join fetch post.poster " +
                                       "where post.createDate IN (:dates) " +
                                       "order by post.createDate ");
-          query.setParameterList("dates",dates);
+          query.setCacheable(true);
+		  query.setParameterList("dates",dates);
           List posts = query.list();
           Map forumPostMap = new HashMap(createDates.size());
           Iterator iterator = createDates.iterator();
@@ -1928,6 +1932,41 @@
    }
    
    protected Session getSession () {
-       return factory.getCurrentSession();
+       Session session = factory.getCurrentSession();
+	   System.out.println ("CATEGORY");
+	   Map cacheEntries = null;
+	   org.hibernate.stat.SecondLevelCacheStatistics stats = factory.getStatistics()
+        .getSecondLevelCacheStatistics("org.jboss.portlet.forums.impl.CategoryImpl");
+       if ( stats !=null) {
+		  cacheEntries = stats.getEntries();
+          Iterator it = cacheEntries.keySet().iterator();
+	      while (it.hasNext()) {
+	         Object ob = it.next();
+		     System.out.println ("KEY: "+ob+" VALUE: "+cacheEntries.get(ob));
+	      }
+	   }
+	   System.out.println ("FORUM");
+	   stats = factory.getStatistics()
+        .getSecondLevelCacheStatistics("org.jboss.portlet.forums.impl.ForumImpl");
+       if ( stats !=null) {
+		  cacheEntries = stats.getEntries();
+          Iterator it = cacheEntries.keySet().iterator();
+	      while (it.hasNext()) {
+	         Object ob = it.next();
+		     System.out.println ("KEY: "+ob+" VALUE: "+cacheEntries.get(ob));
+	      }
+	   }
+	   System.out.println ("CATEGORY.FORUMS");
+	   stats = factory.getStatistics()
+        .getSecondLevelCacheStatistics("org.jboss.portlet.forums.impl.CategoryImpl.forums");
+       if ( stats !=null) {
+		  cacheEntries = stats.getEntries();
+          Iterator it = cacheEntries.keySet().iterator();
+	      while (it.hasNext()) {
+	         Object ob = it.next();
+		     System.out.println ("KEY: "+ob+" VALUE: "+cacheEntries.get(ob));
+	      }
+	   }
+	   return session;
    }
 }
\ No newline at end of file

Modified: labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/PostImpl.java
===================================================================
--- labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/PostImpl.java	2007-06-11 22:18:41 UTC (rev 12473)
+++ labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/PostImpl.java	2007-06-11 22:21:21 UTC (rev 12474)
@@ -28,6 +28,7 @@
  * @author <a href="mailto:boleslaw.dawidowicz at jboss.com">Boleslaw Dawidowicz</a>
  * @version $Revision: 2066 $
  * @hibernate.class table="jbp_forums_posts"
+ * @hibernate.cache usage="read-write"
  */
 public class PostImpl
    implements Serializable,

Modified: labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/PosterImpl.java
===================================================================
--- labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/PosterImpl.java	2007-06-11 22:18:41 UTC (rev 12473)
+++ labs/jbossforums/branches/forums110P26/forums/src/main/org/jboss/portlet/forums/impl/PosterImpl.java	2007-06-11 22:21:21 UTC (rev 12474)
@@ -27,6 +27,7 @@
  * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  * @version $Revision: 2811 $
  * @hibernate.class table="jbp_forums_posters"
+ * @hibernate.cache usage="read-write"
  */
 public class PosterImpl
    implements Poster

Modified: labs/jbossforums/branches/forums110P26/forums/src/resources/portal-forums-sar/conf/hibernate/hibernate.cfg.xml
===================================================================
--- labs/jbossforums/branches/forums110P26/forums/src/resources/portal-forums-sar/conf/hibernate/hibernate.cfg.xml	2007-06-11 22:18:41 UTC (rev 12473)
+++ labs/jbossforums/branches/forums110P26/forums/src/resources/portal-forums-sar/conf/hibernate/hibernate.cfg.xml	2007-06-11 22:21:21 UTC (rev 12474)
@@ -5,8 +5,13 @@
 <hibernate-configuration>
    <session-factory>
       <property name="connection.datasource">java:@portal.datasource.name@</property>
-      <property name="show_sql">false</property>
-
+      <property name="show_sql">true</property>
+      <property name="format_sql">true</property>
+      <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
+      <property name="hibernate.cache.use_query_cache">true</property>
+      <property name="hibernate.cache.use_second_level_cache">true</property>
+      <property name="hibernate.generate_statistics">true</property>
+      <property name="hibernate.cache.use_structured_entries">true</property>
       <!-- Force the dialect instead of using autodetection -->
       <!--
       <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>

Added: labs/jbossforums/branches/forums110P26/forums/src/resources/portal-forums-sar/ehcache.xml
===================================================================
--- labs/jbossforums/branches/forums110P26/forums/src/resources/portal-forums-sar/ehcache.xml	                        (rev 0)
+++ labs/jbossforums/branches/forums110P26/forums/src/resources/portal-forums-sar/ehcache.xml	2007-06-11 22:21:21 UTC (rev 12474)
@@ -0,0 +1,129 @@
+<ehcache>
+
+    <!-- Sets the path to the directory where cache .data files are created.
+
+         If the path is a Java System Property it is replaced by
+         its value in the running VM.
+
+         The following properties are translated:
+         user.home - User's home directory
+         user.dir - User's current working directory
+         java.io.tmpdir - Default temp file path -->
+    <diskStore path="java.io.tmpdir"/>
+
+
+    <!--Default Cache configuration. These will applied to caches programmatically created through
+        the CacheManager.
+
+        The following attributes are required for defaultCache:
+
+        maxInMemory       - Sets the maximum number of objects that will be created in memory
+        eternal           - Sets whether elements are eternal. If eternal,  timeouts are ignored and the element
+                            is never expired.
+        timeToIdleSeconds - Sets the time to idle for an element before it expires. Is only used
+                            if the element is not eternal. Idle time is now - last accessed time
+        timeToLiveSeconds - Sets the time to live for an element before it expires. Is only used
+                            if the element is not eternal. TTL is now - creation time
+        overflowToDisk    - Sets whether elements can overflow to disk when the in-memory cache
+                            has reached the maxInMemory limit.
+
+        -->
+    <defaultCache
+        maxElementsInMemory="10000"
+        eternal="false"
+        timeToIdleSeconds="120"
+        timeToLiveSeconds="120"
+        overflowToDisk="true"
+        />
+
+    <!--Predefined caches.  Add your cache configuration settings here.
+        If you do not have a configuration for your cache a WARNING will be issued when the
+        CacheManager starts
+
+        The following attributes are required for defaultCache:
+
+        name              - Sets the name of the cache. This is used to identify the cache. It must be unique.
+        maxInMemory       - Sets the maximum number of objects that will be created in memory
+        eternal           - Sets whether elements are eternal. If eternal,  timeouts are ignored and the element
+                            is never expired.
+        timeToIdleSeconds - Sets the time to idle for an element before it expires. Is only used
+                            if the element is not eternal. Idle time is now - last accessed time
+        timeToLiveSeconds - Sets the time to live for an element before it expires. Is only used
+                            if the element is not eternal. TTL is now - creation time
+        overflowToDisk    - Sets whether elements can overflow to disk when the in-memory cache
+                            has reached the maxInMemory limit.
+
+        -->
+
+    <!-- Sample cache named sampleCache1
+        This cache contains a maximum in memory of 10000 elements, and will expire
+        an element if it is idle for more than 5 minutes and lives for more than
+        10 minutes.
+
+        If there are more than 10000 elements it will overflow to the
+        disk cache, which in this configuration will go to wherever java.io.tmp is
+        defined on your system. On a standard Linux system this will be /tmp"
+        -->
+    <cache name="sampleCache1"
+        maxElementsInMemory="10000"
+        eternal="false"
+        timeToIdleSeconds="300"
+        timeToLiveSeconds="600"
+        overflowToDisk="true"
+        />
+
+    <!-- Sample cache named sampleCache2
+        This cache contains 1000 elements. Elements will always be held in memory.
+        They are not expired. -->
+    <cache name="sampleCache2"
+        maxElementsInMemory="1000"
+        eternal="true"
+        timeToIdleSeconds="0"
+        timeToLiveSeconds="0"
+        overflowToDisk="false"
+        /> -->
+
+    <!-- Place configuration for your caches following -->
+
+    <cache name="org.jboss.portlet.forums.impl.CategoryImpl"
+        maxElementsInMemory="10000"
+        eternal="false"
+        timeToIdleSeconds="3000"
+        timeToLiveSeconds="6000"
+        overflowToDisk="false"
+    />
+
+    <cache name="org.jboss.portlet.forums.impl.CategoryImpl.forums"
+        maxElementsInMemory="10000"
+        eternal="false"
+        timeToIdleSeconds="3000"
+        timeToLiveSeconds="6000"
+        overflowToDisk="false"
+    />
+
+    <cache name="org.jboss.portlet.forums.impl.ForumImpl"
+        maxElementsInMemory="10000"
+        eternal="false"
+        timeToIdleSeconds="3000"
+        timeToLiveSeconds="6000"
+        overflowToDisk="false"
+    />
+
+    <cache name="org.jboss.portlet.forums.impl.PostImpl"
+        maxElementsInMemory="10000"
+        eternal="false"
+        timeToIdleSeconds="3000"
+        timeToLiveSeconds="6000"
+        overflowToDisk="false"
+    />
+
+    <cache name="org.jboss.portlet.forums.impl.PosterImpl"
+        maxElementsInMemory="10000"
+        eternal="false"
+        timeToIdleSeconds="3000"
+        timeToLiveSeconds="6000"
+        overflowToDisk="false"
+    />
+
+
+</ehcache>




More information about the jboss-svn-commits mailing list