1 24 25 package org.objectweb.cjdbc.controller.cache.result; 26 27 import org.apache.regexp.RE; 28 import org.apache.regexp.RESyntaxException; 29 import org.objectweb.cjdbc.common.log.Trace; 30 import org.objectweb.cjdbc.common.sql.AbstractRequest; 31 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 32 import org.objectweb.cjdbc.common.xml.XmlComponent; 33 34 42 public class ResultCacheRule implements XmlComponent 43 { 44 Trace logger = Trace.getLogger(ResultCacheRule.class.getName()); 45 private RE queryPattern; 46 private String queryString; 47 private boolean isCaseSensitive; 48 private boolean applyToSkeleton; 49 private long timestampResolution; 50 private CacheBehavior behavior; 51 52 61 public ResultCacheRule( 62 String queryString, 63 boolean caseSensitive, 64 boolean applyToSkeleton, 65 long timestampResolution) 66 throws RESyntaxException 67 { 68 this.queryString = queryString; 69 queryPattern = new RE(queryString); 70 this.isCaseSensitive = caseSensitive; 71 this.applyToSkeleton = applyToSkeleton; 72 this.timestampResolution = timestampResolution; 73 } 74 75 80 public RE getQueryPattern() 81 { 82 return this.queryPattern; 83 } 84 85 90 public CacheBehavior getCacheBehavior() 91 { 92 return behavior; 93 } 94 95 100 public void setCacheBehavior(CacheBehavior behavior) 101 { 102 this.behavior = behavior; 103 } 104 105 110 public long getTimestampResolution() 111 { 112 return this.timestampResolution; 113 } 114 115 119 public CacheBehavior matches(AbstractRequest request) 120 { 121 if (queryPattern.match(request.getSQL())) 122 { 123 return behavior; 124 } 125 else 126 return null; 127 } 128 129 132 public String getXml() 133 { 134 StringBuffer info = new StringBuffer (); 135 info.append( 136 "<" 137 + DatabasesXmlTags.ELT_ResultCacheRule 138 + " " 139 + DatabasesXmlTags.ATT_queryPattern 140 + "=\"" 141 + queryString 142 + "\" " 143 + DatabasesXmlTags.ATT_caseSensitive 144 + "=\"" 145 + isCaseSensitive 146 + "\" " 147 + DatabasesXmlTags.ATT_applyToSkeleton 148 + "=\"" 149 + applyToSkeleton 150 + "\" " 151 + DatabasesXmlTags.ATT_timestampResolution 152 + "=\"" 153 + timestampResolution / 1000 154 + "\" >"); 155 info.append(behavior.getXml()); 156 info.append("</" + DatabasesXmlTags.ELT_ResultCacheRule + ">"); 157 return info.toString(); 158 } 159 160 } | Popular Tags |