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.util.StringTokenizer;
025:
026: /**
027: * This is used to connect to Cloudscape SQL databases.
028: *
029: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
030: * @version $Id: DBCloudscape.java 473821 2006-11-11 22:37:25Z tv $
031: */
032: public class DBCloudscape extends AbstractDBAdapter {
033: /**
034: * Serial version
035: */
036: private static final long serialVersionUID = -7475830417640153351L;
037:
038: /** qualifier */
039: private static final String QUALIFIER = ".";
040:
041: /**
042: * Constructor.
043: */
044: protected DBCloudscape() {
045: }
046:
047: /**
048: * This method is used to ignore case.
049: *
050: * @param in The string to transform to upper case.
051: * @return The upper case string.
052: */
053: public String toUpperCase(String in) {
054: return in;
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 in;
065: }
066:
067: /**
068: * @see org.apache.torque.adapter.DB#getIDMethodType()
069: */
070: public String getIDMethodType() {
071: return AUTO_INCREMENT;
072: }
073:
074: /**
075: * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
076: */
077: public String getIDMethodSQL(Object obj) {
078: StringBuffer sql = new StringBuffer(132);
079: sql
080: .append("select distinct ConnectionInfo.lastAutoincrementValue(");
081:
082: String qualifiedIdentifier = (String) obj;
083:
084: StringTokenizer tokenizer = new StringTokenizer(
085: qualifiedIdentifier, QUALIFIER);
086: int count = tokenizer.countTokens();
087:
088: String schema, table, column;
089:
090: System.out.println("qi = " + qualifiedIdentifier);
091: // no qualifiers, its simply a column name
092: switch (count) {
093: case 0:
094: /* return ""; */// not valid -- we need the column name and table name
095: case 1:
096: return ""; // not valid -- we need the table name to select from
097:
098: case 2:
099: table = tokenizer.nextToken();
100: column = tokenizer.nextToken();
101: sql.append("'APP', '");
102: sql.append(table);
103: break;
104:
105: case 3:
106: schema = tokenizer.nextToken();
107: table = tokenizer.nextToken();
108: column = tokenizer.nextToken();
109: sql.append("'");
110: sql.append(schema);
111: sql.append("', '");
112: sql.append(table);
113: break;
114:
115: default:
116: return ""; // not valid
117: }
118:
119: sql.append("', '");
120: sql.append(column);
121: sql.append("') FROM ");
122: sql.append(table);
123:
124: System.out.println(sql.toString());
125: return sql.toString();
126: }
127:
128: /**
129: * Locks the specified table.
130: *
131: * @param con The JDBC connection to use.
132: * @param table The name of the table to lock.
133: * @exception SQLException No Statement could be created or executed.
134: */
135: public void lockTable(Connection con, String table)
136: throws SQLException {
137: }
138:
139: /**
140: * Unlocks the specified table.
141: *
142: * @param con The JDBC connection to use.
143: * @param table The name of the table to unlock.
144: * @exception SQLException No Statement could be created or executed.
145: */
146: public void unlockTable(Connection con, String table)
147: throws SQLException {
148: }
149: }
|