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 SapDB databases.
028: *
029: * <a href="http://www.sapdb.org">http://www.sapdb.org</a>
030: *
031: * @author <a href="mailto:dave.polito@planetcad.com">Dave Polito</a>
032: * @version $Id: DBSapDB.java 473821 2006-11-11 22:37:25Z tv $
033: */
034: public class DBSapDB extends AbstractDBAdapter {
035: /**
036: * Serial version
037: */
038: private static final long serialVersionUID = 8277068258155186370L;
039:
040: /**
041: * Empty constructor.
042: */
043: protected DBSapDB() {
044: }
045:
046: /**
047: * This method is used to ignore case.
048: *
049: * @param in The string to transform to upper case.
050: * @return The upper case string.
051: */
052: public String toUpperCase(String in) {
053: return new StringBuffer("UPPER(").append(in).append(")")
054: .toString();
055: }
056:
057: /**
058: * This method is used to ignore case.
059: *
060: * @param in The string whose case to ignore.
061: * @return The string in a case that can be ignored.
062: */
063: public String ignoreCase(String in) {
064: return new StringBuffer("UPPER(").append(in).append(")")
065: .toString();
066: }
067:
068: /**
069: * @see org.apache.torque.adapter.DB#getIDMethodType()
070: */
071: public String getIDMethodType() {
072: return SEQUENCE;
073: }
074:
075: /**
076: * Returns the next key from a sequence. Uses the following
077: * implementation:
078: *
079: * <blockquote><code><pre>
080: * select sequenceName.nextval from dual
081: * </pre></code></blockquote>
082: *
083: * @param sequenceName The name of the sequence (should be of type
084: * <code>String</code>).
085: * @return SQL to retreive the next database key.
086: * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object)
087: */
088: public String getIDMethodSQL(Object sequenceName) {
089: return ("select " + sequenceName + ".nextval from dual");
090: }
091:
092: /**
093: * Locks the specified table.
094: *
095: * @param con The JDBC connection to use.
096: * @param table The name of the table to lock.
097: * @exception SQLException No Statement could be created or executed.
098: */
099: public void lockTable(Connection con, String table)
100: throws SQLException {
101: Statement statement = con.createStatement();
102:
103: StringBuffer stmt = new StringBuffer();
104: stmt.append("SELECT next_id FROM ").append(table).append(
105: " FOR UPDATE");
106:
107: statement.executeQuery(stmt.toString());
108: }
109:
110: /**
111: * This method is for the SqlExpression.quoteAndEscape rules. The rule is,
112: * any string in a SqlExpression with a BACKSLASH will either be changed to
113: * "\\" or left as "\". SapDB does not need the escape character.
114: *
115: * @return false.
116: */
117:
118: public boolean escapeText() {
119: return false;
120: }
121:
122: /**
123: * Unlocks the specified table.
124: *
125: * @param con The JDBC connection to use.
126: * @param table The name of the table to unlock.
127: * @exception SQLException No Statement could be created or
128: * executed.
129: */
130: public void unlockTable(Connection con, String table)
131: throws SQLException {
132: // Tables in SapDB are unlocked when a commit is issued. The
133: // user may have issued a commit but do it here to be sure.
134: con.commit();
135: }
136: }
|