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.util.sequence.SequenceManagerHelper; 24 25 128 public class PlatformDb2Impl extends PlatformDefaultImpl 129 { 130 134 public void setObjectForStatement(PreparedStatement ps, int index, 135 Object value, int sqlType) throws SQLException 136 { 137 if (sqlType == Types.TINYINT) 138 { 139 ps.setByte(index, ((Byte ) value).byteValue()); 140 } 141 else 142 { 143 super.setObjectForStatement(ps, index, value, sqlType); 144 } 145 } 146 147 public String createSequenceQuery(String sequenceName) 148 { 149 return "create sequence " + sequenceName; 150 } 151 152 public String createSequenceQuery(String sequenceName, Properties prop) 153 { 154 180 StringBuffer query = new StringBuffer (createSequenceQuery(sequenceName)); 181 if(prop != null) 182 { 183 Boolean b; 184 Long value; 185 String str; 186 187 str = SequenceManagerHelper.getSeqAsValue(prop); 188 if(str != null) 189 { 190 query.append(" AS ").append(str); 191 } 192 193 value = SequenceManagerHelper.getSeqStart(prop); 194 if(value != null) 195 { 196 query.append(" START WITH ").append(value.longValue()); 197 } 198 199 value = SequenceManagerHelper.getSeqIncrementBy(prop); 200 if(value != null) 201 { 202 query.append(" INCREMENT BY ").append(value.longValue()); 203 } 204 205 value = SequenceManagerHelper.getSeqMinValue(prop); 206 if(value != null) 207 { 208 query.append(" MINVALUE ").append(value.longValue()); 209 } 210 211 value = SequenceManagerHelper.getSeqMaxValue(prop); 212 if(value != null) 213 { 214 query.append(" MAXVALUE ").append(value.longValue()); 215 } 216 217 b = SequenceManagerHelper.getSeqCycleValue(prop); 218 if(b != null) 219 { 220 if(b.booleanValue()) query.append(" CYCLE"); 221 else query.append(" NO CYCLE"); 222 } 223 224 value = SequenceManagerHelper.getSeqCacheValue(prop); 225 if(value != null) 226 { 227 query.append(" CACHE ").append(value.longValue()); 228 } 229 230 b = SequenceManagerHelper.getSeqOrderValue(prop); 231 if(b != null) 232 { 233 if(b.booleanValue()) query.append(" ORDER"); 234 else query.append(" NO ORDER"); 235 } 236 } 237 return query.toString(); 238 } 239 240 public String nextSequenceQuery(String sequenceName) 241 { 242 return "values nextval for "+ sequenceName; 243 } 244 245 public String dropSequenceQuery(String sequenceName) 246 { 247 return "drop sequence " + sequenceName; 248 } 249 250 public String getLastInsertIdentityQuery(String tableName) 251 { 252 return "values IDENTITY_VAL_LOCAL()"; 260 } 261 } 262 | Popular Tags |