1 24 25 package org.objectweb.cjdbc.controller.backend.rewriting; 26 27 33 public class SimpleRewritingRule extends AbstractRewritingRule 34 { 35 36 private int queryPatternLength; 37 38 47 public SimpleRewritingRule(String queryPattern, String rewrite, 48 boolean caseSensitive, boolean stopOnMatch) 49 { 50 super(queryPattern, caseSensitive ? rewrite : rewrite.toLowerCase(), 51 caseSensitive, stopOnMatch); 52 queryPatternLength = queryPattern.length(); 53 } 54 55 58 public String rewrite(String sqlQuery) 59 { 60 int start; 62 if (isCaseSensitive) 63 start = sqlQuery.indexOf(queryPattern); 64 else 65 start = sqlQuery.toLowerCase().indexOf(queryPattern.toLowerCase()); 66 if (start == -1) 67 { hasMatched = false; 69 return sqlQuery; 70 } 71 hasMatched = true; 73 if (start == 0) 74 { 75 if (queryPatternLength < sqlQuery.length()) 76 return rewrite + sqlQuery.substring(queryPatternLength); 78 else 79 return rewrite; 81 } 82 else 83 { 84 if (start + queryPatternLength < sqlQuery.length()) 85 return sqlQuery.substring(0, start) + rewrite 86 + sqlQuery.substring(start + queryPatternLength); 87 else 88 return sqlQuery.substring(0, start) + rewrite; 90 } 91 } 92 93 } | Popular Tags |