| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
package com.buckosoft.PicMan.db; |
| 9 | |
|
| 10 | |
import java.sql.ResultSet; |
| 11 | |
import java.sql.SQLException; |
| 12 | |
import java.sql.Types; |
| 13 | |
import java.util.Calendar; |
| 14 | |
import java.util.Date; |
| 15 | |
import java.util.HashMap; |
| 16 | |
import java.util.Iterator; |
| 17 | |
import java.util.LinkedList; |
| 18 | |
import java.util.List; |
| 19 | |
|
| 20 | |
import javax.sql.DataSource; |
| 21 | |
|
| 22 | |
import org.apache.commons.logging.Log; |
| 23 | |
import org.apache.commons.logging.LogFactory; |
| 24 | |
import org.springframework.dao.DataAccessException; |
| 25 | |
import org.springframework.jdbc.core.SqlParameter; |
| 26 | |
import org.springframework.jdbc.object.MappingSqlQuery; |
| 27 | |
import org.springframework.jdbc.object.SqlFunction; |
| 28 | |
import org.springframework.jdbc.object.SqlUpdate; |
| 29 | |
|
| 30 | |
import com.buckosoft.PicMan.domain.Pic; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | 0 | public class PicsDaoJdbc implements PicsDao { |
| 38 | |
|
| 39 | |
private final static boolean DEBUG = false; |
| 40 | 0 | private final Log logger = LogFactory.getLog(getClass()); |
| 41 | |
|
| 42 | |
private DataSource ds; |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public void setDataSource(DataSource ds) { |
| 49 | 0 | this.ds = ds; |
| 50 | 0 | } |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
@SuppressWarnings("unchecked") |
| 56 | |
public List<Pic> getPics() { |
| 57 | |
if (DEBUG) |
| 58 | |
logger.info("GetPicsList"); |
| 59 | |
|
| 60 | |
|
| 61 | 0 | if (sql_getPicsListQUERY == null) |
| 62 | 0 | sql_getPicsListQUERY = new PicsQuery(ds); |
| 63 | 0 | return(sql_getPicsListQUERY.execute()); |
| 64 | |
} |
| 65 | 0 | private PicsQuery sql_getPicsListQUERY = null; |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
public Pic getPic(String name) { |
| 71 | |
|
| 72 | |
|
| 73 | 0 | if (sql_getPicQUERY == null) |
| 74 | 0 | sql_getPicQUERY = new PicsQuery(ds, name); |
| 75 | 0 | return (Pic)sql_getPicQUERY.findObject(name); |
| 76 | |
} |
| 77 | 0 | private PicsQuery sql_getPicQUERY = null; |
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
public Pic getPic(int pid) { |
| 83 | |
|
| 84 | |
|
| 85 | 0 | if (sql_getPicPidQUERY == null) |
| 86 | 0 | sql_getPicPidQUERY = new PicsQuery(ds, pid); |
| 87 | 0 | return (Pic)sql_getPicPidQUERY.findObject(pid); |
| 88 | |
} |
| 89 | 0 | private PicsQuery sql_getPicPidQUERY = null; |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
public Pic getNewestPic() { |
| 95 | |
if (DEBUG) |
| 96 | |
logger.info("getNewestPic:"); |
| 97 | 0 | if (sql_getPicNewQUERY == null) |
| 98 | 0 | sql_getPicNewQUERY = new PicsQuery(ds, ds); |
| 99 | 0 | return (Pic)sql_getPicNewQUERY.execute().get(0); |
| 100 | |
} |
| 101 | 0 | private PicsQuery sql_getPicNewQUERY = null; |
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
public Pic getRandomPic() { |
| 107 | 0 | int max = this.getPicCount(); |
| 108 | 0 | long r = Math.round(Math.random()*max); |
| 109 | 0 | return(getPic((int)r)); |
| 110 | |
} |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
public Pic getRandomPic(int rid) { |
| 116 | 0 | int max = this.getPicCount(rid); |
| 117 | 0 | long r = Math.round(Math.random()*max); |
| 118 | 0 | if (sql_getPicRandQUERY == null) |
| 119 | 0 | sql_getPicRandQUERY = new PicsQuery(ds, rid, r); |
| 120 | 0 | Pic p = (Pic)sql_getPicRandQUERY.findObject(rid, (int)r); |
| 121 | |
if (DEBUG) |
| 122 | |
logger.info("getRandomPic: " + rid + " " + r + " = " + p.getName()); |
| 123 | 0 | return(p); |
| 124 | |
} |
| 125 | 0 | private PicsQuery sql_getPicRandQUERY = null; |
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
@SuppressWarnings("unchecked") |
| 133 | |
public List<Pic> getPics(String name) { |
| 134 | |
if (DEBUG) |
| 135 | |
logger.info("getPics: " + name); |
| 136 | 0 | if (sql_getPicsQUERY == null) |
| 137 | 0 | sql_getPicsQUERY = new PicsQuery(ds, name, true); |
| 138 | 0 | return (sql_getPicsQUERY.execute(name)); |
| 139 | |
} |
| 140 | 0 | private PicsQuery sql_getPicsQUERY = null; |
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | |
@Override |
| 147 | |
@SuppressWarnings("unchecked") |
| 148 | |
public List<Pic> getPicsByMD5Sum(long md5sum) { |
| 149 | 0 | if (sql_getPicsMD5QUERY == null) |
| 150 | 0 | sql_getPicsMD5QUERY = new PicMD5SumQuery(ds, 0); |
| 151 | 0 | return(sql_getPicsMD5QUERY.execute(md5sum)); |
| 152 | |
} |
| 153 | 0 | private PicMD5SumQuery sql_getPicsMD5QUERY = null; |
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
public List<Pic> getPics(List<String> list) { |
| 159 | 0 | LinkedList<Pic> picList = new LinkedList<Pic>(); |
| 160 | 0 | Iterator<String> iter = list.iterator(); |
| 161 | 0 | while (iter.hasNext()) { |
| 162 | 0 | String s = iter.next(); |
| 163 | 0 | picList.add(getPic(s)); |
| 164 | 0 | } |
| 165 | 0 | return(picList); |
| 166 | |
} |
| 167 | |
|
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
@SuppressWarnings("unchecked") |
| 172 | |
public List<Pic> getPicsInDir(int rid, String dirName) { |
| 173 | |
if (DEBUG) |
| 174 | |
logger.info("getPics: " + dirName); |
| 175 | 0 | if (sql_getPicsDirQUERY == null) |
| 176 | 0 | sql_getPicsDirQUERY = new PicsQuery(ds, dirName, rid); |
| 177 | 0 | return (sql_getPicsDirQUERY.execute(new Object[] {dirName, new Integer(rid)})); |
| 178 | |
} |
| 179 | 0 | private PicsQuery sql_getPicsDirQUERY = null; |
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
@SuppressWarnings("unchecked") |
| 186 | |
public List<Pic> getPicsNewerThan(Calendar calendar) { |
| 187 | |
if (DEBUG) |
| 188 | |
logger.info("getPicsNewerThan: " + calendar.getTime().toString()); |
| 189 | 0 | if (sql_getPicsNewerQUERY == null) |
| 190 | 0 | sql_getPicsNewerQUERY = new PicsQuery(ds, calendar); |
| 191 | 0 | return (sql_getPicsNewerQUERY.execute(new Object[] {calendar.getTime()})); |
| 192 | |
} |
| 193 | 0 | private PicsQuery sql_getPicsNewerQUERY = null; |
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
public HashMap<String, Date> getPicsMap() { |
| 199 | |
if (DEBUG) |
| 200 | |
logger.info("GetPicsMap"); |
| 201 | 0 | List<Pic> l = getPics(); |
| 202 | 0 | HashMap<String, Date> hm = new HashMap<String, Date>(); |
| 203 | 0 | Iterator<Pic> i = l.iterator(); |
| 204 | |
Pic p; |
| 205 | 0 | while (i.hasNext()) { |
| 206 | 0 | p = (Pic)i.next(); |
| 207 | 0 | hm.put(p.getName(), p.getDate()); |
| 208 | |
} |
| 209 | 0 | return(hm); |
| 210 | |
} |
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
@SuppressWarnings("unchecked") |
| 216 | |
public List<String> getPicNames() { |
| 217 | 0 | PicNameQuery pnq = new PicNameQuery(ds); |
| 218 | 0 | return(pnq.execute()); |
| 219 | |
} |
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
@SuppressWarnings("unchecked") |
| 225 | |
public List<String> getPicNamesByDateFunc(String operator, String operand) { |
| 226 | 0 | PicNameQuery pnq = new PicNameQuery(ds, "DATE(`timestamp`)", operator, operand); |
| 227 | 0 | return(pnq.execute()); |
| 228 | |
} |
| 229 | |
|
| 230 | |
|
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
@SuppressWarnings("unchecked") |
| 235 | |
public List<String> getPicNamesByRootFunc(String operator, int rid) { |
| 236 | 0 | PicNameQuery pnq = new PicNameQuery(ds, "rid", operator, rid); |
| 237 | 0 | return(pnq.execute()); |
| 238 | |
} |
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
public void addPic(Pic pic) { |
| 253 | |
if (DEBUG) |
| 254 | |
logger.info("addPic: " + pic.getName()); |
| 255 | 0 | PicInsert pi = new PicInsert(ds); |
| 256 | 0 | pi.insert(pic); |
| 257 | 0 | Pic pic1 = getPic(pic.getName()); |
| 258 | 0 | pic.setPid(pic1.getPid()); |
| 259 | 0 | PicMD5SumUpdate psu = new PicMD5SumUpdate(ds); |
| 260 | 0 | psu.update(pic); |
| 261 | 0 | } |
| 262 | |
|
| 263 | |
|
| 264 | |
|
| 265 | |
|
| 266 | |
|
| 267 | |
public void updatePic(Pic pic) throws DataAccessException { |
| 268 | 0 | PicUpdate pu = new PicUpdate(ds); |
| 269 | 0 | pu.update(pic); |
| 270 | 0 | PicMD5SumUpdate psu = new PicMD5SumUpdate(ds); |
| 271 | 0 | psu.update(pic); |
| 272 | 0 | } |
| 273 | |
|
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
@SuppressWarnings("unchecked") |
| 278 | |
public int getMaxThumbCacheDirUsed() { |
| 279 | 0 | PicsQuery pq = new PicsQuery(ds, false); |
| 280 | 0 | List<Pic> list = pq.execute(); |
| 281 | 0 | if (list.size() == 0) |
| 282 | 0 | return(0); |
| 283 | 0 | Pic pic = list.get(0); |
| 284 | 0 | if (pic == null) |
| 285 | 0 | return(0); |
| 286 | 0 | return(pic.getCacheDir()); |
| 287 | |
} |
| 288 | |
|
| 289 | |
public int getPicCount() { |
| 290 | 0 | PicCount pc = new PicCount(ds); |
| 291 | 0 | return(pc.run()); |
| 292 | |
|
| 293 | |
} |
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
public int getPicCount(int rid) { |
| 298 | 0 | PicCount pc = new PicCount(ds, rid, false); |
| 299 | 0 | return(pc.run(rid)); |
| 300 | |
} |
| 301 | |
|
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
public int getThumbCacheFillCount(int cacheDir) { |
| 307 | 0 | PicCount pc = new PicCount(ds, cacheDir); |
| 308 | 0 | return(pc.run(cacheDir)); |
| 309 | |
} |
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
private class PicsQuery extends MappingSqlQuery { |
| 316 | |
|
| 317 | 0 | PicsQuery(DataSource ds) { |
| 318 | 0 | super(ds, "SELECT * from pics"); |
| 319 | 0 | compile(); |
| 320 | 0 | } |
| 321 | |
|
| 322 | 0 | PicsQuery(DataSource ds, String name) { |
| 323 | 0 | super(ds, "SELECT * from pics where name = ?"); |
| 324 | 0 | declareParameter(new SqlParameter(Types.VARCHAR)); |
| 325 | 0 | compile(); |
| 326 | 0 | } |
| 327 | 0 | PicsQuery(DataSource ds, int pid) { |
| 328 | 0 | super(ds, "SELECT * from pics where pid = ?"); |
| 329 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 330 | 0 | compile(); |
| 331 | 0 | } |
| 332 | 0 | PicsQuery(DataSource ds, String name, boolean unused) { |
| 333 | 0 | super(ds, "SELECT * from pics where name like ?"); |
| 334 | 0 | declareParameter(new SqlParameter(Types.VARCHAR)); |
| 335 | 0 | compile(); |
| 336 | 0 | } |
| 337 | |
|
| 338 | |
|
| 339 | |
|
| 340 | |
|
| 341 | |
|
| 342 | 0 | PicsQuery(DataSource ds, Calendar calendar) { |
| 343 | 0 | super(ds, "SELECT * from pics where timestamp > ?"); |
| 344 | 0 | declareParameter(new SqlParameter(Types.TIMESTAMP)); |
| 345 | 0 | compile(); |
| 346 | 0 | } |
| 347 | 0 | PicsQuery(DataSource ds, String dirName, int rid) { |
| 348 | 0 | super(ds, "SELECT * from pics where location = ? AND rid = ? ORDER BY name"); |
| 349 | 0 | declareParameter(new SqlParameter(Types.VARCHAR)); |
| 350 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 351 | 0 | compile(); |
| 352 | 0 | } |
| 353 | 0 | PicsQuery(DataSource ds, DataSource unused) { |
| 354 | 0 | super(ds, "SELECT * from pics ORDER BY timestamp DESC LIMIT 1"); |
| 355 | 0 | compile(); |
| 356 | 0 | } |
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | 0 | PicsQuery(DataSource ds, int rid, long r) { |
| 364 | 0 | super(ds, "SELECT * from pics where rid = ? LIMIT ?, 1"); |
| 365 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 366 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 367 | 0 | compile(); |
| 368 | 0 | } |
| 369 | |
|
| 370 | 0 | PicsQuery(DataSource ds, boolean unused) { |
| 371 | 0 | super(ds, "SELECT * from pics ORDER BY cacheDir DESC LIMIT 1"); |
| 372 | 0 | compile(); |
| 373 | 0 | } |
| 374 | |
protected Object mapRow(ResultSet rs, int rowNum) throws SQLException { |
| 375 | 0 | Pic pic = new Pic(); |
| 376 | 0 | pic.setName(rs.getString("name")); |
| 377 | |
if (false) |
| 378 | |
logger.info("picName=" + pic.getName()); |
| 379 | |
try { |
| 380 | 0 | pic.getDate().setTime(rs.getTimestamp("timestamp").getTime()); |
| 381 | 0 | } catch (Exception e) {} |
| 382 | 0 | pic.setPid(rs.getInt("pid")); |
| 383 | 0 | pic.setWidth(rs.getInt("width")); |
| 384 | 0 | pic.setHeight(rs.getInt("height")); |
| 385 | 0 | pic.setRid(rs.getInt("rid")); |
| 386 | 0 | pic.setCacheDir(rs.getInt("cacheDir")); |
| 387 | 0 | pic.setLocation(rs.getString("location")); |
| 388 | 0 | return pic; |
| 389 | |
} |
| 390 | |
} |
| 391 | |
|
| 392 | |
private class PicMD5SumQuery extends MappingSqlQuery { |
| 393 | 0 | PicMD5SumQuery(DataSource ds, long sum) { |
| 394 | 0 | super(ds, "SELECT * FROM pics p left join picmd5sums s on p.pid = s.pid WHERE s.md5sum = ?"); |
| 395 | 0 | declareParameter(new SqlParameter(Types.BIGINT)); |
| 396 | 0 | compile(); |
| 397 | 0 | } |
| 398 | |
protected Object mapRow(ResultSet rs, int rowNum) throws SQLException { |
| 399 | 0 | Pic pic = new Pic(); |
| 400 | 0 | pic.setName(rs.getString("name")); |
| 401 | |
if (false) |
| 402 | |
logger.info("picName=" + pic.getName()); |
| 403 | |
try { |
| 404 | 0 | pic.getDate().setTime(rs.getTimestamp("timestamp").getTime()); |
| 405 | 0 | } catch (Exception e) {} |
| 406 | 0 | pic.setPid(rs.getInt("pid")); |
| 407 | 0 | pic.setWidth(rs.getInt("width")); |
| 408 | 0 | pic.setHeight(rs.getInt("height")); |
| 409 | 0 | pic.setRid(rs.getInt("rid")); |
| 410 | 0 | pic.setCacheDir(rs.getInt("cacheDir")); |
| 411 | 0 | pic.setLocation(rs.getString("location")); |
| 412 | 0 | pic.setMd5(rs.getLong("md5sum")); |
| 413 | 0 | return pic; |
| 414 | |
} |
| 415 | |
|
| 416 | |
} |
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
|
| 421 | |
|
| 422 | |
|
| 423 | |
private class PicNameQuery extends MappingSqlQuery { |
| 424 | |
|
| 425 | 0 | PicNameQuery(DataSource ds) { |
| 426 | 0 | super(ds, "SELECT name FROM pics"); |
| 427 | 0 | compile(); |
| 428 | |
|
| 429 | 0 | } |
| 430 | 0 | PicNameQuery(DataSource ds, String column, String operator, String operand) { |
| 431 | 0 | super(ds, "SELECT name FROM pics WHERE " + column + " " + operator + " \"" + operand + "\""); |
| 432 | 0 | compile(); |
| 433 | |
if (DEBUG) |
| 434 | |
logger.info("PicNameQuery() WHERE " + column + " " + operator + " \"" + operand + "\""); |
| 435 | |
|
| 436 | 0 | } |
| 437 | 0 | PicNameQuery(DataSource ds, String column, String operator, int operand) { |
| 438 | 0 | super(ds, "SELECT name FROM pics WHERE " + column + " " + operator + " \"" + operand + "\""); |
| 439 | 0 | compile(); |
| 440 | |
if (DEBUG) |
| 441 | |
logger.info("PicNameQuery() WHERE " + column + " " + operator + " \"" + operand + "\""); |
| 442 | |
|
| 443 | 0 | } |
| 444 | |
|
| 445 | |
protected Object mapRow(ResultSet rs, int rowNum) throws SQLException { |
| 446 | |
|
| 447 | |
|
| 448 | 0 | return(rs.getString("name")); |
| 449 | |
} |
| 450 | |
} |
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
private class PicCount extends SqlFunction { |
| 456 | |
|
| 457 | 0 | PicCount(DataSource ds) { |
| 458 | 0 | super(ds, "SELECT COUNT(*) from pics"); |
| 459 | 0 | compile(); |
| 460 | 0 | } |
| 461 | |
|
| 462 | |
|
| 463 | |
|
| 464 | |
|
| 465 | 0 | PicCount(DataSource ds, int cacheDir) { |
| 466 | 0 | super(ds, "SELECT COUNT(*) from pics WHERE cacheDir = ?"); |
| 467 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 468 | 0 | compile(); |
| 469 | 0 | } |
| 470 | |
|
| 471 | |
|
| 472 | |
|
| 473 | |
|
| 474 | |
|
| 475 | 0 | PicCount(DataSource ds, int rid, boolean unused) { |
| 476 | 0 | super(ds, "SELECT COUNT(*) from pics WHERE rid = ?"); |
| 477 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 478 | 0 | compile(); |
| 479 | 0 | } |
| 480 | |
} |
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
private class PicInsert extends SqlUpdate { |
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | 0 | protected PicInsert(DataSource ds) { |
| 492 | 0 | super(ds, "INSERT INTO pics VALUES(?,?,?,?,?,?,?,?)"); |
| 493 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 494 | 0 | declareParameter(new SqlParameter(Types.VARCHAR)); |
| 495 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 496 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 497 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 498 | 0 | declareParameter(new SqlParameter(Types.VARCHAR)); |
| 499 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 500 | 0 | declareParameter(new SqlParameter(Types.TIMESTAMP)); |
| 501 | 0 | compile(); |
| 502 | 0 | } |
| 503 | |
|
| 504 | |
protected void insert(Pic p) { |
| 505 | 0 | Object[] objs = new Object[] { |
| 506 | |
new Integer(0), |
| 507 | 0 | p.getName(), new Integer(p.getWidth()), new Integer(p.getHeight()), |
| 508 | 0 | new Integer(p.getRid()), p.getLocation(), |
| 509 | 0 | new Integer(p.getCacheDir()), |
| 510 | 0 | p.getDate() |
| 511 | |
}; |
| 512 | 0 | super.update(objs); |
| 513 | 0 | } |
| 514 | |
} |
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
private class PicUpdate extends SqlUpdate { |
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | 0 | protected PicUpdate(DataSource ds) { |
| 527 | 0 | super(ds, "UPDATE pics SET width=?, height=?, rid=?, location=?, cacheDir=?, timestamp=? WHERE name = ? LIMIT 1"); |
| 528 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 529 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 530 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 531 | 0 | declareParameter(new SqlParameter(Types.VARCHAR)); |
| 532 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 533 | 0 | declareParameter(new SqlParameter(Types.TIMESTAMP)); |
| 534 | 0 | declareParameter(new SqlParameter(Types.VARCHAR)); |
| 535 | 0 | compile(); |
| 536 | 0 | } |
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
protected int update(Pic pic) { |
| 544 | 0 | return this.update(new Object[] { |
| 545 | 0 | new Integer(pic.getWidth()), |
| 546 | 0 | new Integer(pic.getHeight()), |
| 547 | 0 | new Integer(pic.getRid()), |
| 548 | 0 | pic.getLocation(), |
| 549 | 0 | new Integer(pic.getCacheDir()), |
| 550 | 0 | pic.getDate(), |
| 551 | 0 | pic.getName(), |
| 552 | |
}); |
| 553 | |
} |
| 554 | |
} |
| 555 | |
|
| 556 | |
private class PicMD5SumUpdate extends SqlUpdate { |
| 557 | 0 | protected PicMD5SumUpdate(DataSource ds) { |
| 558 | 0 | super(ds, "REPLACE INTO picmd5sums VALUES(?,?) "); |
| 559 | 0 | declareParameter(new SqlParameter(Types.INTEGER)); |
| 560 | 0 | declareParameter(new SqlParameter(Types.BIGINT)); |
| 561 | 0 | } |
| 562 | |
protected void update(Pic p) { |
| 563 | 0 | Object[] objs = new Object[] { |
| 564 | 0 | new Integer(p.getPid()), |
| 565 | 0 | new Long(p.getMd5()) |
| 566 | |
}; |
| 567 | 0 | this.update(objs); |
| 568 | 0 | } |
| 569 | |
} |
| 570 | |
|
| 571 | |
} |