1 package org.apache.torque.adapter; 2 3 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 39 public class DBPostgres extends AbstractDBAdapter 40 { 41 44 private static final long serialVersionUID = 7643304924262475272L; 45 46 47 private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; 48 49 52 protected DBPostgres() 53 { 54 } 55 56 62 public String toUpperCase(String in) 63 { 64 String s = new StringBuffer ("UPPER(").append(in).append(")").toString(); 65 return s; 66 } 67 68 74 public String ignoreCase(String in) 75 { 76 String s = new StringBuffer ("UPPER(").append(in).append(")").toString(); 77 return s; 78 } 79 80 83 public String getIDMethodType() 84 { 85 return SEQUENCE; 86 } 87 88 94 public String getIDMethodSQL(Object name) 95 { 96 return ("select nextval('" + name + "')"); 97 } 98 99 106 public void lockTable(Connection con, String table) throws SQLException 107 { 108 } 109 110 117 public void unlockTable(Connection con, String table) throws SQLException 118 { 119 } 120 121 128 public int getLimitStyle() 129 { 130 return DB.LIMIT_STYLE_POSTGRES; 131 } 132 133 137 public boolean supportsNativeLimit() 138 { 139 return true; 140 } 141 142 146 public boolean supportsNativeOffset() 147 { 148 return true; 149 } 150 151 160 public void generateLimits(Query query, int offset, int limit) 161 { 162 StringBuffer limitStringBuffer = new StringBuffer (); 163 164 if (offset > 0) 165 { 166 limitStringBuffer.append(limit) 167 .append(" offset ") 168 .append(offset); 169 } 170 else 171 { 172 if (limit >= 0) 173 { 174 limitStringBuffer.append(limit); 175 } 176 } 177 178 query.setLimit(limitStringBuffer.toString()); 179 query.setPreLimit(null); 180 query.setPostLimit(null); 181 } 182 183 188 public String getBooleanString(Boolean b) 189 { 190 return (b == null) ? "FALSE" : (Boolean.TRUE.equals(b) ? "TRUE" : "FALSE"); 191 } 192 193 203 public String getDateString(Date date) 204 { 205 DateFormat df = new SimpleDateFormat (DATE_FORMAT); 206 StringBuffer dateBuf = new StringBuffer (); 207 char delim = getStringDelimiter(); 208 dateBuf.append(delim); 209 dateBuf.append(df.format(date)); 210 dateBuf.append(delim); 211 return dateBuf.toString(); 212 } 213 214 222 public boolean useIlike() 223 { 224 return true; 225 } 226 } 227 | Popular Tags |