1 22 23 package org.continuent.sequoia.controller.cache.result; 24 25 import java.util.regex.Pattern ; 26 27 import org.continuent.sequoia.common.log.Trace; 28 import org.continuent.sequoia.common.xml.DatabasesXmlTags; 29 import org.continuent.sequoia.common.xml.XmlComponent; 30 import org.continuent.sequoia.controller.requests.AbstractRequest; 31 32 41 public class ResultCacheRule implements XmlComponent 42 { 43 Trace logger = Trace.getLogger(ResultCacheRule.class 44 .getName()); 45 private Pattern queryPattern; 46 private String queryString; 47 private boolean isCaseSensitive; 48 private boolean applyToSkeleton; 49 private long timestampResolution; 50 private CacheBehavior behavior; 51 52 60 public ResultCacheRule(String queryString, boolean caseSensitive, 61 boolean applyToSkeleton, long timestampResolution) 62 { 63 this.queryString = queryString; 64 queryPattern = Pattern.compile(queryString); 65 this.isCaseSensitive = caseSensitive; 66 this.applyToSkeleton = applyToSkeleton; 67 this.timestampResolution = timestampResolution; 68 } 69 70 75 public Pattern getQueryPattern() 76 { 77 return this.queryPattern; 78 } 79 80 86 public CacheBehavior getCacheBehavior() 87 { 88 return behavior; 89 } 90 91 96 public void setCacheBehavior(CacheBehavior behavior) 97 { 98 this.behavior = behavior; 99 } 100 101 106 public long getTimestampResolution() 107 { 108 return this.timestampResolution; 109 } 110 111 115 public CacheBehavior matches(AbstractRequest request) 116 { 117 if (queryPattern.matcher(request.getSqlOrTemplate()).matches()) 118 return behavior; 119 else 120 return null; 121 } 122 123 126 public String getXml() 127 { 128 StringBuffer info = new StringBuffer (); 129 info.append("<" + DatabasesXmlTags.ELT_ResultCacheRule + " " 130 + DatabasesXmlTags.ATT_queryPattern + "=\"" + queryString + "\" " 131 + DatabasesXmlTags.ATT_caseSensitive + "=\"" + isCaseSensitive + "\" " 132 + DatabasesXmlTags.ATT_applyToSkeleton + "=\"" + applyToSkeleton 133 + "\" " + DatabasesXmlTags.ATT_timestampResolution + "=\"" 134 + timestampResolution / 1000 + "\" >"); 135 info.append(behavior.getXml()); 136 info.append("</" + DatabasesXmlTags.ELT_ResultCacheRule + ">"); 137 return info.toString(); 138 } 139 140 } | Popular Tags |