KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > backend > rewriting > AbstractRewritingRule


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: sequoia@continuent.org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Initial developer(s): Emmanuel Cecchet.
20  * Contributor(s): ______________________.
21  */

22
23 package org.continuent.sequoia.controller.backend.rewriting;
24
25 import org.continuent.sequoia.common.xml.DatabasesXmlTags;
26
27 /**
28  * This class defines a AbstractRewritingRule to rewrite SQL requests for a
29  * specific backend.
30  *
31  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet</a>
32  * @version 1.0
33  */

34 public abstract class AbstractRewritingRule
35 {
36   protected String JavaDoc queryPattern;
37   protected String JavaDoc rewrite;
38   protected boolean isCaseSensitive;
39   protected boolean stopOnMatch;
40   protected boolean hasMatched;
41
42   /**
43    * Creates a new <code>AbstractRewritingRule</code> object
44    *
45    * @param queryPattern SQL pattern to match
46    * @param rewrite rewritten SQL query
47    * @param caseSensitive true if matching is case sensitive
48    * @param stopOnMatch true if rewriting must stop after this rule if it
49    * matches.
50    */

51   public AbstractRewritingRule(String JavaDoc queryPattern, String JavaDoc rewrite,
52       boolean caseSensitive, boolean stopOnMatch)
53   {
54     this.queryPattern = queryPattern;
55     this.rewrite = rewrite;
56     this.isCaseSensitive = caseSensitive;
57     this.stopOnMatch = stopOnMatch;
58     this.hasMatched = false;
59   }
60
61   /**
62    * Returns true if the query given in the last call to rewrite has matched
63    * this rule.
64    * <p>1. call rewrite(query)
65    * <p>2. call hasMatched() to know if query matched this rule.
66    *
67    * @return true if the query matched this rule.
68    * @see #rewrite(String)
69    */

70   public boolean hasMatched()
71   {
72     return hasMatched;
73   }
74
75   /**
76    * Rewrite the given query according to the rule. Note that this method does
77    * not check if the given query matches the rule or not. You must call
78    * matches(String) before calling this method.
79    *
80    * @param sqlQuery request to rewrite
81    * @return the rewritten SQL query according to the rule.
82    * @see AbstractRewritingRule#hasMatched
83    */

84   public abstract String JavaDoc rewrite(String JavaDoc sqlQuery);
85
86   /**
87    * Returns the isCaseSensitive value.
88    *
89    * @return Returns the isCaseSensitive.
90    */

91   public boolean isCaseSensitive()
92   {
93     return isCaseSensitive;
94   }
95
96   /**
97    * Returns the queryPattern value.
98    *
99    * @return Returns the queryPattern.
100    */

101   public String JavaDoc getQueryPattern()
102   {
103     return queryPattern;
104   }
105
106   /**
107    * Returns the rewrite value.
108    *
109    * @return Returns the rewrite.
110    */

111   public String JavaDoc getRewrite()
112   {
113     return rewrite;
114   }
115
116   /**
117    * Returns the stopOnMatch value.
118    *
119    * @return Returns the stopOnMatch.
120    */

121   public boolean isStopOnMatch()
122   {
123     return stopOnMatch;
124   }
125
126   /**
127    * Get xml information about this AbstractRewritingRule.
128    *
129    * @return xml formatted information on this AbstractRewritingRule.
130    */

131   public String JavaDoc getXml()
132   {
133     return "<" + DatabasesXmlTags.ELT_RewritingRule + " "
134         + DatabasesXmlTags.ATT_queryPattern + "=\"" + queryPattern + "\" "
135         + DatabasesXmlTags.ATT_rewrite + "=\"" + rewrite + "\" "
136         + DatabasesXmlTags.ATT_caseSensitive + "=\"" + isCaseSensitive + "\" "
137         + DatabasesXmlTags.ATT_stopOnMatch + "=\"" + stopOnMatch + "\"/>";
138   }
139
140 }
141
Popular Tags