You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by me...@apache.org on 2009/07/29 16:22:48 UTC

svn commit: r798917 - in /incubator/click/trunk/click: examples/src/org/apache/click/examples/service/CustomerService.java examples/src/oscache.properties examples/webapp/WEB-INF/web.xml extras/src/org/apache/click/extras/cayenne/DataContextFilter.java

Author: medgar
Date: Wed Jul 29 14:22:47 2009
New Revision: 798917

URL: http://svn.apache.org/viewvc?rev=798917&view=rev
Log:
CLK-573

Added:
    incubator/click/trunk/click/examples/src/oscache.properties
Modified:
    incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java
    incubator/click/trunk/click/examples/webapp/WEB-INF/web.xml
    incubator/click/trunk/click/extras/src/org/apache/click/extras/cayenne/DataContextFilter.java

Modified: incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java?rev=798917&r1=798916&r2=798917&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java (original)
+++ incubator/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java Wed Jul 29 14:22:47 2009
@@ -21,21 +21,21 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
-
 import java.util.Map;
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.click.examples.domain.Customer;
-import org.apache.click.extras.cayenne.CayenneTemplate;
 
-import org.apache.commons.lang.StringUtils;
+import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.exp.ExpressionFactory;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.query.IndirectQuery;
 import org.apache.cayenne.query.Query;
+import org.apache.cayenne.query.QueryCacheStrategy;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.query.SelectQuery;
+import org.apache.click.examples.domain.Customer;
+import org.apache.click.extras.cayenne.CayenneTemplate;
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 import org.springframework.stereotype.Component;
 
@@ -43,8 +43,6 @@
  * Provides a Customer Service.
  *
  * @see Customer
