%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.torque.adapter.DBFirebird |
|
|
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; |
|
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 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | return in; |
80 | } |
|
81 | ||
82 | /** |
|
83 | * @see org.apache.torque.adapter.DB#getIDMethodType() |
|
84 | */ |
|
85 | public String getIDMethodType() |
|
86 | { |
|
87 | 0 | 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 | 0 | 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 | 0 | Statement statement = con.createStatement(); |
108 | ||
109 | 0 | StringBuffer stmt = new StringBuffer(); |
110 | 0 | 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 | 0 | statement.executeQuery(stmt.toString()); |
118 | 0 | } |
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 | // Tables in Interbase are unlocked when a commit is issued. |
|
130 | // The user may have issued a commit but do it here to be |
|
131 | // sure. |
|
132 | 0 | con.commit(); |
133 | 0 | } |
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 | 0 | char delim = getStringDelimiter(); |
147 | 0 | 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 | 0 | 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 | 0 | return true; |
175 | } |
|
176 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |