00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00036
00037
00038
00039
00040
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
00054
00055
00056
00057
00058
00059
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
00077
00078
00079
00080 public RE getQueryPattern()
00081 {
00082 return this.queryPattern;
00083 }
00084
00085
00086
00087
00088
00089
00090 public CacheBehavior getCacheBehavior()
00091 {
00092 return behavior;
00093 }
00094
00095
00096
00097
00098
00099
00100 public void setCacheBehavior(CacheBehavior behavior)
00101 {
00102 this.behavior = behavior;
00103 }
00104
00105
00106
00107
00108
00109
00110 public long getTimestampResolution()
00111 {
00112 return this.timestampResolution;
00113 }
00114
00115
00116
00117
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
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 }