001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.lucene.store.jdbc.dialect;
018:
019: import org.apache.lucene.store.jdbc.JdbcDirectorySettings;
020:
021: /**
022: * A database specific abstraction. All other dialects must extend this Dialect.
023: *
024: * @author kimchy
025: */
026: public abstract class Dialect {
027:
028: /**
029: * Process settings and apply any dialect related changes. Defaults to
030: * do nothing.
031: */
032: public void processSettings(JdbcDirectorySettings settings) {
033:
034: }
035:
036: /**
037: * Does the database (or the jdbc driver) supports transactional blob. Is so,
038: * can be used with the {@link org.apache.lucene.store.jdbc.index.FetchPerTransactionJdbcIndexInput}.
039: * Defaults to <code>false</code>.
040: */
041: public boolean supportTransactionalScopedBlobs() {
042: return false;
043: }
044:
045: /**
046: * Does the database support "if exists" before the table name when constructing
047: * a sql drop for the table. Defaults to <code>false<code>.
048: */
049: public boolean supportsIfExistsBeforeTableName() {
050: return false;
051: }
052:
053: /**
054: * Does the database support "if exists" after the table name when constructing
055: * a sql drop for the table. Defaults to <code>false</code>.
056: */
057: public boolean supportsIfExistsAfterTableName() {
058: return false;
059: }
060:
061: /**
062: * Does the dialect support a special query to check if a table exists.
063: * Defaults to <code>false</code>.
064: */
065: public boolean supportsTableExists() {
066: return false;
067: }
068:
069: /**
070: * If the dialect support a special query to check if a table exists, the actual
071: * sql that is used to perform it. Defaults to throw an Unsupported excetion (see
072: * {@link #supportsTableExists()}.
073: */
074: public String sqlTableExists(String catalog, String schemaName) {
075: throw new UnsupportedOperationException(
076: "Not sql provided to define if a table exists");
077: }
078:
079: /**
080: * Does the database require using an <code>InputStream</code> to insert a blob,
081: * or the <code>setBlob</code> method. Defaults to <code>true</code>.
082: */
083: public boolean useInputStreamToInsertBlob() {
084: return true;
085: }
086:
087: /**
088: * Do we need to perform a special check to see if the lock already exists in the database, or should
089: * we try and insert it without checking. Defaults to <code>true</code>.
090: */
091: public boolean useExistsBeforeInsertLock() {
092: return true;
093: }
094:
095: /**
096: * The opening quote for a quoted identifier. Defaults to ".
097: */
098: public char openQuote() {
099: return '"';
100: }
101:
102: /**
103: * The closing quote for a quoted identifier . Defaults to ".
104: */
105: public char closeQuote() {
106: return '"';
107: }
108:
109: /**
110: * Some database require quoting the blob in selects
111: */
112: public String openBlobSelectQuote() {
113: return "";
114: }
115:
116: /**
117: * Some database require quoting the blob in selects
118: */
119: public String closeBlobSelectQuote() {
120: return "";
121: }
122:
123: /**
124: * Completely optional cascading drop clause
125: */
126: public String getCascadeConstraintsString() {
127: return "";
128: }
129:
130: /**
131: * Does the database supports select ... for update sql clause?
132: */
133: public abstract boolean supportsForUpdate();
134:
135: /**
136: * Does this dialect support the <code>FOR UPDATE</code> syntax? Defaults to <code> for update</code>.
137: */
138: public String getForUpdateString() {
139: return " for update";
140: }
141:
142: /**
143: * Does this dialect support the Oracle-style <code>FOR UPDATE NOWAIT</code> syntax?
144: * Defaults to {@link #getForUpdateString()}.
145: */
146: public String getForUpdateNowaitString() {
147: return getForUpdateString();
148: }
149:
150: /**
151: * The type of the table that is created. Defaults to an empty string.
152: */
153: public String getTableTypeString() {
154: return "";
155: }
156:
157: /**
158: * Does the database supports a query for the current timestamp. Defaults to <code>false</code>.
159: */
160: public boolean supportsCurrentTimestampSelection() {
161: return false;
162: }
163:
164: /**
165: * The database current time stamp select query.
166: */
167: public String getCurrentTimestampSelectString() {
168: throw new UnsupportedOperationException(
169: "Database not known to define a current timestamp function");
170: }
171:
172: /**
173: * If the current timestamp select queyr is a callable query or not.
174: */
175: public boolean isCurrentTimestampSelectStringCallable() {
176: throw new UnsupportedOperationException(
177: "Database not known to define a current timestamp function");
178: }
179:
180: /**
181: * The database current timestamp function that is used with several sql updates.
182: */
183: public abstract String getCurrentTimestampFunction();
184:
185: /**
186: * The database varchar type for the given length. The length is in chars.
187: */
188: public abstract String getVarcharType(int length);
189:
190: /**
191: * The database blob type for the given length. The length is in KB.
192: */
193: public abstract String getBlobType(long length);
194:
195: /**
196: * The database number type.
197: */
198: public abstract String getNumberType();
199:
200: /**
201: * The database TIMESTAMP type.
202: */
203: public abstract String getTimestampType();
204:
205: /**
206: * The database BIT type.
207: */
208: public abstract String getBitType();
209:
210: }
|