1 package org.apache.torque.adapter;
2
3 /* ====================================================================
4 * The Apache Software License, Version 1.1
5 *
6 * Copyright (c) 2001 The Apache Software Foundation. All rights
7 * reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. The end-user documentation included with the redistribution,
22 * if any, must include the following acknowledgment:
23 * "This product includes software developed by the
24 * Apache Software Foundation (http://www.apache.org/)."
25 * Alternately, this acknowledgment may appear in the software itself,
26 * if and wherever such third-party acknowledgments normally appear.
27 *
28 * 4. The names "Apache" and "Apache Software Foundation" and
29 * "Apache Turbine" must not be used to endorse or promote products
30 * derived from this software without prior written permission. For
31 * written permission, please contact apache@apache.org.
32 *
33 * 5. Products derived from this software may not be called "Apache",
34 * "Apache Turbine", nor may "Apache" appear in their name, without
35 * prior written permission of the Apache Software Foundation.
36 *
37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48 * SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This software consists of voluntary contributions made by many
52 * individuals on behalf of the Apache Software Foundation. For more
53 * information on the Apache Software Foundation, please see
54 * <http://www.apache.org/>.
55 */
56
57 import java.sql.Connection;
58 import java.sql.SQLException;
59 import java.sql.Statement;
60 import java.util.Date;
61 import java.text.SimpleDateFormat;
62
63 /***
64 * This is used to connect to a Sybase database using Sybase's
65 * JConnect JDBC driver.
66 *
67 * <B>NOTE:</B><I>Currently JConnect does not implement the required
68 * methods for ResultSetMetaData, and therefore the village API's may
69 * not function. For connection pooling, everything works.</I>
70 *
71 * @author <a href="mailto:ekkerbj@netscape.net">Jeff Brekke</a>
72 * @version $Id: DBSybase.java,v 1.8 2002/09/19 14:33:31 mpoeschl Exp $
73 */
74 public class DBSybase extends DB
75 {
76 /*** date format */
77 private static final String DATE_FORMAT = "yyyyMMdd HH:mm:ss";
78
79 /***
80 * Empty constructor.
81 */
82 protected DBSybase()
83 {
84 }
85
86 /***
87 * This method is used to ignore case.
88 *
89 * @param in The string to transform to upper case.
90 * @return The upper case string.
91 */
92 public String toUpperCase(String in)
93 {
94 return new StringBuffer("UPPER(").append(in).append(")").toString();
95 }
96
97 /***
98 * This method is used to ignore case.
99 *
100 * @param in The string whose case to ignore.
101 * @return The string in a case that can be ignored.
102 */
103 public String ignoreCase(String in)
104 {
105 return new StringBuffer("UPPER(").append(in).append(")").toString();
106 }
107
108 /***
109 * @see org.apache.torque.adapter.DB#getIDMethodType()
110 */
111 public String getIDMethodType()
112 {
113 return AUTO_INCREMENT;
114 }
115
116 /***
117 * Returns the last value from an identity column (available on a
118 * per-session basis from the global variable
119 * <code>@@identity</code>).
120 *
121 * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
122 */
123 public String getIDMethodSQL(Object unused)
124 {
125 return "select @@identity";
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 * @throws SQLException No Statement could be created or executed.
134 */
135 public void lockTable(Connection con, String table) throws SQLException
136 {
137 Statement statement = con.createStatement();
138
139 StringBuffer stmt = new StringBuffer();
140 stmt.append("SELECT next_id FROM ")
141 .append(table)
142 .append(" FOR UPDATE");
143
144 statement.executeQuery(stmt.toString());
145 }
146
147 /***
148 * Unlocks the specified table.
149 *
150 * @param con The JDBC connection to use.
151 * @param table The name of the table to unlock.
152 * @throws SQLException No Statement could be created or executed.
153 */
154 public void unlockTable(Connection con, String table) throws SQLException
155 {
156 // Tables in Sybase are unlocked when a commit is issued. The
157 // user may have issued a commit but do it here to be sure.
158 con.commit();
159 }
160
161 /***
162 * This method is used to chek whether the database natively
163 * supports limiting the size of the resultset.
164 *
165 * @return True.
166 */
167 public boolean supportsNativeLimit()
168 {
169 return true;
170 }
171
172 /***
173 * This method is used to chek whether the database supports
174 * limiting the size of the resultset.
175 *
176 * @return LIMIT_STYLE_SYBASE.
177 */
178 public int getLimitStyle()
179 {
180 return DB.LIMIT_STYLE_SYBASE;
181 }
182
183 /***
184 * This method overrides the JDBC escapes used to format dates
185 * using a <code>DateFormat</code>. As of version 11, the Sybase
186 * JDBC driver does not implement JDBC 3.0 escapes.
187 *
188 * @param date the date to format
189 * @return The properly formatted date String.
190 */
191 public String getDateString(Date date)
192 {
193 char delim = getStringDelimiter();
194 return (delim + new SimpleDateFormat(DATE_FORMAT).format(date) + delim);
195 }
196 }
This page was automatically generated by Maven