1 package org.apache.torque.adapter;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
157
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 }