%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.torque.adapter.DBPostgres |
|
|
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.text.DateFormat; |
|
25 | import java.text.SimpleDateFormat; |
|
26 | import java.util.Date; |
|
27 | ||
28 | import org.apache.torque.util.Query; |
|
29 | ||
30 | /** |
|
31 | * This is used to connect to PostgresQL databases. |
|
32 | * |
|
33 | * <a href="http://www.postgresql.org/">http://www.postgresql.org/</a> |
|
34 | * |
|
35 | * @author <a href="mailto:hakan42@gmx.de">Hakan Tandogan</a> |
|
36 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> |
|
37 | * @version $Id: DBPostgres.java 476497 2006-11-18 12:11:30Z tfischer $ |
|
38 | */ |
|
39 | public class DBPostgres extends AbstractDBAdapter |
|
40 | { |
|
41 | /** |
|
42 | * Serial version |
|
43 | */ |
|
44 | private static final long serialVersionUID = 7643304924262475272L; |
|
45 | ||
46 | /** A specialized date format for PostgreSQL. */ |
|
47 | private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; |
|
48 | ||
49 | /** |
|
50 | * Empty constructor. |
|
51 | */ |
|
52 | protected DBPostgres() |
|
53 | 16 | { |
54 | 16 | } |
55 | ||
56 | /** |
|
57 | * This method is used to ignore case. |
|
58 | * |
|
59 | * @param in The string to transform to upper case. |
|
60 | * @return The upper case string. |
|
61 | */ |
|
62 | public String toUpperCase(String in) |
|
63 | { |
|
64 | 0 | String s = new StringBuffer("UPPER(").append(in).append(")").toString(); |
65 | 0 | return s; |
66 | } |
|
67 | ||
68 | /** |
|
69 | * This method is used to ignore case. |
|
70 | * |
|
71 | * @param in The string whose case to ignore. |
|
72 | * @return The string in a case that can be ignored. |
|
73 | */ |
|
74 | public String ignoreCase(String in) |
|
75 | { |
|
76 | 0 | String s = new StringBuffer("UPPER(").append(in).append(")").toString(); |
77 | 0 | return s; |
78 | } |
|
79 | ||
80 | /** |
|
81 | * @see org.apache.torque.adapter.DB#getIDMethodType() |
|
82 | */ |
|
83 | public String getIDMethodType() |
|
84 | { |
|
85 | 0 | return SEQUENCE; |
86 | } |
|
87 | ||
88 | /** |
|
89 | * @param name The name of the field (should be of type |
|
90 | * <code>String</code>). |
|
91 | * @return SQL to retreive the next database key. |
|
92 | * @see org.apache.torque.adapter.DB#getIDMethodSQL(Object) |
|
93 | */ |
|
94 | public String getIDMethodSQL(Object name) |
|
95 | { |
|
96 | 0 | return ("select nextval('" + name + "')"); |
97 | } |
|
98 | ||
99 | /** |
|
100 | * Locks the specified table. |
|
101 | * |
|
102 | * @param con The JDBC connection to use. |
|
103 | * @param table The name of the table to lock. |
|
104 | * @exception SQLException No Statement could be created or executed. |
|
105 | */ |
|
106 | public void lockTable(Connection con, String table) throws SQLException |
|
107 | { |
|
108 | 0 | } |
109 | ||
110 | /** |
|
111 | * Unlocks the specified table. |
|
112 | * |
|
113 | * @param con The JDBC connection to use. |
|
114 | * @param table The name of the table to unlock. |
|
115 | * @exception SQLException No Statement could be created or executed. |
|
116 | */ |
|
117 | public void unlockTable(Connection con, String table) throws SQLException |
|
118 | { |
|
119 | 0 | } |
120 | ||
121 | /** |
|
122 | * This method is used to chek whether the database supports |
|
123 | * limiting the size of the resultset. |
|
124 | * |
|
125 | * @return LIMIT_STYLE_POSTGRES. |
|
126 | * @deprecated This should not be exposed to the outside |
|
127 | */ |
|
128 | public int getLimitStyle() |
|
129 | { |
|
130 | 0 | return DB.LIMIT_STYLE_POSTGRES; |
131 | } |
|
132 | ||
133 | /** |
|
134 | * Return true for PostgreSQL |
|
135 | * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeLimit() |
|
136 | */ |
|
137 | public boolean supportsNativeLimit() |
|
138 | { |
|
139 | 0 | return true; |
140 | } |
|
141 | ||
142 | /** |
|
143 | * Return true for PostgreSQL |
|
144 | * @see org.apache.torque.adapter.AbstractDBAdapter#supportsNativeOffset() |
|
145 | */ |
|
146 | public boolean supportsNativeOffset() |
|
147 | { |
|
148 | 0 | return true; |
149 | } |
|
150 | ||
151 | /** |
|
152 | * Generate a LIMIT limit OFFSET offset clause if offset > 0 |
|
153 | * or an LIMIT limit clause if limit is > 0 and offset |
|
154 | * is 0. |
|
155 | * |
|
156 | * @param query The query to modify |
|
157 | * @param offset the offset Value |
|
158 | * @param limit the limit Value |
|
159 | */ |
|
160 | public void generateLimits(Query query, int offset, class="keyword">int limit) |
|
161 | { |
|
162 | 0 | StringBuffer limitStringBuffer = new StringBuffer(); |
163 | ||
164 | 0 | if (offset > 0) |
165 | { |
|
166 | 0 | limitStringBuffer.append(limit) |
167 | .append(" offset ") |
|
168 | .append(offset); |
|
169 | 0 | } |
170 | else |
|
171 | { |
|
172 | 0 | if (limit >= 0) |
173 | { |
|
174 | 0 | limitStringBuffer.append(limit); |
175 | } |
|
176 | } |
|
177 | ||
178 | 0 | query.setLimit(limitStringBuffer.toString()); |
179 | 0 | query.setPreLimit(null); |
180 | 0 | query.setPostLimit(null); |
181 | 0 | } |
182 | ||
183 | /** |
|
184 | * Override the default behavior to associate b with null? |
|
185 | * |
|
186 | * @see DB#getBooleanString(Boolean) |
|
187 | */ |
|
188 | public String getBooleanString(Boolean b) |
|
189 | { |
|
190 | 16 | return (b == null) ? "FALSE" : (Boolean.TRUE.equals(b) ? "TRUE" : "FALSE"); |
191 | } |
|
192 | ||
193 | /** |
|
194 | * This method overrides the JDBC escapes used to format dates |
|
195 | * using a <code>DateFormat</code>. |
|
196 | * |
|
197 | * This generates the timedate format defined in |
|
198 | * http://www.postgresql.org/docs/7.3/static/datatype-datetime.html |
|
199 | * which defined PostgreSQL dates as YYYY-MM-DD hh:mm:ss |
|
200 | * @param date the date to format |
|
201 | * @return The properly formatted date String. |
|
202 | */ |
|
203 | public String getDateString(Date date) |
|
204 | { |
|
205 | 0 | DateFormat df = new SimpleDateFormat(DATE_FORMAT); |
206 | 0 | StringBuffer dateBuf = new StringBuffer(); |
207 | 0 | char delim = getStringDelimiter(); |
208 | 0 | dateBuf.append(delim); |
209 | 0 | dateBuf.append(df.format(date)); |
210 | 0 | dateBuf.append(delim); |
211 | 0 | return dateBuf.toString(); |
212 | } |
|
213 | ||
214 | /** |
|
215 | * Whether ILIKE should be used for case insensitive like clauses. |
|
216 | * |
|
217 | * As postgres uses ILIKE, this mimplementation returns true. |
|
218 | * |
|
219 | * @return true if ilike should be used for case insensitive likes, |
|
220 | * false if ignoreCase should be applied to the compared strings. |
|
221 | */ |
|
222 | public boolean useIlike() |
|
223 | { |
|
224 | 0 | return true; |
225 | } |
|
226 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |