Return-Path: Delivered-To: apmail-incubator-click-commits-archive@minotaur.apache.org Received: (qmail 80737 invoked from network); 29 Jul 2009 14:23:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Jul 2009 14:23:20 -0000 Received: (qmail 47932 invoked by uid 500); 29 Jul 2009 14:23:20 -0000 Delivered-To: apmail-incubator-click-commits-archive@incubator.apache.org Received: (qmail 47918 invoked by uid 500); 29 Jul 2009 14:23:20 -0000 Mailing-List: contact click-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: click-dev@incubator.apache.org Delivered-To: mailing list click-commits@incubator.apache.org Received: (qmail 47908 invoked by uid 99); 29 Jul 2009 14:23:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Jul 2009 14:23:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 29 Jul 2009 14:23:09 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 491722388854; Wed, 29 Jul 2009 14:22:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Wed, 29 Jul 2009 14:22:48 -0000 To: click-commits@incubator.apache.org From: medgar@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090729142248.491722388854@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 @@ - - - - - - Click Examples - - - - contextConfigLocation - WEB-INF/spring-beans.xml - - - - - - - DataContextFilter - org.apache.click.extras.cayenne.DataContextFilter - - session-scope - false - - - - - - PerformanceFilter - org.apache.click.extras.filter.PerformanceFilter - - cachable-paths - /assets/* - - - exclude-paths - */excel-export.htm - - - - - - springSecurityFilterChain - org.springframework.web.filter.DelegatingFilterProxy - - - - DataContextFilter - *.htm - - - - springSecurityFilterChain - /* - - - - PerformanceFilter - ClickServlet - - - - PerformanceFilter - *.css - - - - PerformanceFilter - *.js - - - - PerformanceFilter - *.gif - - - - PerformanceFilter - *.png - - - - - - - org.quartz.ee.servlet.QuartzInitializerListener - - - - - org.springframework.web.context.ContextLoaderListener - - - - - org.apache.click.examples.util.DatabaseInitListener - - - - - - - ClickServlet - org.apache.click.extras.spring.SpringClickServlet - 0 - - - - ClickServlet - *.htm - - - - ClickServlet - /click/* - - - - - - redirect.html - - - + + + + + + Click Examples + + + + contextConfigLocation + WEB-INF/spring-beans.xml + + + + + + + DataContextFilter + org.apache.click.extras.cayenne.DataContextFilter + + oscache-enabled + true + + + + + + PerformanceFilter + org.apache.click.extras.filter.PerformanceFilter + + cachable-paths + /assets/* + + + exclude-paths + */excel-export.htm + + + + + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + + DataContextFilter + *.htm + + + + springSecurityFilterChain + /* + + + + PerformanceFilter + ClickServlet + + + + PerformanceFilter + *.css + + + + PerformanceFilter + *.js + + + + PerformanceFilter + *.gif + + + + PerformanceFilter + *.png + + + + + + + org.quartz.ee.servlet.QuartzInitializerListener + + + + + org.springframework.web.context.ContextLoaderListener + + + + + org.apache.click.examples.util.DatabaseInitListener + + + + + + + ClickServlet + org.apache.click.extras.spring.SpringClickServlet + 0 + + + + ClickServlet + *.htm + + + + ClickServlet + /click/* + + + + + + redirect.html + + + 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); }