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 import java.sql.Connection;
23 import java.sql.SQLException;
24 import java.sql.Statement;
25 import java.util.Date;
26 import java.text.SimpleDateFormat;
27
28 /***
29 * This code should be used for a Firebird database pool.
30 *
31 * @author Joerg Friedrich
32 * @version $Id: DBInterbase.java 239630 2005-08-24 12:25:32Z henning $
33 */
34 public class DBFirebird extends AbstractDBAdapter
35 {
36 /***
37 * Serial version.
38 */
39 private static final long serialVersionUID = -2782124791802056450L;
40
41 /***
42 * The format in which firebird expects dates (with time).
43 */
44 private static final String DATE_FORMAT = "yyyy-MM-dd HH:MM:ss";
45
46 /***
47 * This method is used to ignore case.
48 *
49 * @param in The string to transform to upper case.
50 * @return The upper case string.
51 */
52 public String toUpperCase(String in)
53 {
54 return new StringBuffer("UPPER(").append(in).append(")").toString();
55 }
56
57 /***
58 * This method is used to ignore case.
59 *
60 * @param in The string whose case to ignore.
61 * @return The string in a case that can be ignored.
62 */
63 public String ignoreCase(String in)
64 {
65 return new StringBuffer("UPPER(").append(in).append(")").toString();
66 }
67
68 /***
69 * This method is used to ignore case in an ORDER BY clause.
70 * Usually it is the same as ignoreCase, but some databases
71 * (Interbase for example) does not use the same SQL in ORDER BY
72 * and other clauses.
73 *
74 * @param in The string whose case to ignore.
75 * @return The string in a case that can be ignored.
76 */
77 public String ignoreCaseInOrderBy(String in)
78 {
79 return in;
80 }
81
82 /***
83 * @see org.apache.torque.adapter.DB#getIDMethodType()
84 */
85 public String getIDMethodType()
86 {
87 return NO_ID_METHOD;
88 }
89
90 /***
91 * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object obj)
92 */
93 public String getIDMethodSQL(Object obj)
94 {
95 return null;
96 }
97
98 /***
99 * Locks the specified table.
100 *
101 * @param con The JDBC connection to use.
102 * @param table The name of the table to lock.
103 * @exception SQLException No Statement could be created or executed.
104 */
105 public void lockTable(Connection con, String table) throws SQLException
106 {
107 Statement statement = con.createStatement();
108
109 StringBuffer stmt = new StringBuffer();
110 stmt.append("SET TRANSACTION ")
111 .append("ISOLATION LEVEL READ COMMITTED ")
112 .append("NO RECORD_VERSION WAIT ")
113 .append("RESERVING ")
114 .append(table)
115 .append(" FOR PROTECTED WRITE");
116
117 statement.executeQuery(stmt.toString());
118 }
119
120 /***
121 * Unlocks the specified table.
122 *
123 * @param con The JDBC connection to use.
124 * @param table The name of the table to unlock.
125 * @exception SQLException No Statement could be created or executed.
126 */
127 public void unlockTable(Connection con, String table) throws SQLException
128 {
129
130
131
132 con.commit();
133 }
134
135
136 /***
137 * This method overrides the JDBC escapes used to format dates
138 * using a <code>DateFormat</code>. As of version 2.0.11, the MM
139 * JDBC driver does not implement JDBC 3.0 escapes.
140 *
141 * @param date the date to format
142 * @return The properly formatted date String.
143 */
144 public String getDateString(Date date)
145 {
146 char delim = getStringDelimiter();
147 return (delim + new SimpleDateFormat(DATE_FORMAT).format(date) + delim);
148 }
149
150 /***
151 * This method is for the SqlExpression.quoteAndEscape rules. The rule is,
152 * any string in a SqlExpression with a BACKSLASH will either be changed to
153 * "//" (if the method returns true) or left as "\" (if the method returns
154 * false).
155 *
156 * @return false.
157 */
158 public boolean escapeText()
159 {
160 return false;
161 }
162
163 /***
164 * Whether an escape clause in like should be used.
165 * Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\';
166 *
167 * Firebird needs this, so this implementation always returns
168 * <code>true</code>.
169 *
170 * @return whether the escape clause should be appended or not.
171 */
172 public boolean useEscapeClauseForLike()
173 {
174 return true;
175 }
176 }