1 24 package org.objectweb.cjdbc.controller.monitoring; 25 26 import org.apache.regexp.RE; 27 import org.apache.regexp.RESyntaxException; 28 import org.objectweb.cjdbc.common.sql.AbstractRequest; 29 import org.objectweb.cjdbc.common.xml.DatabasesXmlTags; 30 31 37 public class SQLMonitoringRule 38 { 39 private RE queryPattern; 40 private boolean isCaseSentive; 41 private boolean applyToSkeleton; 42 private boolean monitoring; 43 44 52 public SQLMonitoringRule( 53 String queryPattern, 54 boolean isCaseSentive, 55 boolean applyToSkeleton, 56 boolean monitoring) 57 { 58 try 59 { 60 this.queryPattern = new RE(queryPattern); 61 } 62 catch (RESyntaxException e) 63 { 64 throw new RuntimeException ( 65 "Invalid regexp in SQL Monitoring rule (" + e + ")"); 66 } 67 this.isCaseSentive = isCaseSentive; 68 if (isCaseSentive) 69 this.queryPattern.setMatchFlags(RE.MATCH_NORMAL); 70 else 71 this.queryPattern.setMatchFlags(RE.MATCH_CASEINDEPENDENT); 72 this.applyToSkeleton = applyToSkeleton; 73 this.monitoring = monitoring; 74 } 75 76 81 public boolean isCaseSentive() 82 { 83 return isCaseSentive; 84 } 85 86 91 public boolean isMonitoring() 92 { 93 return monitoring; 94 } 95 96 101 public String getQueryPattern() 102 { 103 return queryPattern.toString(); 104 } 105 106 111 public void setCaseSentive(boolean b) 112 { 113 isCaseSentive = b; 114 } 115 116 121 public void setMonitoring(boolean b) 122 { 123 monitoring = b; 124 } 125 126 131 public void setQueryPattern(String queryPattern) 132 { 133 try 134 { 135 this.queryPattern = new RE(queryPattern); 136 } 137 catch (RESyntaxException e) 138 { 139 throw new RuntimeException ( 140 "Invalid regexp in SQL Monitoring rule (" + e + ")"); 141 } 142 } 143 144 149 public boolean isApplyToSkeleton() 150 { 151 return applyToSkeleton; 152 } 153 154 159 public void setApplyToSkeleton(boolean b) 160 { 161 applyToSkeleton = b; 162 } 163 164 171 public String matches(AbstractRequest request) 172 { 173 if (applyToSkeleton) 174 { 175 String skel = request.getSqlSkeleton(); 176 if (skel == null) 177 return null; 178 else 179 { 180 if (queryPattern.match(skel)) 181 return skel; 182 else 183 return null; 184 } 185 } 186 else 187 { 188 if (queryPattern.match(request.getSQL())) 189 return request.getSQL(); 190 else 191 return null; 192 } 193 } 194 195 198 public String getXml() 199 { 200 String info = 201 "<" 202 + DatabasesXmlTags.ELT_SQLMonitoringRule 203 + " " 204 + DatabasesXmlTags.ATT_queryPattern 205 + "=\"" 206 + getQueryPattern() 207 + "\" " 208 + DatabasesXmlTags.ATT_caseSensitive 209 + "=\"" 210 + isCaseSentive() 211 + "\" " 212 + DatabasesXmlTags.ATT_applyToSkeleton 213 + "=\"" 214 + isApplyToSkeleton() 215 + "\" " 216 + DatabasesXmlTags.ATT_monitoring 217 + "=\""; 218 if (isMonitoring()) 219 info += "on"; 220 else 221 info += "off"; 222 info += "\"/>"; 223 return info; 224 } 225 226 } 227 | Popular Tags |