1 package org.apache.ojb.broker.platforms; 2 3 17 18 import java.sql.PreparedStatement ; 19 import java.sql.SQLException ; 20 import java.sql.Types ; 21 import java.util.Properties ; 22 23 import org.apache.ojb.broker.query.LikeCriteria; 24 import org.apache.ojb.broker.util.sequence.SequenceManagerHelper; 25 26 121 122 public class PlatformPostgreSQLImpl extends PlatformDefaultImpl 123 { 124 public void setObjectForStatement(PreparedStatement ps, int index, Object value, int sqlType) throws SQLException 125 { 126 if ((value instanceof byte[]) && (sqlType == Types.LONGVARBINARY)) 127 { 128 ps.setBytes(index, (byte[]) value); 129 } 130 else 131 { 132 super.setObjectForStatement(ps, index, value, sqlType); 133 } 134 } 135 136 public String createSequenceQuery(String sequenceName) 137 { 138 return "create sequence " + sequenceName; 139 } 140 141 public String createSequenceQuery(String sequenceName, Properties prop) 142 { 143 148 StringBuffer query = new StringBuffer (createSequenceQuery(sequenceName)); 149 if(prop != null) 150 { 151 Boolean b; 152 Long value; 153 154 value = SequenceManagerHelper.getSeqIncrementBy(prop); 155 if(value != null) 156 { 157 query.append(" INCREMENT ").append(value.longValue()); 158 } 159 160 value = SequenceManagerHelper.getSeqMinValue(prop); 161 if(value != null) 162 { 163 query.append(" MINVALUE ").append(value.longValue()); 164 } 165 166 value = SequenceManagerHelper.getSeqMaxValue(prop); 167 if(value != null) 168 { 169 query.append(" MAXVALUE ").append(value.longValue()); 170 } 171 172 value = SequenceManagerHelper.getSeqStart(prop); 173 if(value != null) 174 { 175 query.append(" START ").append(value.longValue()); 176 } 177 178 value = SequenceManagerHelper.getSeqCacheValue(prop); 179 if(value != null) 180 { 181 query.append(" CACHE ").append(value.longValue()); 182 } 183 184 b = SequenceManagerHelper.getSeqCycleValue(prop); 185 if(b != null) 186 { 187 if(b.booleanValue()) query.append(" CYCLE"); 188 } 189 } 190 return query.toString(); 191 } 192 193 public String nextSequenceQuery(String sequenceName) 194 { 195 return "select nextval('" + sequenceName + "')"; 196 } 197 198 public String dropSequenceQuery(String sequenceName) 199 { 200 return "drop sequence " + sequenceName; 201 } 202 203 206 public void addPagingSql(StringBuffer anSqlString) 207 { 208 anSqlString.append(" LIMIT ? OFFSET ?"); 209 } 210 211 214 public boolean supportsPaging() 215 { 216 return true; 217 } 218 219 222 public int bindPagingParameters(PreparedStatement ps, int index, int startAt, int endAt) throws SQLException 223 { 224 ps.setInt(index, endAt - (startAt - 1)); index++; 226 ps.setInt(index, startAt - 1); index++; 228 return index; 229 } 230 231 234 public String getEscapeClause(LikeCriteria aCriteria) 235 { 236 if (LikeCriteria.getEscapeCharacter() != LikeCriteria.DEFAULT_ESCPAPE_CHARACTER) 237 { 238 return super.getEscapeClause(aCriteria); 240 } 241 else 242 { 243 return ""; 244 } 245 } 246 } 247 | Popular Tags |