KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > controller > backend > rewriting > AbstractRewritingRule


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________.
23  */

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

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

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

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

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

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

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

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

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

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