KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > torque > adapter > DBCloudscape


1 package org.apache.torque.adapter;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */

21
22 import java.sql.Connection JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.util.StringTokenizer JavaDoc;
25
26 /**
27  * This is used to connect to Cloudscape SQL databases.
28  *
29  * @author <a HREF="mailto:taylor@apache.org">David Sean Taylor</a>
30  * @version $Id: DBCloudscape.java 473821 2006-11-11 22:37:25Z tv $
31  */

32 public class DBCloudscape extends AbstractDBAdapter
33 {
34     /**
35      * Serial version
36      */

37     private static final long serialVersionUID = -7475830417640153351L;
38
39     /** qualifier */
40     private static final String JavaDoc QUALIFIER = ".";
41
42     /**
43      * Constructor.
44      */

45     protected DBCloudscape()
46     {
47     }
48     /**
49      * This method is used to ignore case.
50      *
51      * @param in The string to transform to upper case.
52      * @return The upper case string.
53      */

54     public String JavaDoc toUpperCase(String JavaDoc in)
55     {
56         return in;
57     }
58
59     /**
60      * This method is used to ignore case.
61      *
62      * @param in The string whose case to ignore.
63      * @return The string in a case that can be ignored.
64      */

65     public String JavaDoc ignoreCase(String JavaDoc in)
66     {
67         return in;
68     }
69
70     /**
71      * @see org.apache.torque.adapter.DB#getIDMethodType()
72      */

73     public String JavaDoc getIDMethodType()
74     {
75         return AUTO_INCREMENT;
76     }
77
78     /**
79      * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
80      */

81     public String JavaDoc getIDMethodSQL(Object JavaDoc obj)
82     {
83         StringBuffer JavaDoc sql = new StringBuffer JavaDoc(132);
84         sql.append("select distinct ConnectionInfo.lastAutoincrementValue(");
85
86         String JavaDoc qualifiedIdentifier = (String JavaDoc) obj;
87
88         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(qualifiedIdentifier,
89                 QUALIFIER);
90         int count = tokenizer.countTokens();
91
92         String JavaDoc schema, table, column;
93
94         System.out.println("qi = " + qualifiedIdentifier);
95         // no qualifiers, its simply a column name
96
switch (count)
97         {
98         case 0:
99             /* return ""; */ // not valid -- we need the column name and table name
100
case 1:
101             return ""; // not valid -- we need the table name to select from
102

103         case 2:
104             table = tokenizer.nextToken();
105             column = tokenizer.nextToken();
106             sql.append("'APP', '");
107             sql.append(table);
108             break;
109
110         case 3:
111             schema = tokenizer.nextToken();
112             table = tokenizer.nextToken();
113             column = tokenizer.nextToken();
114             sql.append("'");
115             sql.append(schema);
116             sql.append("', '");
117             sql.append(table);
118             break;
119
120         default:
121             return ""; // not valid
122
}
123
124         sql.append("', '");
125         sql.append(column);
126         sql.append("') FROM ");
127         sql.append(table);
128
129         System.out.println(sql.toString());
130         return sql.toString();
131     }
132
133     /**
134      * Locks the specified table.
135      *
136      * @param con The JDBC connection to use.
137      * @param table The name of the table to lock.
138      * @exception SQLException No Statement could be created or executed.
139      */

140     public void lockTable(Connection JavaDoc con, String JavaDoc table) throws SQLException JavaDoc
141     {
142     }
143
144     /**
145      * Unlocks the specified table.
146      *
147      * @param con The JDBC connection to use.
148      * @param table The name of the table to unlock.
149      * @exception SQLException No Statement could be created or executed.
150      */

151     public void unlockTable(Connection JavaDoc con, String JavaDoc table) throws SQLException JavaDoc
152     {
153     }
154 }
155
Popular Tags