001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Emmanuel Cecchet.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.controller.requests;
021:
022: import java.util.regex.Pattern;
023:
024: /**
025: * This class defines the regular expressions to be used with generic ANSI SQL
026: * requests.
027: *
028: * @author <a href="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
029: * @version 1.0
030: */
031: public final class SequoiaRequestRegExp implements RequestRegExp {
032: private static final String ALTER_REQUEST_PATTERN_STRING = "^alter.*";
033: private static final String CREATE_REQUEST_PATTERN_STRING = "^(create|select\\s.+\\sinto\\s).*";
034: private static final String DELETE_REQUEST_PATTERN_STRING = "^(delete|truncate).*";
035: private static final String DROP_REQUEST_PATTERN_STRING = "^drop.*";
036: private static final String INSERT_REQUEST_PATTERN_STRING = "^insert.*";
037: private static final String SELECT_REQUEST_PATTERN_STRING = "^(\\s|\\()*select.*";
038: private static final String SELECT_FOR_UPDATE_PATTERN_STRING = ".*select.*\\s+for\\s+update\\s*.*";
039: private static final String STORED_PROCEDURE_PATTERN_STRING = "^\\{(\\s*\\?\\s*=)?\\s*call.*";
040: private static final String UPDATE_REQUEST_PATTERN_STRING = "^update.*";
041: private static final String UNKNOWN_READ_REQUEST_PATTERN_STRING = "^show.*";
042: private static final String UNKNOWN_WRITE_REQUEST_PATTERN_STRING = "^(grant|lock|revoke|set).*";
043: private static final String STATEMENT_EXECUTE_REQUEST_PATTERN_STRING = "^(explain\\s+analyze).*";
044: private static final String UNAUTHORIZED_REQUEST_PATTERN_STRING = "^(shutdown|kill).*";
045:
046: // Note that we use Patterns and not Matchers because these objects are
047: // potentially accessed concurrently and parsing could occur in parallel. This
048: // way, each caller will have to call Pattern.matcher() that will allocate a
049: // matcher for its own use in a thread-safe way.
050:
051: private static final Pattern ALTER_REQUEST_PATTERN = Pattern
052: .compile(ALTER_REQUEST_PATTERN_STRING,
053: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
054:
055: private static final Pattern CREATE_REQUEST_PATTERN = Pattern
056: .compile(CREATE_REQUEST_PATTERN_STRING,
057: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
058:
059: private static final Pattern DELETE_REQUEST_PATTERN = Pattern
060: .compile(DELETE_REQUEST_PATTERN_STRING,
061: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
062: private static final Pattern DROP_REQUEST_PATTERN = Pattern
063: .compile(DROP_REQUEST_PATTERN_STRING,
064: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
065:
066: private static final Pattern INSERT_REQUEST_PATTERN = Pattern
067: .compile(INSERT_REQUEST_PATTERN_STRING,
068: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
069:
070: private static final Pattern SELECT_REQUEST_PATTERN = Pattern
071: .compile(SELECT_REQUEST_PATTERN_STRING,
072: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
073: private static final Pattern SELECT_FOR_UPDATE_PATTERN = Pattern
074: .compile(SELECT_FOR_UPDATE_PATTERN_STRING,
075: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
076:
077: private static final Pattern STORED_PROCEDURE_PATTERN = Pattern
078: .compile(STORED_PROCEDURE_PATTERN_STRING,
079: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
080:
081: private static final Pattern UPDATE_REQUEST_PATTERN = Pattern
082: .compile(UPDATE_REQUEST_PATTERN_STRING,
083: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
084:
085: private static final Pattern UNKNOWN_READ_REQUEST_PATTERN = Pattern
086: .compile(UNKNOWN_READ_REQUEST_PATTERN_STRING,
087: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
088:
089: private static final Pattern UNKNOWN_WRITE_REQUEST_PATTERN = Pattern
090: .compile(UNKNOWN_WRITE_REQUEST_PATTERN_STRING,
091: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
092:
093: private static final Pattern STATEMENT_EXECUTE_REQUEST_PATTERN = Pattern
094: .compile(STATEMENT_EXECUTE_REQUEST_PATTERN_STRING,
095: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
096:
097: private static final Pattern UNAUTHORIZED_REQUEST_PATTERN = Pattern
098: .compile(UNAUTHORIZED_REQUEST_PATTERN_STRING,
099: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
100:
101: /**
102: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getAlterRequestPattern()
103: */
104: public Pattern getAlterRequestPattern() {
105: return ALTER_REQUEST_PATTERN;
106: }
107:
108: /**
109: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getCreateRequestPattern()
110: */
111: public Pattern getCreateRequestPattern() {
112: return CREATE_REQUEST_PATTERN;
113: }
114:
115: /**
116: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getDeleteRequestPattern()
117: */
118: public Pattern getDeleteRequestPattern() {
119: return DELETE_REQUEST_PATTERN;
120: }
121:
122: /**
123: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getDropRequestPattern()
124: */
125: public Pattern getDropRequestPattern() {
126: return DROP_REQUEST_PATTERN;
127: }
128:
129: /**
130: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getInsertQueryPattern()
131: */
132: public Pattern getInsertQueryPattern() {
133: return INSERT_REQUEST_PATTERN;
134: }
135:
136: /**
137: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getSelectForUpdatePattern()
138: */
139: public Pattern getSelectForUpdatePattern() {
140: return SELECT_FOR_UPDATE_PATTERN;
141: }
142:
143: /**
144: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getSelectRequestPattern()
145: */
146: public Pattern getSelectRequestPattern() {
147: return SELECT_REQUEST_PATTERN;
148: }
149:
150: /**
151: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getStoredProcedurePattern()
152: */
153: public Pattern getStoredProcedurePattern() {
154: return STORED_PROCEDURE_PATTERN;
155: }
156:
157: /**
158: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getUnknownReadRequestPattern()
159: */
160: public Pattern getUnknownReadRequestPattern() {
161: return UNKNOWN_READ_REQUEST_PATTERN;
162: }
163:
164: /**
165: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getUnknownWriteRequestPattern()
166: */
167: public Pattern getUnknownWriteRequestPattern() {
168: return UNKNOWN_WRITE_REQUEST_PATTERN;
169: }
170:
171: /**
172: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getUpdateRequestPattern()
173: */
174: public Pattern getUpdateRequestPattern() {
175: return UPDATE_REQUEST_PATTERN;
176: }
177:
178: /**
179: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getStatementExecuteRequestPattern()
180: */
181: public Pattern getStatementExecuteRequestPattern() {
182: return STATEMENT_EXECUTE_REQUEST_PATTERN;
183: }
184:
185: /**
186: * @see org.continuent.sequoia.controller.requests.RequestRegExp#getUnauthorizedRequestsPattern()
187: */
188: public Pattern getUnauthorizedRequestsPattern() {
189: return UNAUTHORIZED_REQUEST_PATTERN;
190: }
191:
192: }
|