Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ResultCacheRule.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk
00022  * Contributor(s): Emmanuel Cecchet. 
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.cache.result;
00026 
00027 import org.apache.regexp.RE;
00028 import org.apache.regexp.RESyntaxException;
00029 import org.objectweb.cjdbc.common.log.Trace;
00030 import org.objectweb.cjdbc.common.sql.AbstractRequest;
00031 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags;
00032 import org.objectweb.cjdbc.common.xml.XmlComponent;
00033 
00034 /**
00035  * This is the to define cache rules in the cache. A <code>ResultCacheRule</code>
00036  * is defined by a queryPattern, set to 'default' if default rule, and a <code>CacheBehavior</code>.
00037  * 
00038  * @author <a href="mailto:Nicolas.Modrzyk@inrialpes.fr">Nicolas Modrzyk</a>
00039  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
00040  * @version 1.0
00041  */
00042 public class ResultCacheRule implements XmlComponent
00043 {
00044   Trace logger = Trace.getLogger(ResultCacheRule.class.getName());
00045   private RE queryPattern;
00046   private String queryString;
00047   private boolean isCaseSensitive;
00048   private boolean applyToSkeleton;
00049   private long timestampResolution;
00050   private CacheBehavior behavior;
00051 
00052   /**
00053    * Creates a new <code>ResultCacheRule</code>
00054    * 
00055    * @param queryString for this rule
00056    * @param caseSensitive true if matching is case sensitive
00057    * @param applyToSkeleton true if rule apply to query skeleton
00058    * @param timestampResolution timestamp resolution for NOW() macro
00059    * @throws RESyntaxException if the query pattern is invalid
00060    */
00061   public ResultCacheRule(
00062     String queryString,
00063     boolean caseSensitive,
00064     boolean applyToSkeleton,
00065     long timestampResolution)
00066     throws RESyntaxException
00067   {
00068     this.queryString = queryString;
00069     queryPattern = new RE(queryString);
00070     this.isCaseSensitive = caseSensitive;
00071     this.applyToSkeleton = applyToSkeleton;
00072     this.timestampResolution = timestampResolution;
00073   }
00074 
00075   /**
00076    * Get the query pattern
00077    * 
00078    * @return the queryPattern for this <code>ResultCacheRule</code>
00079    */
00080   public RE getQueryPattern()
00081   {
00082     return this.queryPattern;
00083   }
00084 
00085   /**
00086    * Get the cache behavior
00087    * 
00088    * @return the <code>CacheBehavior</code> for this <code>ResultCacheRule</code>
00089    */
00090   public CacheBehavior getCacheBehavior()
00091   {
00092     return behavior;
00093   }
00094 
00095   /**
00096    * Set the cache behavior
00097    * 
00098    * @param behavior behavior for this rule
00099    */
00100   public void setCacheBehavior(CacheBehavior behavior)
00101   {
00102     this.behavior = behavior;
00103   }
00104 
00105   /**
00106    * Retrieve the timestamp resolution of this scheduler
00107    * 
00108    * @return timestampResolution
00109    */
00110   public long getTimestampResolution()
00111   {
00112     return this.timestampResolution;
00113   }
00114 
00115   /**
00116    * @param request we may want to add to the cache
00117    * @return the behavior to get the entry
00118    */
00119   public CacheBehavior matches(AbstractRequest request)
00120   {
00121     if (queryPattern.match(request.getSQL()))
00122     {
00123       return behavior;
00124     }
00125     else
00126       return null;
00127   }
00128 
00129   /**
00130    * @see org.objectweb.cjdbc.common.xml.XmlComponent#getXml()
00131    */
00132   public String getXml()
00133   {
00134     StringBuffer info = new StringBuffer();
00135     info.append(
00136       "<"
00137         + DatabasesXmlTags.ELT_ResultCacheRule
00138         + " "
00139         + DatabasesXmlTags.ATT_queryPattern
00140         + "=\""
00141         + queryString
00142         + "\" "
00143         + DatabasesXmlTags.ATT_caseSensitive
00144         + "=\""
00145         + isCaseSensitive
00146         + "\" "
00147         + DatabasesXmlTags.ATT_applyToSkeleton
00148         + "=\""
00149         + applyToSkeleton
00150         + "\" "
00151         + DatabasesXmlTags.ATT_timestampResolution
00152         + "=\""
00153         + timestampResolution / 1000
00154         + "\" >");
00155     info.append(behavior.getXml());
00156     info.append("</" + DatabasesXmlTags.ELT_ResultCacheRule + ">");
00157     return info.toString();
00158   }
00159 
00160 }

Generated on Mon Apr 11 22:01:34 2005 for C-JDBC by  doxygen 1.3.9.1