001: package org.apache.torque.adapter;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import java.sql.Connection;
023: import java.sql.SQLException;
024: import java.sql.Statement;
025: import java.util.Date;
026: import java.text.SimpleDateFormat;
027:
028: /**
029: * This code should be used for an Interbase database pool.
030: *
031: * @author <a href="mailto:frank@opticode.co.za">Frank Conradie</a>
032: * @version $Id: DBInterbase.java 476550 2006-11-18 16:08:37Z tfischer $
033: */
034: public class DBInterbase extends AbstractDBAdapter {
035: /**
036: * Serial version
037: */
038: private static final long serialVersionUID = -6709312389168248070L;
039:
040: /**
041: * The format in which interbase expects dates (with time).
042: */
043: private static final String DATE_FORMAT = "yyyy-MM-dd HH:MM:ss";
044:
045: /**
046: * This method is used to ignore case.
047: *
048: * @param in The string to transform to upper case.
049: * @return The upper case string.
050: */
051: public String toUpperCase(String in) {
052: return new StringBuffer("UPPER(").append(in).append(")")
053: .toString();
054: }
055:
056: /**
057: * This method is used to ignore case.
058: *
059: * @param in The string whose case to ignore.
060: * @return The string in a case that can be ignored.
061: */
062: public String ignoreCase(String in) {
063: return new StringBuffer("UPPER(").append(in).append(")")
064: .toString();
065: }
066:
067: /**
068: * This method is used to ignore case in an ORDER BY clause.
069: * Usually it is the same as ignoreCase, but some databases
070: * (Interbase for example) does not use the same SQL in ORDER BY
071: * and other clauses.
072: *
073: * @param in The string whose case to ignore.
074: * @return The string in a case that can be ignored.
075: */
076: public String ignoreCaseInOrderBy(String in) {
077: return in;
078: }
079:
080: /**
081: * @see org.apache.torque.adapter.DB#getIDMethodType()
082: */
083: public String getIDMethodType() {
084: return NO_ID_METHOD;
085: }
086:
087: /**
088: * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
089: */
090: public String getIDMethodSQL(Object obj) {
091: return null;
092: }
093:
094: /**
095: * Locks the specified table.
096: *
097: * @param con The JDBC connection to use.
098: * @param table The name of the table to lock.
099: * @exception SQLException No Statement could be created or executed.
100: */
101: public void lockTable(Connection con, String table)
102: throws SQLException {
103: Statement statement = con.createStatement();
104:
105: StringBuffer stmt = new StringBuffer();
106: stmt.append("SET TRANSACTION ").append(
107: "ISOLATION LEVEL READ COMMITTED ").append(
108: "NO RECORD_VERSION WAIT ").append("RESERVING ").append(
109: table).append(" FOR PROTECTED WRITE");
110:
111: statement.executeQuery(stmt.toString());
112: }
113:
114: /**
115: * Unlocks the specified table.
116: *
117: * @param con The JDBC connection to use.
118: * @param table The name of the table to unlock.
119: * @exception SQLException No Statement could be created or executed.
120: */
121: public void unlockTable(Connection con, String table)
122: throws SQLException {
123: // Tables in Interbase are unlocked when a commit is issued.
124: // The user may have issued a commit but do it here to be
125: // sure.
126: con.commit();
127: }
128:
129: /**
130: * This method overrides the JDBC escapes used to format dates
131: * using a <code>DateFormat</code>. As of version 2.0.11, the MM
132: * JDBC driver does not implement JDBC 3.0 escapes.
133: *
134: * @param date the date to format
135: * @return The properly formatted date String.
136: */
137: public String getDateString(Date date) {
138: char delim = getStringDelimiter();
139: return (delim + new SimpleDateFormat(DATE_FORMAT).format(date) + delim);
140: }
141:
142: /**
143: * This method is for the SqlExpression.quoteAndEscape rules. The rule is,
144: * any string in a SqlExpression with a BACKSLASH will either be changed to
145: * "\\" (if the method returns true) or left as "\" (if the method returns
146: * false).
147: *
148: * @return false.
149: */
150: public boolean escapeText() {
151: return false;
152: }
153:
154: /**
155: * Whether an escape clause in like should be used.
156: * Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';
157: *
158: * Interbase needs this, so this implementation always returns
159: * <code>true</code>.
160: *
161: * @return whether the escape clause should be appended or not.
162: */
163: public boolean useEscapeClauseForLike() {
164: return true;
165: }
166: }
|