- *
- * @author Malcolm Edgar
  */
 @Component
 public class CustomerService extends CayenneTemplate {
@@ -67,10 +65,15 @@
 
     @SuppressWarnings("unchecked")
     public List<Customer> getCustomersSortedBy(String property, boolean ascending) {
+
         SelectQuery query = new SelectQuery(Customer.class);
         if (property != null) {
             query.addOrdering(property, ascending);
         }
+
+        // Example use of shared cache which is managed with oscache.properties
+        query.setCacheStrategy(QueryCacheStrategy.SHARED_CACHE);
+
         return performQuery(query);
     }
 

Added: incubator/click/trunk/click/examples/src/oscache.properties
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/src/oscache.properties?rev=798917&view=auto
==============================================================================
--- incubator/click/trunk/click/examples/src/oscache.properties (added)
+++ incubator/click/trunk/click/examples/src/oscache.properties Wed Jul 29 14:22:47 2009
@@ -0,0 +1,36 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#
+# OSCache configuration properties
+#
+# See: http://www.opensymphony.com/oscache/wiki/Configuration.html
+#
+                      
+cache.capacity=10000
+cache.algorithm=com.opensymphony.oscache.base.algorithm.LRUCache
+                        
+# Cayenne specific properties:
+                       
+# Default refresh period in seconds 
+# (used for all cache groups not explicitly overriding it here)
+cayenne.default.refresh = 30
+
+# Default expiry specified as cron expressions per
+#    http://www.opensymphony.com/oscache/wiki/Cron%20Expressions.html
+# expire entries every hour on the 10's minute
+# cayenne.default.cron = 10 * * * *

Modified: incubator/click/trunk/click/examples/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/examples/webapp/WEB-INF/web.xml?rev=798917&r1=798916&r2=798917&view=diff
==============================================================================
--- incubator/click/trunk/click/examples/webapp/WEB-INF/web.xml (original)
+++ incubator/click/trunk/click/examples/webapp/WEB-INF/web.xml Wed Jul 29 14:22:47 2009
@@ -1,166 +1,166 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-   Licensed to the Apache Software Foundation (ASF) under one
-   or more contributor license agreements.  See the NOTICE file
-   distributed with this work for additional information
-   regarding copyright ownership.  The ASF licenses this file
-   to you under the Apache License, Version 2.0 (the
-   "License"); you may not use this file except in compliance
-   with the License.  You may obtain a copy of the License at
-
-     http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing,
-   software distributed under the License is distributed on an
-   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-   KIND, either express or implied.  See the License for the
-   specific language governing permissions and limitations
-   under the License.
--->
-
-<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
-    version="2.4">
-    
-	<display-name>Click Examples</display-name>
-	
-	<!-- 
-	Spring configuration location. 
-	-->
-	<context-param>
-		<param-name>contextConfigLocation</param-name>
-		<param-value>WEB-INF/spring-beans.xml</param-value>
-	</context-param>
-	
-	<!-- Filters -->
-
-	<!--
-	Provides a thread local Cayenne DataContext filter.
-	-->
-	<filter>
-		<filter-name>DataContextFilter</filter-name>
-		<filter-class>org.apache.click.extras.cayenne.DataContextFilter</filter-class>
-		<init-param>
-			<param-name>session-scope</param-name>
- 			<param-value>false</param-value>
-		</init-param>
-	</filter>
- 
-	<!-- 
-	Provides a web application performance filter which compresses the response
-	and sets the Expires header on selected static resources. 
-	The "cachable-paths" init parameter tells the filter resources can have 
-	their Expires header set so the browser will cache them.
-	The "excludes-path" init parameter tells the filter which requests should
-	be ignored by the filter.
-	-->
-	<filter>
-		<filter-name>PerformanceFilter</filter-name>
-		<filter-class>org.apache.click.extras.filter.PerformanceFilter</filter-class>
-		<init-param>
-			<param-name>cachable-paths</param-name>
- 			<param-value>/assets/*</param-value>
-		</init-param>
-		<init-param>
-			<param-name>exclude-paths</param-name>
- 			<param-value>*/excel-export.htm</param-value>
-		</init-param>
-	</filter>
-
-	<!-- 
-	Provides a Spring Security (Acegi) filter.
-	-->
-	<filter>
-		<filter-name>springSecurityFilterChain</filter-name>
-		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
-	</filter>
-
-	<filter-mapping>
-		<filter-name>DataContextFilter</filter-name>
-    <url-pattern>*.htm</url-pattern>
-	</filter-mapping>
-
-	<filter-mapping>
-		<filter-name>springSecurityFilterChain</filter-name>
-		<url-pattern>/*</url-pattern>
-	</filter-mapping>
-
-	<filter-mapping>
-		<filter-name>PerformanceFilter</filter-name>
-		<servlet-name>ClickServlet</servlet-name>
-	</filter-mapping>
-
-	<filter-mapping>
-		<filter-name>PerformanceFilter</filter-name>
-		<url-pattern>*.css</url-pattern>
-	</filter-mapping>
-	
-	<filter-mapping>
-		<filter-name>PerformanceFilter</filter-name>
-		<url-pattern>*.js</url-pattern>
-	</filter-mapping>
-	
-	<filter-mapping>
-		<filter-name>PerformanceFilter</filter-name>
-		<url-pattern>*.gif</url-pattern>
-	</filter-mapping>
-	
-	<filter-mapping>
-		<filter-name>PerformanceFilter</filter-name>
-		<url-pattern>*.png</url-pattern>
-	</filter-mapping>
-
-	<!-- Listeners -->
-	
-	<!--  
-	The Quartz initialization listenger which loads the Quartz scheduler.  
-	-->
-	<listener>
-		<listener-class>org.quartz.ee.servlet.QuartzInitializerListener</listener-class>
-	</listener>
-	
-	<!-- 
-	The Spring Context Loader which initializes the Spring runtime. 
-	-->
-	<listener>
-		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
-	</listener>
-	
-	<!-- 
-	Provides an in memory databae initialization listener. In a production 
-	application a separate database would be used, and this listener would not
-	be needed.
-	-->
-	<listener>
-		<listener-class>org.apache.click.examples.util.DatabaseInitListener</listener-class>
-	</listener>
-		
-	<!-- Servlets -->
-
-	<!--
-	The Spring Click Servlet which handles *.htm requests.
-	-->
-	<servlet>
-		<servlet-name>ClickServlet</servlet-name>
-		<servlet-class>org.apache.click.extras.spring.SpringClickServlet</servlet-class>
-		<load-on-startup>0</load-on-startup>
-	</servlet>
-
-	<servlet-mapping>
-		<servlet-name>ClickServlet</servlet-name>
-		<url-pattern>*.htm</url-pattern>
-	</servlet-mapping>
-
-	<servlet-mapping>
-		<servlet-name>ClickServlet</servlet-name>
-		<url-pattern>/click/*</url-pattern>
-	</servlet-mapping>
-	
-	<!-- Wecome Files -->
-
-	<welcome-file-list>
-		<welcome-file>redirect.html</welcome-file>
-	</welcome-file-list>
-
-</web-app>
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF licenses this file
+   to you under the Apache License, Version 2.0 (the
+   "License"); you may not use this file except in compliance
+   with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing,
+   software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+   KIND, either express or implied.  See the License for the
+   specific language governing permissions and limitations
+   under the License.
+-->
+
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+    version="2.4">
+    
+	<display-name>Click Examples</display-name>
+	
+	<!-- 
+	Spring configuration location. 
+	-->
+	<context-param>
+		<param-name>contextConfigLocation</param-name>
+		<param-value>WEB-INF/spring-beans.xml</param-value>
+	</context-param>
+	
+	<!-- Filters -->
+
+	<!--
+	Provides a thread local Cayenne DataContext filter.
+	-->
+	<filter>
+		<filter-name>DataContextFilter</filter-name>
+		<filter-class>org.apache.click.extras.cayenne.DataContextFilter</filter-class>
+		<init-param>
+			<param-name>oscache-enabled</param-name>
+ 			<param-value>true</param-value>
+		</init-param>
+	</filter>
+ 
+	<!-- 
+	Provides a web application performance filter which compresses the response
+	and sets the Expires header on selected static resources. 
+	The "cachable-paths" init parameter tells the filter resources can have 
+	their Expires header set so the browser will cache them.
+	The "excludes-path" init parameter tells the filter which requests should
+	be ignored by the filter.
+	-->
+	<filter>
+		<filter-name>PerformanceFilter</filter-name>
+		<filter-class>org.apache.click.extras.filter.PerformanceFilter</filter-class>
+		<init-param>
+			<param-name>cachable-paths</param-name>
+ 			<param-value>/assets/*</param-value>
+		</init-param>
+		<init-param>
+			<param-name>exclude-paths</param-name>
+ 			<param-value>*/excel-export.htm</param-value>
+		</init-param>
+	</filter>
+
+	<!-- 
+	Provides a Spring Security (Acegi) filter.
+	-->
+	<filter>
+		<filter-name>springSecurityFilterChain</filter-name>
+		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
+	</filter>
+
+	<filter-mapping>
+		<filter-name>DataContextFilter</filter-name>
+    <url-pattern>*.htm</url-pattern>
+	</filter-mapping>
+
+	<filter-mapping>
+		<filter-name>springSecurityFilterChain</filter-name>
+		<url-pattern>/*</url-pattern>
+	</filter-mapping>
+
+	<filter-mapping>
+		<filter-name>PerformanceFilter</filter-name>
+		<servlet-name>ClickServlet</servlet-name>
+	</filter-mapping>
+
+	<filter-mapping>
+		<filter-name>PerformanceFilter</filter-name>
+		<url-pattern>*.css</url-pattern>
+	</filter-mapping>
+	
+	<filter-mapping>
+		<filter-name>PerformanceFilter</filter-name>
+		<url-pattern>*.js</url-pattern>
+	</filter-mapping>
+	
+	<filter-mapping>
+		<filter-name>PerformanceFilter</filter-name>
+		<url-pattern>*.gif</url-pattern>
+	</filter-mapping>
+	
+	<filter-mapping>
+		<filter-name>PerformanceFilter</filter-name>
+		<url-pattern>*.png</url-pattern>
+	</filter-mapping>
+
+	<!-- Listeners -->
+	
+	<!--  
+	The Quartz initialization listenger which loads the Quartz scheduler.  
+	-->
+	<listener>
+		<listener-class>org.quartz.ee.servlet.QuartzInitializerListener</listener-class>
+	</listener>
+	
+	<!-- 
+	The Spring Context Loader which initializes the Spring runtime. 
+	-->
+	<listener>
+		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+	</listener>
+	
+	<!-- 
+	Provides an in memory databae initialization listener. In a production 
+	application a separate database would be used, and this listener would not
+	be needed.
+	-->
+	<listener>
+		<listener-class>org.apache.click.examples.util.DatabaseInitListener</listener-class>
+	</listener>
+		
+	<!-- Servlets -->
+
+	<!--
+	The Spring Click Servlet which handles *.htm requests.
+	-->
+	<servlet>
+		<servlet-name>ClickServlet</servlet-name>
+		<servlet-class>org.apache.click.extras.spring.SpringClickServlet</servlet-class>
+		<load-on-startup>0</load-on-startup>
+	</servlet>
+
+	<servlet-mapping>
+		<servlet-name>ClickServlet</servlet-name>
+		<url-pattern>*.htm</url-pattern>
+	</servlet-mapping>
+
+	<servlet-mapping>
+		<servlet-name>ClickServlet</servlet-name>
+		<url-pattern>/click/*</url-pattern>
+	</servlet-mapping>
+	
+	<!-- Wecome Files -->
+
+	<welcome-file-list>
+		<welcome-file>redirect.html</welcome-file>
+	</welcome-file-list>
+
+</web-app>

Modified: incubator/click/trunk/click/extras/src/org/apache/click/extras/cayenne/DataContextFilter.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/extras/src/org/apache/click/extras/cayenne/DataContextFilter.java?rev=798917&r1=798916&r2=798917&view=diff
==============================================================================
--- incubator/click/trunk/click/extras/src/org/apache/click/extras/cayenne/DataContextFilter.java (original)
+++ incubator/click/trunk/click/extras/src/org/apache/click/extras/cayenne/DataContextFilter.java Wed Jul 29 14:22:47 2009
@@ -34,6 +34,7 @@
 import org.apache.cayenne.LifecycleListener;
 import org.apache.cayenne.access.DataContext;
 import org.apache.cayenne.access.DataDomain;
+import org.apache.cayenne.cache.OSQueryCacheFactory;
 import org.apache.cayenne.conf.Configuration;
 import org.apache.cayenne.conf.ServletUtil;
 import org.apache.cayenne.map.LifecycleEvent;
@@ -189,17 +190,17 @@
      * The filter configuration object we are associated with.  If this value
      * is null, this filter instance is not currently configured.
      */
-    protected FilterConfig filterConfig = null;
+    protected FilterConfig filterConfig;
 
     /**
-     * Maintain user HttpSession scope DataContext object, the default value is
-     * true. If sessionScope is false then a new DataContext object will be
+     * Maintain user DataContext object in their HttpSession, the default value
+     * is false. If sessionScope is false then a new DataContext object will be
      * created for each request.
      */
-    protected boolean sessionScope = true;
+    protected boolean sessionScope = false;
 
     /** Create DataContext objects using the shared cache. */
-    protected boolean sharedCache = true;
+    protected Boolean sharedCache;
 
     /** The Click log service. */
     protected LogService logger;
@@ -217,6 +218,9 @@
      */
     public synchronized void init(FilterConfig config) {
 
+         HtmlStringBuffer buffer = new HtmlStringBuffer();
+         buffer.append("DataContextFilter initialized: ");
+
         filterConfig = config;
 
         ServletUtil.initializeSharedConfiguration(config.getServletContext());
@@ -229,21 +233,34 @@
         if (StringUtils.isNotBlank(value)) {
             autoRollback = "true".equalsIgnoreCase(value);
         }
+        buffer.append(" auto-rollback=" + autoRollback);
+
 
         value = config.getInitParameter("session-scope");
         if (StringUtils.isNotBlank(value)) {
             sessionScope = "true".equalsIgnoreCase(value);
         }
+        buffer.append(", session-scope=" + sessionScope);
 
         value = config.getInitParameter("shared-cache");
         if (StringUtils.isNotBlank(value)) {
             sharedCache = "true".equalsIgnoreCase(value);
         }
+        buffer.append(", shared-cache=");
+        buffer.append((sharedCache != null) ? sharedCache : "default");
+
+        value = config.getInitParameter("oscache-enabled");
+        boolean oscacheEnabled = "true".equalsIgnoreCase(value);
+        if (oscacheEnabled) {
+            dataDomain.setQueryCacheFactory(new OSQueryCacheFactory());
+        }
+        buffer.append(", oscache-enabled=" + oscacheEnabled);
 
         String classname = config.getInitParameter("lifecycle-listener");
 
         if (StringUtils.isNotEmpty(classname)) {
             try {
+                @SuppressWarnings("unchecked")
                 Class listenerClass = ClickUtils.classForName(classname);
 
                 LifecycleCallbackRegistry registry =
@@ -254,6 +271,7 @@
 
                 if (registry.isEmpty(LifecycleEvent.POST_LOAD)) {
                     registry.addDefaultListener(lifecycleListener);
+                    buffer.append(", lifecycle-listener=" + classname);
 
                 } else {
                     String message =
@@ -268,6 +286,9 @@
                 throw new RuntimeException(message, e);
             }
         }
+
+        // Log init data, note LogService is not yet initialized
+        getFilterConfig().getServletContext().log(buffer.toString());
     }
 
     /**
@@ -393,7 +414,14 @@
      * @return the DataContext object
      */
     protected DataContext createDataContext() {
-        DataContext dataContext = dataDomain.createDataContext(sharedCache);
+
+        DataContext dataContext = null;
+        if (sharedCache != null) {
+            dataContext = dataDomain.createDataContext(sharedCache);
+
+        } else {
+            dataContext = dataDomain.createDataContext();
+        }
 
         if (logger.isTraceEnabled()) {
             HtmlStringBuffer buffer = new HtmlStringBuffer();
@@ -403,11 +431,11 @@
             } else {
                 buffer.append("request scope");
             }
-            if (sharedCache) {
-                buffer.append(" and shared cache.");
-            } else {
-                buffer.append(".");
+            if (sharedCache != null) {
+                buffer.append(", and shared cache ");
+                buffer.append(sharedCache);
             }
+            buffer.append(".");
             logger.trace(buffer);
         }