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.driver;
021:
022: import java.util.regex.Pattern;
023:
024: /**
025: * This class defines the regular expressions to map generic ANSI SQL requests
026: * to JDBC API calls.
027: *
028: * @author <a href="mailto:emmanuel.cecchet@continuent.com">Emmanuel Cecchet</a>
029: * @version 1.0
030: */
031: public final class SequoiaJDBCRegExp implements JDBCRegExp {
032: /** Regexp patterns for Statement class */
033: private static final String BEGIN_PATTERN_STRING = "^begin.*";
034: private static final String COMMIT_PATTERN_STRING = "^commit.*";
035: private static final String RELEASE_SAVEPOINT_PATTERN_STRING = "^release\\s+savepoint.*";
036: private static final String ROLLBACK_PATTERN_STRING = "^rollback.*";
037: private static final String ROLLBACK_TO_SAVEPOINT_PATTERN_STRING = "^rollback\\s+to\\s+.*";
038: private static final String SET_ISOLATION_LEVEL_PATTERN_STRING = "^set.*transaction.*isolation\\s+level.*";
039: private static final String SET_READ_ONLY_TRANSACTION_PATTERN_STRING = "^set.*transaction\\s+read\\s+only.*";
040: private static final String SET_SAVEPOINT_PATTERN_STRING = "^savepoint.*";
041: private static final String SET_AUTOCOMMIT_1_PATTERN_STRING = "";
042:
043: // Note that we use Patterns and not Matchers because these objects are
044: // potentially accessed concurrently and parsing could occur in parallel. This
045: // way, each caller will have to call Pattern.matcher() that will allocate a
046: // matcher for its own use in a thread-safe way.
047:
048: private static final Pattern BEGIN_PATTERN = Pattern.compile(
049: BEGIN_PATTERN_STRING, Pattern.CASE_INSENSITIVE
050: | Pattern.DOTALL);
051:
052: private static final Pattern COMMIT_PATTERN = Pattern.compile(
053: COMMIT_PATTERN_STRING, Pattern.CASE_INSENSITIVE
054: | Pattern.DOTALL);
055:
056: private static final Pattern RELEASE_SAVEPOINT_PATTERN = Pattern
057: .compile(RELEASE_SAVEPOINT_PATTERN_STRING,
058: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
059:
060: private static final Pattern ROLLBACK_PATTERN = Pattern.compile(
061: ROLLBACK_PATTERN_STRING, Pattern.CASE_INSENSITIVE
062: | Pattern.DOTALL);
063:
064: private static final Pattern ROLLBACK_TO_SAVEPOINT_PATTERN = Pattern
065: .compile(ROLLBACK_TO_SAVEPOINT_PATTERN_STRING,
066: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
067:
068: private static final Pattern SET_ISOLATION_LEVEL_PATTERN = Pattern
069: .compile(SET_ISOLATION_LEVEL_PATTERN_STRING,
070: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
071:
072: private static final Pattern SET_READ_ONLY_TRANSACTION_PATTERN = Pattern
073: .compile(SET_READ_ONLY_TRANSACTION_PATTERN_STRING,
074: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
075:
076: private static final Pattern SET_SAVEPOINT_PATTERN = Pattern
077: .compile(SET_SAVEPOINT_PATTERN_STRING,
078: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
079: private static final Pattern SET_AUTOCOMMIT_1_PATTERN = Pattern
080: .compile(SET_AUTOCOMMIT_1_PATTERN_STRING,
081: Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
082:
083: /**
084: * @see org.continuent.sequoia.driver.JDBCRegExp#getBeginPattern()
085: */
086: public Pattern getBeginPattern() {
087: return BEGIN_PATTERN;
088: }
089:
090: /**
091: * @see org.continuent.sequoia.driver.JDBCRegExp#getCommitPattern()
092: */
093: public Pattern getCommitPattern() {
094: return COMMIT_PATTERN;
095: }
096:
097: /**
098: * @see org.continuent.sequoia.driver.JDBCRegExp#getReleaseSavepointPattern()
099: */
100: public Pattern getReleaseSavepointPattern() {
101: return RELEASE_SAVEPOINT_PATTERN;
102: }
103:
104: /**
105: * @see org.continuent.sequoia.driver.JDBCRegExp#getRollbackPattern()
106: */
107: public Pattern getRollbackPattern() {
108: return ROLLBACK_PATTERN;
109: }
110:
111: /**
112: * @see org.continuent.sequoia.driver.JDBCRegExp#getRollbackToSavepointPattern()
113: */
114: public Pattern getRollbackToSavepointPattern() {
115: return ROLLBACK_TO_SAVEPOINT_PATTERN;
116: }
117:
118: /**
119: * @see org.continuent.sequoia.driver.JDBCRegExp#getSetIsolationLevelPattern()
120: */
121: public Pattern getSetIsolationLevelPattern() {
122: return SET_ISOLATION_LEVEL_PATTERN;
123: }
124:
125: /**
126: * @see org.continuent.sequoia.driver.JDBCRegExp#getSetReadOnlyTransactionPattern()
127: */
128: public Pattern getSetReadOnlyTransactionPattern() {
129: return SET_READ_ONLY_TRANSACTION_PATTERN;
130: }
131:
132: /**
133: * @see org.continuent.sequoia.driver.JDBCRegExp#getSetSavepointPattern()
134: */
135: public Pattern getSetSavepointPattern() {
136: return SET_SAVEPOINT_PATTERN;
137: }
138:
139: /**
140: * @see org.continuent.sequoia.driver.JDBCRegExp#getSetAutocommitPattern()
141: */
142: public Pattern getSetAutocommit1Pattern() {
143: return SET_AUTOCOMMIT_1_PATTERN;
144: }
145:
146: }
|