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:
026: /**
027: * This is used to connect to an embedded Apache Derby Database using
028: * the supplied JDBC driver.
029: *
030: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
031: * @version $Id: DBDerby.java 473821 2006-11-11 22:37:25Z tv $
032: */
033: public class DBDerby extends AbstractDBAdapter {
034: /**
035: * Serial version
036: */
037: private static final long serialVersionUID = 6265962681516206415L;
038:
039: /**
040: * Empty constructor.
041: */
042: protected DBDerby() {
043: }
044:
045: /**
046: * This method is used to ignore case.
047: *
048: * @param str The string to transform to upper case.
049: * @return The upper case string.
050: */
051: public String toUpperCase(String str) {
052: return new StringBuffer("UPPER(").append(str).append(")")
053: .toString();
054: }
055:
056: /**
057: * This method is used to ignore case.
058: *
059: * @param str The string whose case to ignore.
060: * @return The string in a case that can be ignored.
061: */
062: public String ignoreCase(String str) {
063: return toUpperCase(str);
064: }
065:
066: /**
067: * @see org.apache.torque.adapter.DB#getIDMethodType()
068: */
069: public String getIDMethodType() {
070: return AUTO_INCREMENT;
071: }
072:
073: /**
074: * Returns the SQL to get the database key of the last row
075: * inserted, which in this case is
076: * <code>VALUES IDENTITY_VAL_LOCAL()</code>.
077: *
078: * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
079: */
080: public String getIDMethodSQL(Object obj) {
081: return "VALUES IDENTITY_VAL_LOCAL()";
082: }
083:
084: /**
085: * Locks the specified table.
086: *
087: * @param con The JDBC connection to use.
088: * @param table The name of the table to lock.
089: * @exception SQLException No Statement could be created or executed.
090: */
091: public void lockTable(Connection con, String table)
092: throws SQLException {
093: Statement statement = con.createStatement();
094: StringBuffer stmt = new StringBuffer();
095: stmt.append("LOCK TABLE ").append(table).append(
096: " IN EXCLUSIVE MODE");
097: statement.executeUpdate(stmt.toString());
098: }
099:
100: /**
101: * Unlocks the specified table.
102: *
103: * @param con The JDBC connection to use.
104: * @param table The name of the table to unlock.
105: * @exception SQLException No Statement could be created or executed.
106: */
107: public void unlockTable(Connection con, String table)
108: throws SQLException {
109: }
110:
111: /**
112: * Whether backslashes (\) should be escaped in explicit SQL strings.
113: * If true is returned, a BACKSLASH will be changed to "\\". If false
114: * is returned, a BACKSLASH will be left as "\".
115: *
116: * As derby does not need escaping of Backslashes, this method always
117: * returns false.
118: *
119: * @return true if the database needs to escape backslashes
120: * in SqlExpressions.
121: */
122:
123: public boolean escapeText() {
124: return false;
125: }
126:
127: /**
128: * Whether an escape clause in like should be used.
129: * Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';
130: *
131: * Derby needs this, so this implementation always returns
132: * <code>true</code>.
133: *
134: * @return whether the escape clause should be appended or not.
135: */
136: public boolean useEscapeClauseForLike() {
137: return true;
138: }
139: }
|