| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| DatabaseImpl |
|
| 1.5422535211267605;1.542 | ||||
| DatabaseImpl$1 |
|
| 1.5422535211267605;1.542 | ||||
| DatabaseImpl$HomeThumbAttr |
|
| 1.5422535211267605;1.542 |
| 1 | /****************************************************************************** | |
| 2 | * DatabaseImpl.java - Implement the API into the PicMan database | |
| 3 | * | |
| 4 | * PicMan - The BuckoSoft Picture Manager in Java | |
| 5 | * Copyright(c) 2005 - Dick Balaska | |
| 6 | * | |
| 7 | */ | |
| 8 | package com.buckosoft.PicMan.db; | |
| 9 | ||
| 10 | import java.text.DecimalFormat; | |
| 11 | import java.util.Calendar; | |
| 12 | import java.util.Date; | |
| 13 | import java.util.HashMap; | |
| 14 | import java.util.Iterator; | |
| 15 | import java.util.LinkedHashMap; | |
| 16 | import java.util.LinkedList; | |
| 17 | import java.util.List; | |
| 18 | ||
| 19 | import org.apache.commons.logging.Log; | |
| 20 | import org.apache.commons.logging.LogFactory; | |
| 21 | import org.hibernate.HibernateException; | |
| 22 | import org.hibernate.Session; | |
| 23 | import org.springframework.dao.DataAccessException; | |
| 24 | ||
| 25 | import com.buckosoft.PicMan.business.SetChangedListener; | |
| 26 | import com.buckosoft.PicMan.business.common.PicManCommonFacade; | |
| 27 | import com.buckosoft.PicMan.db.logic.MetaSetFilter; | |
| 28 | import com.buckosoft.PicMan.domain.Chain; | |
| 29 | import com.buckosoft.PicMan.domain.Contact; | |
| 30 | import com.buckosoft.PicMan.domain.Filter; | |
| 31 | import com.buckosoft.PicMan.domain.FilterMicroSet; | |
| 32 | import com.buckosoft.PicMan.domain.MetaSet; | |
| 33 | import com.buckosoft.PicMan.domain.MetaSetRule; | |
| 34 | import com.buckosoft.PicMan.domain.Mosaic; | |
| 35 | import com.buckosoft.PicMan.domain.MosaicBatch; | |
| 36 | import com.buckosoft.PicMan.domain.MosaicTile; | |
| 37 | import com.buckosoft.PicMan.domain.Pic; | |
| 38 | import com.buckosoft.PicMan.domain.Poster; | |
| 39 | import com.buckosoft.PicMan.domain.Root; | |
| 40 | import com.buckosoft.PicMan.domain.Set; | |
| 41 | import com.buckosoft.PicMan.domain.SetSize; | |
| 42 | import com.buckosoft.PicMan.domain.SyncClient; | |
| 43 | import com.buckosoft.PicMan.domain.SyncServer; | |
| 44 | import com.buckosoft.PicMan.domain.System; | |
| 45 | import com.buckosoft.PicMan.domain.User; | |
| 46 | import com.buckosoft.PicMan.domain.Virgin; | |
| 47 | import com.buckosoft.PicMan.domain.mosaic.MosaicVector; | |
| 48 | ||
| 49 | /** Implement the API into the PicMan database | |
| 50 | * @author Dick Balaska | |
| 51 | * @since 2006/07/17 | |
| 52 | * @see <a href="http://cvs.buckosoft.com/Projects/PicMan/PicMan/src/com/buckosoft/PicMan/db/DatabaseImpl.java">DatabaseImpl.java</a> | |
| 53 | */ | |
| 54 | public class DatabaseImpl implements DatabaseFacade, SetChangedListener { | |
| 55 | 0 | private static boolean DEBUG = false; |
| 56 | // private static boolean DEBUGMETASETS = false; | |
| 57 | 0 | protected final Log logger = LogFactory.getLog(getClass()); |
| 58 | ||
| 59 | private String dbUser; | |
| 60 | private String dbUrl; | |
| 61 | ||
| 62 | private List<Integer> sizes; // totally unflexible size list (should be a database) | |
| 63 | private int[] sizeArray; // easier to deal with totally unflexible size array | |
| 64 | private ChainsDao chainsDao; | |
| 65 | private ContactsDao contactsDao; | |
| 66 | private FiltersDao filtersDao; | |
| 67 | private FiltersMicroSetsDao filtersMicroSetsDao; | |
| 68 | private MetaSetsDao metaSetsDao; | |
| 69 | private MosaicsDao mosaicsDao; | |
| 70 | private MosaicBatchesDao mosaicBatchesDao; | |
| 71 | private MosaicTilesDao mosaicTilesDao; | |
| 72 | private MosaicVectorsDao mosaicVectorsDao; | |
| 73 | private PicsDao picsDao; | |
| 74 | private PostersDao postersDao; | |
| 75 | private RootsDao rootsDao; | |
| 76 | private Server_SyncDao server_SyncDao; | |
| 77 | private SystemDao systemDao; | |
| 78 | private SetsDao setsDao; | |
| 79 | private SetTimestampsDao setTimestampsDao; | |
| 80 | private UsersDao usersDao; | |
| 81 | private VirginsDao virginsDao; | |
| 82 | ||
| 83 | 0 | private MetaSetFilter metaSetFilter = new MetaSetFilter(); |
| 84 | ||
| 85 | // XXX: This should be extended to support multiple users | |
| 86 | 0 | private class HomeThumbAttr { |
| 87 | 0 | String homeThumbsForUserSetCached = ""; |
| 88 | 0 | List<String> homeThumbsForUser = null; |
| 89 | 0 | User homeThumbsUser = null; |
| 90 | 0 | int homeThumbsUserIndex = 0; |
| 91 | } | |
| 92 | 0 | HomeThumbAttr homeThumbAttr = new HomeThumbAttr(); |
| 93 | ||
| 94 | PicManCommonFacade pmcf; | |
| 95 | ||
| 96 | 0 | DatabaseImpl() { |
| 97 | 0 | this.metaSetFilter.setDatabase(this); |
| 98 | ||
| 99 | 0 | sizes = new LinkedList<Integer>(); |
| 100 | 0 | sizes.add(new Integer(75)); |
| 101 | 0 | sizes.add(new Integer(100)); |
| 102 | 0 | sizes.add(new Integer(150)); |
| 103 | 0 | sizes.add(new Integer(200)); |
| 104 | 0 | sizes.add(new Integer(300)); |
| 105 | ||
| 106 | 0 | sizeArray = new int[5]; |
| 107 | 0 | sizeArray[0] = 75; |
| 108 | 0 | sizeArray[1] = 100; |
| 109 | 0 | sizeArray[2] = 150; |
| 110 | 0 | sizeArray[3] = 200; |
| 111 | 0 | sizeArray[4] = 300; |
| 112 | 0 | } |
| 113 | ||
| 114 | ||
| 115 | public void setPicManCommonFacade(PicManCommonFacade picManCommonFacade) { | |
| 116 | 0 | this.pmcf = picManCommonFacade; |
| 117 | 0 | this.pmcf.addSetChangedListener(this); |
| 118 | 0 | } |
| 119 | ||
| 120 | /* (non-Javadoc) | |
| 121 | * @see com.buckosoft.PicMan.db.DatabaseFacade#setDEBUG(boolean) | |
| 122 | */ | |
| 123 | public void setDEBUG(boolean debugFlag) { | |
| 124 | 0 | DEBUG = debugFlag; |
| 125 | 0 | } |
| 126 | ||
| 127 | ||
| 128 | //------------------------------------------------------------------------- | |
| 129 | // Setter methods for dependency injection | |
| 130 | //------------------------------------------------------------------------- | |
| 131 | ||
| 132 | /** AOP setter for the ChainsDao | |
| 133 | * @param chainsDao The ChainsDao from the Spring Database Setup | |
| 134 | */ | |
| 135 | public void setChainsDao(ChainsDao chainsDao) { | |
| 136 | 0 | this.chainsDao = chainsDao; |
| 137 | 0 | } |
| 138 | /** AOP setter for the ContactsDao | |
| 139 | * @param contactsDao The ContactsDao from the Spring Database Setup | |
| 140 | */ | |
| 141 | public void setContactsDao(ContactsDao contactsDao) { | |
| 142 | 0 | this.contactsDao = contactsDao; |
| 143 | 0 | } |
| 144 | /** AOP setter for the FiltersDao | |
| 145 | * @param filtersDao The FiltersDao from the Spring Database Setup | |
| 146 | */ | |
| 147 | public void setFiltersDao(FiltersDao filtersDao) { | |
| 148 | 0 | this.filtersDao = filtersDao; |
| 149 | 0 | } |
| 150 | /** AOP setter for the FiltersMicroSetsDao | |
| 151 | * @param filtersMicroSetsDao The FiltersMicroSetsDao from the Spring Database Setup | |
| 152 | */ | |
| 153 | public void setFiltersMicroSetsDao(FiltersMicroSetsDao filtersMicroSetsDao) { | |
| 154 | 0 | this.filtersMicroSetsDao = filtersMicroSetsDao; |
| 155 | 0 | } |
| 156 | /** AOP setter for the MetaSetsDao | |
| 157 | * @param metaSetsDao The MetaSetsDao from the Spring Database Setup | |
| 158 | */ | |
| 159 | public void setMetaSetsDao(MetaSetsDao metaSetsDao) { | |
| 160 | 0 | this.metaSetsDao = metaSetsDao; |
| 161 | 0 | } |
| 162 | /** AOP setter for the MosaicTilesDao | |
| 163 | * @param mosaicTilesDao The MosaicTilesDao from the Spring Database Setup | |
| 164 | */ | |
| 165 | public void setMosaicTilesDao(MosaicTilesDao mosaicTilesDao) { | |
| 166 | 0 | this.mosaicTilesDao = mosaicTilesDao; |
| 167 | 0 | } |
| 168 | /** AOP setter for the MosaicsDao | |
| 169 | * @param mosaicsDao The MosaicsDao from the Spring Database Setup | |
| 170 | */ | |
| 171 | public void setMosaicsDao(MosaicsDao mosaicsDao) { | |
| 172 | 0 | this.mosaicsDao = mosaicsDao; |
| 173 | 0 | } |
| 174 | /** AOP setter for the MosaicsDao | |
| 175 | * @param mosaicBatchesDao The MosaicsBatchDao from the Spring Database Setup | |
| 176 | */ | |
| 177 | public void setMosaicBatchesDao(MosaicBatchesDao mosaicBatchesDao) { | |
| 178 | 0 | this.mosaicBatchesDao = mosaicBatchesDao; |
| 179 | 0 | } |
| 180 | /** AOP setter for the MosaicVectorsDao | |
| 181 | * @param mosaicVectorsDao The MosaicVectorsDao from the Spring Database Setup | |
| 182 | */ | |
| 183 | public void setMosaicVectorsDao(MosaicVectorsDao mosaicVectorsDao) { | |
| 184 | 0 | this.mosaicVectorsDao = mosaicVectorsDao; |
| 185 | 0 | } |
| 186 | /** AOP setter for the PicsDao | |
| 187 | * @param picsDao The PicsDao from the Spring Database Setup | |
| 188 | */ | |
| 189 | public void setPicsDao(PicsDao picsDao) { | |
| 190 | 0 | this.picsDao = picsDao; |
| 191 | 0 | } |
| 192 | /** AOP setter for the PostersDao | |
| 193 | * @param postersDao The PostersDao from the Spring Database Setup | |
| 194 | */ | |
| 195 | public void setPostersDao(PostersDao postersDao) { | |
| 196 | 0 | this.postersDao = postersDao; |
| 197 | 0 | } |
| 198 | /** AOP setter for the RootsDao | |
| 199 | * @param rootsDao The RootsDao from the Spring Database Setup | |
| 200 | */ | |
| 201 | public void setRootsDao(RootsDao rootsDao) { | |
| 202 | 0 | this.rootsDao = rootsDao; |
| 203 | 0 | } |
| 204 | /** AOP setter for the Server's SyncDao | |
| 205 | * @param server_SyncDao The Server_SyncDao from the Spring Database Setup | |
| 206 | */ | |
| 207 | public void setServer_SyncDao(Server_SyncDao server_SyncDao) { | |
| 208 | 0 | this.server_SyncDao = server_SyncDao; |
| 209 | 0 | } |
| 210 | /** AOP setter for the SystemDao | |
| 211 | * @param systemDao The SystemDao from the Spring Database Setup | |
| 212 | */ | |
| 213 | public void setSystemDao(SystemDao systemDao) { | |
| 214 | 0 | this.systemDao = systemDao; |
| 215 | 0 | } |
| 216 | /** AOP setter for the SetsDao | |
| 217 | * @param setsDao The SetsDao from the Spring Database Setup | |
| 218 | */ | |
| 219 | public void setSetsDao(SetsDao setsDao) { | |
| 220 | 0 | this.setsDao = setsDao; |
| 221 | 0 | } |
| 222 | /** AOP setter for the SetTimestampsDao | |
| 223 | * @param setTimestampsDao The SetTimestampsDao from the Spring Database Setup | |
| 224 | */ | |
| 225 | public void setSetTimestampsDao(SetTimestampsDao setTimestampsDao) { | |
| 226 | 0 | this.setTimestampsDao = setTimestampsDao; |
| 227 | 0 | } |
| 228 | /** AOP setter for the UsersDao | |
| 229 | * @param usersDao The UsersDao from the Spring Database Setup | |
| 230 | */ | |
| 231 | public void setUsersDao(UsersDao usersDao) { | |
| 232 | 0 | this.usersDao = usersDao; |
| 233 | 0 | } |
| 234 | /** AOP setter for the VirginsDao | |
| 235 | * @param virginsDao The VirginsDao from the Spring Database Setup | |
| 236 | */ | |
| 237 | public void setVirginsDao(VirginsDao virginsDao) { | |
| 238 | 0 | this.virginsDao = virginsDao; |
| 239 | 0 | } |
| 240 | ||
| 241 | /** Why is this public? Because Spring was freaking out trying to reflect the type. | |
| 242 | * @return Our kinda private ChainsDao | |
| 243 | */ | |
| 244 | 0 | public ChainsDao getChainsDao() { return(chainsDao); } |
| 245 | ||
| 246 | ||
| 247 | //------------------------------------------------------------------------- | |
| 248 | // Operation methods, implementing the PicManFacade interface | |
| 249 | //------------------------------------------------------------------------- | |
| 250 | ||
| 251 | /* (non-Javadoc) | |
| 252 | * @see com.buckosoft.PicMan.db.DatabaseFacade#setDbUser(java.lang.String) | |
| 253 | */ | |
| 254 | @Override | |
| 255 | public void setDbUser(String dbUser) { | |
| 256 | 0 | this.dbUser = dbUser; |
| 257 | 0 | } |
| 258 | ||
| 259 | ||
| 260 | /* (non-Javadoc) | |
| 261 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getDbUser() | |
| 262 | */ | |
| 263 | @Override | |
| 264 | public String getDbUser() { | |
| 265 | 0 | return(this.dbUser); |
| 266 | } | |
| 267 | ||
| 268 | ||
| 269 | /* (non-Javadoc) | |
| 270 | * @see com.buckosoft.PicMan.db.DatabaseFacade#setDbUrl(java.lang.String) | |
| 271 | */ | |
| 272 | @Override | |
| 273 | public void setDbUrl(String dbUrl) { | |
| 274 | 0 | this.dbUrl = dbUrl; |
| 275 | 0 | } |
| 276 | ||
| 277 | ||
| 278 | /* (non-Javadoc) | |
| 279 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getDbUrl() | |
| 280 | */ | |
| 281 | @Override | |
| 282 | public String getDbUrl() { | |
| 283 | 0 | return(this.dbUrl); |
| 284 | } | |
| 285 | ||
| 286 | ||
| 287 | ||
| 288 | /******************************************************* | |
| 289 | * System Management | |
| 290 | */ | |
| 291 | ||
| 292 | /* (non-Javadoc) | |
| 293 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSystem() | |
| 294 | */ | |
| 295 | public System getSystem() { | |
| 296 | 0 | return(this.systemDao.getSystem()); |
| 297 | } | |
| 298 | ||
| 299 | /* (non-Javadoc) | |
| 300 | * @see com.buckosoft.PicMan.db.DatabaseFacade#saveSystem(com.buckosoft.PicMan.domain.System) | |
| 301 | */ | |
| 302 | public void saveSystem(System sys) { | |
| 303 | 0 | this.systemDao.setSystem(sys); |
| 304 | 0 | } |
| 305 | ||
| 306 | /* (non-Javadoc) | |
| 307 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicExtensions() | |
| 308 | */ | |
| 309 | public List<String> getPicExtensions() { | |
| 310 | 0 | return(systemDao.getSystem().getPicExtensions()); |
| 311 | } | |
| 312 | ||
| 313 | /* (non-Javadoc) | |
| 314 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getThumbHeight() | |
| 315 | */ | |
| 316 | public int getThumbHeight() { | |
| 317 | 0 | return(systemDao.getSystem().getThumbHeight()); |
| 318 | } | |
| 319 | ||
| 320 | /////////////////////////////////////////////////////////////////////////// | |
| 321 | /* Roots Management */ | |
| 322 | ||
| 323 | /* (non-Javadoc) | |
| 324 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getRoots() | |
| 325 | */ | |
| 326 | public List<Root> getRoots() { | |
| 327 | 0 | return(rootsDao.getRoots()); |
| 328 | } | |
| 329 | ||
| 330 | /* (non-Javadoc) | |
| 331 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getRootCount() | |
| 332 | */ | |
| 333 | public int getRootCount() { | |
| 334 | 0 | return(rootsDao.getRootCount()); |
| 335 | } | |
| 336 | /* (non-Javadoc) | |
| 337 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getRoot(int) | |
| 338 | */ | |
| 339 | public Root getRoot(int rid) { | |
| 340 | 0 | return(rootsDao.getRoot(rid)); |
| 341 | } | |
| 342 | ||
| 343 | /* (non-Javadoc) | |
| 344 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getRoot(java.lang.String) | |
| 345 | */ | |
| 346 | public Root getRoot(String name) { | |
| 347 | 0 | return(rootsDao.getRoot(name)); |
| 348 | } | |
| 349 | ||
| 350 | /* (non-Javadoc) | |
| 351 | * @see com.buckosoft.PicMan.db.DatabaseFacade#setRoots(java.util.List) | |
| 352 | */ | |
| 353 | public void setRoots(List<Root> roots) { | |
| 354 | 0 | this.rootsDao.setRoots(roots); |
| 355 | 0 | } |
| 356 | ||
| 357 | /* (non-Javadoc) | |
| 358 | * @see com.buckosoft.PicMan.db.DatabaseFacade#addRoot(com.buckosoft.PicMan.domain.Root) | |
| 359 | */ | |
| 360 | public void addRoot(Root r) { | |
| 361 | 0 | int count = rootsDao.getRootCount(); |
| 362 | 0 | r.setRid(count+1); |
| 363 | 0 | rootsDao.addRoot(r); |
| 364 | 0 | } |
| 365 | ||
| 366 | /* (non-Javadoc) | |
| 367 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storeRoot(com.buckosoft.PicMan.domain.Root) | |
| 368 | */ | |
| 369 | public void storeRoot(Root root) { | |
| 370 | 0 | rootsDao.storeRoot(root); |
| 371 | 0 | } |
| 372 | ||
| 373 | /* (non-Javadoc) | |
| 374 | * @see com.buckosoft.PicMan.db.DatabaseFacade#deleteRoot(com.buckosoft.PicMan.domain.Root) | |
| 375 | */ | |
| 376 | public void deleteRoot(Root root) { | |
| 377 | 0 | rootsDao.deleteRoot(root); |
| 378 | 0 | } |
| 379 | ||
| 380 | /* (non-Javadoc) | |
| 381 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getInactiveRoots() | |
| 382 | */ | |
| 383 | public List<Root> getInactiveRoots() { | |
| 384 | 0 | return(rootsDao.getInactiveRoots()); |
| 385 | } | |
| 386 | ||
| 387 | /* (non-Javadoc) | |
| 388 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getActiveRoots() | |
| 389 | */ | |
| 390 | public List<Root> getActiveRoots() { | |
| 391 | 0 | return(rootsDao.getActiveRoots()); |
| 392 | } | |
| 393 | ||
| 394 | /////////////////////////////////////////////////////////////////////////// | |
| 395 | /* Sets Management */ | |
| 396 | ||
| 397 | /* (non-Javadoc) | |
| 398 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSets() | |
| 399 | */ | |
| 400 | public List<Set> getSets() { | |
| 401 | 0 | return(setsDao.getSets()); |
| 402 | } | |
| 403 | ||
| 404 | /* (non-Javadoc) | |
| 405 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSetsClone() | |
| 406 | */ | |
| 407 | public List<Set> getSetsClone() { | |
| 408 | 0 | return(setsDao.getSetsClone()); |
| 409 | } | |
| 410 | ||
| 411 | /* (non-Javadoc) | |
| 412 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSetCount() | |
| 413 | */ | |
| 414 | public int getSetCount() { | |
| 415 | 0 | return(setsDao.getSetCount()); |
| 416 | } | |
| 417 | ||
| 418 | /* (non-Javadoc) | |
| 419 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSet(int) | |
| 420 | */ | |
| 421 | public Set getSet(int sid) { | |
| 422 | 0 | return(setsDao.getSet(sid)); |
| 423 | } | |
| 424 | ||
| 425 | /* (non-Javadoc) | |
| 426 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSet(java.lang.String) | |
| 427 | */ | |
| 428 | public Set getSet(String setName) { | |
| 429 | 0 | return(setsDao.getSet(setName)); |
| 430 | } | |
| 431 | ||
| 432 | /* (non-Javadoc) | |
| 433 | * @see com.buckosoft.PicMan.db.DatabaseFacade#setSets(java.util.List) | |
| 434 | */ | |
| 435 | public void setSets(List<Set> sets) { | |
| 436 | 0 | this.setsDao.setSets(sets); |
| 437 | 0 | } |
| 438 | ||
| 439 | /** Add a new set to the database. | |
| 440 | * @param s The Set to add. The sid should be 0. | |
| 441 | */ | |
| 442 | public void addSet(Set s) { | |
| 443 | // int count = setsDao.getSetCount(); | |
| 444 | // s.setSid(count+1); | |
| 445 | 0 | s.setSid(0); |
| 446 | 0 | setsDao.addSet(s); |
| 447 | 0 | s = setsDao.getSet(s.getName()); |
| 448 | 0 | if (!s.isMetaSet() && !s.isMicroSet() && !s.isNanoSet()) { |
| 449 | 0 | List<Integer> l = getSizes(); |
| 450 | 0 | Iterator<Integer> it = l.iterator(); |
| 451 | 0 | while (it.hasNext()) { |
| 452 | 0 | Integer i = (Integer)it.next(); |
| 453 | 0 | filtersDao.addSet(s.getName(), i.intValue()); |
| 454 | 0 | } |
| 455 | } | |
| 456 | 0 | } |
| 457 | ||
| 458 | /** Store an existing set to the database. | |
| 459 | * @param set The set to store. The sid should NOT be 0. | |
| 460 | */ | |
| 461 | public void storeSet(Set set) { | |
| 462 | 0 | if (!set.isMetaSet() && !set.isMicroSet() && !set.isNanoSet()) { |
| 463 | 0 | Set s1 = getSet(set.getSid()); |
| 464 | 0 | if (!set.getName().equals(s1.getName())) { // renaming a set... |
| 465 | 0 | List<Integer> l = getSizes(); |
| 466 | 0 | Iterator<Integer> it = l.iterator(); |
| 467 | 0 | while (it.hasNext()) { |
| 468 | 0 | Integer i = (Integer)it.next(); |
| 469 | 0 | filtersDao.renameSet(s1.getName(), set.getName(), i.intValue()); |
| 470 | 0 | } |
| 471 | ||
| 472 | } | |
| 473 | } | |
| 474 | 0 | setsDao.storeSet(set); |
| 475 | 0 | } |
| 476 | ||
| 477 | /** Delete this set from the database. | |
| 478 | * @param s The set to delete. | |
| 479 | */ | |
| 480 | public void deleteSet(Set s) { | |
| 481 | 0 | List<Integer> l = getSizes(); |
| 482 | 0 | Iterator<Integer> it = l.iterator(); |
| 483 | 0 | while (it.hasNext()) { |
| 484 | 0 | Integer i = (Integer)it.next(); |
| 485 | 0 | filtersDao.deleteSet(s.getName(), i.intValue()); |
| 486 | 0 | } |
| 487 | 0 | setsDao.deleteSet(s); |
| 488 | 0 | } |
| 489 | ||
| 490 | ||
| 491 | /* (non-Javadoc) | |
| 492 | * @see com.buckosoft.PicMan.db.DatabaseFacade#renameSet(java.lang.String, java.lang.String) | |
| 493 | */ | |
| 494 | public void renameSet(String oldName, String newName) { | |
| 495 | 0 | Set set = this.getSet(oldName); |
| 496 | 0 | List<Chain> clist = this.getChains(); |
| 497 | 0 | for (Chain c : clist) { |
| 498 | 0 | boolean modified = false; |
| 499 | 0 | List<SetSize> slist = c.getSetSizes(); |
| 500 | 0 | Iterator<SetSize> siter = slist.iterator(); |
| 501 | 0 | while (siter.hasNext()) { |
| 502 | 0 | SetSize ss = siter.next(); |
| 503 | 0 | if (ss.getSetName().equals(oldName)) { |
| 504 | 0 | modified = true; |
| 505 | 0 | ss.setSetName(newName); |
| 506 | } | |
| 507 | 0 | } |
| 508 | 0 | if (modified) { |
| 509 | 0 | this.storeChain(c); |
| 510 | } | |
| 511 | 0 | } |
| 512 | 0 | List<Set> slist = this.getSets(); |
| 513 | 0 | for (Set s : slist) { |
| 514 | 0 | boolean modified = false; |
| 515 | 0 | if (!s.isMetaSet()) |
| 516 | 0 | continue; |
| 517 | 0 | MetaSet ms = this.getMetaSet(s.getSid()); |
| 518 | 0 | for (MetaSetRule msr : ms.getRules()) { |
| 519 | 0 | if (msr.getType() == MetaSet.NAME) { |
| 520 | 0 | if (msr.getValue().equals(oldName)) { |
| 521 | 0 | msr.setValue(newName); |
| 522 | 0 | modified = true; |
| 523 | } | |
| 524 | } | |
| 525 | 0 | } |
| 526 | 0 | if (modified) |
| 527 | 0 | this.storeMetaSet(ms); |
| 528 | 0 | } |
| 529 | 0 | set.setName(newName); |
| 530 | 0 | this.storeSet(set); |
| 531 | 0 | } |
| 532 | ||
| 533 | /** Build a list of inactive sets | |
| 534 | * @return A List of Sets | |
| 535 | */ | |
| 536 | public List<Set> getInactiveSets() { | |
| 537 | 0 | return(setsDao.getInactiveSets()); |
| 538 | } | |
| 539 | ||
| 540 | /** Build a list of active sets | |
| 541 | * @return A List of Sets | |
| 542 | */ | |
| 543 | public List<Set> getActiveSets() { | |
| 544 | 0 | return(setsDao.getActiveSets()); |
| 545 | } | |
| 546 | ||
| 547 | /////////////////////////////////////////////////////////////////////////// | |
| 548 | /** | |
| 549 | * MetaSet Management | |
| 550 | */ | |
| 551 | /* (non-Javadoc) | |
| 552 | * @see com.buckosoft.PicMan.domain.logic.PicManFacade#getMetaSet(int) | |
| 553 | */ | |
| 554 | public MetaSet getMetaSet(int sid) { | |
| 555 | 0 | return(this.metaSetsDao.getMetaSet(sid)); |
| 556 | } | |
| 557 | ||
| 558 | /* (non-Javadoc) | |
| 559 | * @see com.buckosoft.PicMan.domain.logic.PicManFacade#storeMetaSet(com.buckosoft.PicMan.domain.MetaSet) | |
| 560 | */ | |
| 561 | public void storeMetaSet(MetaSet mset) { | |
| 562 | 0 | this.metaSetsDao.storeMetaSet(mset); |
| 563 | 0 | } |
| 564 | ||
| 565 | /** Get a List of Column names for the MetaSets. | |
| 566 | * @return a List of "columns" for the known metasets | |
| 567 | */ | |
| 568 | public List<String> getMetaSetColumns() { | |
| 569 | 0 | List<String> columns = new LinkedList<String>(); |
| 570 | 0 | List<Integer> sizes = getSizes(); |
| 571 | 0 | List<Set> sets = getSets(); |
| 572 | 0 | SetSize ss = new SetSize(); |
| 573 | 0 | Iterator<Set> setIter = sets.iterator(); |
| 574 | 0 | while (setIter.hasNext()) { |
| 575 | 0 | Set set = (Set)setIter.next(); |
| 576 | 0 | if (set.isMetaSet()) { |
| 577 | 0 | ss.setSetName(set.getName()); |
| 578 | 0 | Iterator<Integer> sizeIter = sizes.iterator(); |
| 579 | 0 | while (sizeIter.hasNext()) { |
| 580 | 0 | ss.setSize(((Integer)sizeIter.next()).intValue()); |
| 581 | 0 | columns.add(ss.getGuiSetSize()); |
| 582 | } | |
| 583 | } | |
| 584 | 0 | } |
| 585 | 0 | return(columns); |
| 586 | } | |
| 587 | ||
| 588 | /* (non-Javadoc) | |
| 589 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMetaSetFilter() | |
| 590 | */ | |
| 591 | public MetaSetFilter getMetaSetFilter() { | |
| 592 | 0 | return(this.metaSetFilter); |
| 593 | } | |
| 594 | ||
| 595 | /////////////////////////////////////////////////////////////////////////// | |
| 596 | /* | |
| 597 | * Mosaic Management | |
| 598 | */ | |
| 599 | /* (non-Javadoc) | |
| 600 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMosaic(int) | |
| 601 | */ | |
| 602 | public Mosaic getMosaic(int mid) { | |
| 603 | 0 | return(this.mosaicsDao.getMosaic(mid)); |
| 604 | } | |
| 605 | ||
| 606 | /* (non-Javadoc) | |
| 607 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMosaic(java.lang.String, java.lang.String, int, int) | |
| 608 | */ | |
| 609 | public Mosaic getMosaic(String masterPic, String engine, int sid, int tileHeight) { | |
| 610 | 0 | return(this.mosaicsDao.getMosaic(masterPic, engine, sid, tileHeight)); |
| 611 | } | |
| 612 | ||
| 613 | /* (non-Javadoc) | |
| 614 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMosaicTileCount(int) | |
| 615 | */ | |
| 616 | public int getMosaicTileCount(int mid) { | |
| 617 | 0 | return(this.mosaicTilesDao.getTileCount(mid)); |
| 618 | } | |
| 619 | ||
| 620 | /* (non-Javadoc) | |
| 621 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMosaics() | |
| 622 | */ | |
| 623 | public List<Mosaic> getMosaics() { | |
| 624 | 0 | return(this.mosaicsDao.getMosaics()); |
| 625 | } | |
| 626 | ||
| 627 | /* (non-Javadoc) | |
| 628 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storeMosaic(com.buckosoft.PicMan.domain.Mosaic) | |
| 629 | */ | |
| 630 | public void storeMosaic(Mosaic mosaic) { | |
| 631 | 0 | this.mosaicsDao.storeMosaic(mosaic); |
| 632 | 0 | } |
| 633 | ||
| 634 | /* (non-Javadoc) | |
| 635 | * @see com.buckosoft.PicMan.db.DatabaseFacade#deleteMosaic(int) | |
| 636 | */ | |
| 637 | public void deleteMosaic(int mid) { | |
| 638 | 0 | this.mosaicsDao.deleteMosaic(mid); |
| 639 | 0 | } |
| 640 | ||
| 641 | /////////////////////////////////////////////////////////////////////////// | |
| 642 | /* | |
| 643 | * MosaicBatch Management | |
| 644 | */ | |
| 645 | /* (non-Javadoc) | |
| 646 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMosaicBatch(int) | |
| 647 | */ | |
| 648 | public MosaicBatch getMosaicBatch(int mbid) { | |
| 649 | 0 | return(this.mosaicBatchesDao.getMosaicBatch(mbid)); |
| 650 | } | |
| 651 | ||
| 652 | /* (non-Javadoc) | |
| 653 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMosaicBatches() | |
| 654 | */ | |
| 655 | public List<MosaicBatch> getMosaicBatches() { | |
| 656 | 0 | return(this.mosaicBatchesDao.getMosaicBatches()); |
| 657 | } | |
| 658 | ||
| 659 | /* (non-Javadoc) | |
| 660 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storeMosaicBatch(com.buckosoft.PicMan.domain.MosaicBatch) | |
| 661 | */ | |
| 662 | public void storeMosaicBatch(MosaicBatch mbatch) { | |
| 663 | 0 | this.mosaicBatchesDao.storeMosaicBatch(mbatch); |
| 664 | 0 | } |
| 665 | ||
| 666 | /////////////////////////////////////////////////////////////////////////// | |
| 667 | /* | |
| 668 | * MosaicTile Management | |
| 669 | */ | |
| 670 | /* (non-Javadoc) | |
| 671 | * @see com.buckosoft.PicMan.db.DatabaseFacade#deleteMosaicTiles(int) | |
| 672 | */ | |
| 673 | public void deleteMosaicTiles(int mid) { | |
| 674 | 0 | this.mosaicTilesDao.deleteMosaicTiles(mid); |
| 675 | 0 | } |
| 676 | ||
| 677 | /* (non-Javadoc) | |
| 678 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMosaicTiles(int) | |
| 679 | */ | |
| 680 | public List<MosaicTile> getMosaicTiles(int mid) { | |
| 681 | 0 | return(this.mosaicTilesDao.getMosaicTiles(mid)); |
| 682 | } | |
| 683 | ||
| 684 | /* (non-Javadoc) | |
| 685 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storeMosaicTile(com.buckosoft.PicMan.domain.MosaicTile) | |
| 686 | */ | |
| 687 | public void storeMosaicTile(MosaicTile tile) { | |
| 688 | 0 | this.mosaicTilesDao.storeMosaicTile(tile); |
| 689 | 0 | } |
| 690 | ||
| 691 | /////////////////////////////////////////////////////////////////////////// | |
| 692 | /* | |
| 693 | * MosaicVector Management | |
| 694 | */ | |
| 695 | /* (non-Javadoc) | |
| 696 | * @see com.buckosoft.PicMan.db.DatabaseFacade#updateMosaicVectors(com.buckosoft.PicMan.domain.MosaicVector) | |
| 697 | */ | |
| 698 | public void updateMosaicVectors(MosaicVector mv) { | |
| 699 | 0 | this.mosaicVectorsDao.updateMosaicVector(mv); |
| 700 | ||
| 701 | 0 | } |
| 702 | ||
| 703 | /* (non-Javadoc) | |
| 704 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getMosaicVectors(java.util.List) | |
| 705 | */ | |
| 706 | public List<MosaicVector> getMosaicVectors(List<Pic> picList) { | |
| 707 | 0 | return(this.mosaicVectorsDao.getMosaicVectors(picList)); |
| 708 | } | |
| 709 | ||
| 710 | /////////////////////////////////////////////////////////////////////////// | |
| 711 | /* | |
| 712 | * Poster Management | |
| 713 | */ | |
| 714 | /* (non-Javadoc) | |
| 715 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPoster(int) | |
| 716 | */ | |
| 717 | public Poster getPoster(int pid) { | |
| 718 | 0 | return(this.postersDao.getPoster(pid)); |
| 719 | } | |
| 720 | ||
| 721 | /* (non-Javadoc) | |
| 722 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPosters() | |
| 723 | */ | |
| 724 | public List<Poster> getPosters() { | |
| 725 | 0 | return(this.postersDao.getPosters()); |
| 726 | } | |
| 727 | ||
| 728 | /* (non-Javadoc) | |
| 729 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storePoster(com.buckosoft.PicMan.domain.Poster) | |
| 730 | */ | |
| 731 | public void storePoster(Poster poster) { | |
| 732 | 0 | this.postersDao.storePoster(poster); |
| 733 | 0 | } |
| 734 | ||
| 735 | /* (non-Javadoc) | |
| 736 | * @see com.buckosoft.PicMan.db.DatabaseFacade#deletePoster(int) | |
| 737 | */ | |
| 738 | public void deletePoster(int pid) { | |
| 739 | 0 | this.postersDao.deletePoster(pid); |
| 740 | 0 | } |
| 741 | ||
| 742 | ||
| 743 | /////////////////////////////////////////////////////////////////////////// | |
| 744 | /* | |
| 745 | * Size Management | |
| 746 | */ | |
| 747 | ||
| 748 | /* (non-Javadoc) | |
| 749 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSizes() | |
| 750 | */ | |
| 751 | public List<Integer> getSizes() { | |
| 752 | 0 | return(sizes); |
| 753 | } | |
| 754 | ||
| 755 | /* (non-Javadoc) | |
| 756 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSizeArray() | |
| 757 | */ | |
| 758 | public int[] getSizeArray() { | |
| 759 | 0 | return(sizeArray); |
| 760 | } | |
| 761 | ||
| 762 | /* (non-Javadoc) | |
| 763 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSizeCount() | |
| 764 | */ | |
| 765 | public int getSizeCount() { | |
| 766 | 0 | return(5); |
| 767 | } | |
| 768 | ||
| 769 | ||
| 770 | /////////////////////////////////////////////////////////////////////////// | |
| 771 | /* Chains Management */ | |
| 772 | ||
| 773 | /* (non-Javadoc) | |
| 774 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getChains() | |
| 775 | */ | |
| 776 | public List<Chain> getChains() { | |
| 777 | 0 | return(chainsDao.getChains()); |
| 778 | } | |
| 779 | ||
| 780 | /* (non-Javadoc) | |
| 781 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getChainCount() | |
| 782 | */ | |
| 783 | public int getChainCount() { | |
| 784 | 0 | return(chainsDao.getChainCount()); |
| 785 | } | |
| 786 | ||
| 787 | /* (non-Javadoc) | |
| 788 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getChain(java.lang.String) | |
| 789 | */ | |
| 790 | public Chain getChain(String chainName) { | |
| 791 | 0 | return(chainsDao.getChain(chainName)); |
| 792 | } | |
| 793 | ||
| 794 | /* (non-Javadoc) | |
| 795 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getChain(int) | |
| 796 | */ | |
| 797 | public Chain getChain(int cid) { | |
| 798 | 0 | return(chainsDao.getChain(cid)); |
| 799 | } | |
| 800 | ||
| 801 | /* (non-Javadoc) | |
| 802 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storeChain(com.buckosoft.PicMan.domain.Chain) | |
| 803 | */ | |
| 804 | public void storeChain(Chain chain) { | |
| 805 | 0 | chainsDao.storeChain(chain); |
| 806 | 0 | } |
| 807 | ||
| 808 | /* (non-Javadoc) | |
| 809 | * @see com.buckosoft.PicMan.db.DatabaseFacade#deleteChain(com.buckosoft.PicMan.domain.Chain) | |
| 810 | */ | |
| 811 | public void deleteChain(Chain chain) { | |
| 812 | 0 | chainsDao.deleteChain(chain); |
| 813 | 0 | } |
| 814 | ||
| 815 | /* (non-Javadoc) | |
| 816 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSetsInChain(int) | |
| 817 | */ | |
| 818 | public List<Set> getSetsInChain(int cid) { | |
| 819 | 0 | Chain c = getChain(cid); |
| 820 | 0 | LinkedList<Set> theList = new LinkedList<Set>(); |
| 821 | 0 | Iterator<SetSize> iter = c.getSetSizes().iterator(); |
| 822 | 0 | while (iter.hasNext()) { |
| 823 | 0 | SetSize ss = (SetSize)iter.next(); |
| 824 | 0 | boolean match = false; |
| 825 | 0 | Iterator<Set> iterThe = theList.iterator(); |
| 826 | 0 | while (iterThe.hasNext()) { |
| 827 | 0 | Set s = iterThe.next(); |
| 828 | 0 | if (DEBUG) { |
| 829 | 0 | if (s == null || ss == null) { |
| 830 | 0 | logger.info("s or ss == null"); |
| 831 | } | |
| 832 | } | |
| 833 | 0 | if (s.getName().equals(ss.getSetName())) { |
| 834 | 0 | match = true; |
| 835 | 0 | break; |
| 836 | } | |
| 837 | 0 | } |
| 838 | 0 | if (match == false) { |
| 839 | 0 | if (DEBUG) |
| 840 | 0 | logger.info("Add set \"" + ss.getSetName() + "\""); |
| 841 | 0 | Set set = setsDao.getSet(ss.getSetName()); |
| 842 | 0 | if (set == null) { |
| 843 | 0 | RuntimeException e = new RuntimeException("getSetsInChain can't find set \"" + ss.getSetName() + "\" in chain \"" + c.getName() + "\""); |
| 844 | 0 | pmcf.addError(e); |
| 845 | 0 | } else |
| 846 | 0 | theList.add(set); |
| 847 | } | |
| 848 | 0 | } |
| 849 | 0 | return(theList); |
| 850 | ||
| 851 | } | |
| 852 | ||
| 853 | /* (non-Javadoc) | |
| 854 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSetSizesInChain(int, int) | |
| 855 | */ | |
| 856 | @SuppressWarnings("unchecked") | |
| 857 | public List<SetSize> getSetSizesInChain(int cid, int sid) { | |
| 858 | 0 | Chain c = getChain(cid); |
| 859 | 0 | Set set = getSet(sid); |
| 860 | 0 | LinkedList<SetSize> theList = (LinkedList<SetSize>) c.getSetSizes().clone(); |
| 861 | 0 | Iterator<SetSize> iter = theList.iterator(); |
| 862 | 0 | while (iter.hasNext()) { |
| 863 | 0 | SetSize ss = (SetSize)iter.next(); |
| 864 | 0 | if (!set.getName().equals(ss.getSetName())) { |
| 865 | 0 | iter.remove(); |
| 866 | } | |
| 867 | 0 | } |
| 868 | 0 | return(theList); |
| 869 | } | |
| 870 | ||
| 871 | /////////////////////////////////////////////////////////////////////////// | |
| 872 | /* Contacts */ | |
| 873 | ||
| 874 | ||
| 875 | /* (non-Javadoc) | |
| 876 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getContact(int, java.lang.String) | |
| 877 | */ | |
| 878 | public Contact getContact(int cid, String name) { | |
| 879 | 0 | return(contactsDao.getContact(cid, name)); |
| 880 | } | |
| 881 | ||
| 882 | /* (non-Javadoc) | |
| 883 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getContact(int, java.lang.String, int, int) | |
| 884 | */ | |
| 885 | public Contact getContact(int cid, String setName, int size, int item) { | |
| 886 | 0 | return(contactsDao.getContact(cid, setName, size, item)); |
| 887 | } | |
| 888 | ||
| 889 | /* (non-Javadoc) | |
| 890 | * @see com.buckosoft.PicMan.db.DatabaseFacade#addContact(com.buckosoft.PicMan.domain.Contact) | |
| 891 | */ | |
| 892 | public void addContact(Contact c) { | |
| 893 | 0 | contactsDao.addContact(c); |
| 894 | 0 | } |
| 895 | ||
| 896 | /* (non-Javadoc) | |
| 897 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getNewestContact() | |
| 898 | */ | |
| 899 | public Contact getNewestContact() { | |
| 900 | 0 | return(contactsDao.getNewestContact()); |
| 901 | } | |
| 902 | ||
| 903 | /* (non-Javadoc) | |
| 904 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getContactOldestMap(com.buckosoft.PicMan.domain.Chain) | |
| 905 | */ | |
| 906 | public HashMap<String, Date> getContactOldestMap(Chain chain) { | |
| 907 | 0 | return(contactsDao.getContactOldestMap(chain)); |
| 908 | } | |
| 909 | /////////////////////////////////////////////////////////////////////////// | |
| 910 | /* | |
| 911 | * Filter management | |
| 912 | */ | |
| 913 | ||
| 914 | ||
| 915 | /* (non-Javadoc) | |
| 916 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getFilterCount() | |
| 917 | */ | |
| 918 | public int getFilterCount() { | |
| 919 | 0 | return(this.filtersDao.getFilterCount()); |
| 920 | } | |
| 921 | ||
| 922 | /* (non-Javadoc) | |
| 923 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getFilterColumns() | |
| 924 | */ | |
| 925 | public List<String> getFilterColumns() { | |
| 926 | 0 | if (DEBUG) |
| 927 | 0 | logger.info("getFilterColumns()"); |
| 928 | 0 | return(this.filtersDao.getFilterColumns()); |
| 929 | } | |
| 930 | ||
| 931 | /* (non-Javadoc) | |
| 932 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getFilters() | |
| 933 | */ | |
| 934 | public List<Filter> getFilters() { | |
| 935 | 0 | return(this.filtersDao.getFilters()); |
| 936 | } | |
| 937 | ||
| 938 | /* (non-Javadoc) | |
| 939 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getFiltersBySet(java.lang.String, int) | |
| 940 | */ | |
| 941 | public List<Filter> getFiltersBySet(String set, int size) { | |
| 942 | 0 | return(this.filtersDao.getFiltersBySet(set, size)); |
| 943 | } | |
| 944 | ||
| 945 | /* (non-Javadoc) | |
| 946 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicNamesBySet(java.lang.String, int) | |
| 947 | */ | |
| 948 | public List<String> getPicNamesBySet(String setName, int size) { | |
| 949 | 0 | Set set = getSet(setName); |
| 950 | 0 | return(getPicNamesBySet(set, size)); |
| 951 | } | |
| 952 | ||
| 953 | /* (non-Javadoc) | |
| 954 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicNamesBySet(com.buckosoft.PicMan.domain.Set, int) | |
| 955 | */ | |
| 956 | public List<String> getPicNamesBySet(Set set, int size) { | |
| 957 | 0 | if (set.isMetaSet()) |
| 958 | 0 | return(this.metaSetFilter.getListOfPicNamesInMetaSet(set, size, MetaSet.NONE, 0)); |
| 959 | 0 | if (set.isMicroSet() || set.isNanoSet()) |
| 960 | 0 | return(this.getMicroSetPicNamesInSet(set.getSid())); |
| 961 | 0 | return(this.filtersDao.getPicNamesBySet(set, size)); |
| 962 | } | |
| 963 | ||
| 964 | ||
| 965 | @Override | |
| 966 | public List<String> getPicNamesBySet(MetaSet set, int size, int rateOp, int rateVal) { | |
| 967 | 0 | return(this.metaSetFilter.getListOfPicNames(set, size, rateOp, rateVal)); |
| 968 | } | |
| 969 | ||
| 970 | /* (non-Javadoc) | |
| 971 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicNamesBySet(java.lang.String, int, int, int) | |
| 972 | */ | |
| 973 | public List<String> getPicNamesBySet(String setName, int size, int rateOp, int rateVal) { | |
| 974 | 0 | Set set = getSet(setName); |
| 975 | 0 | return(getPicNamesBySet(set, size, rateOp, rateVal)); |
| 976 | } | |
| 977 | ||
| 978 | /* (non-Javadoc) | |
| 979 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicNamesBySet(java.lang.String, int, int, int) | |
| 980 | */ | |
| 981 | public List<String> getPicNamesBySet(Set set, int size, int rateOp, int rateVal) { | |
| 982 | 0 | if (set.isMetaSet()) |
| 983 | 0 | return(this.metaSetFilter.getListOfPicNamesInMetaSet(set, size, rateOp, rateVal)); |
| 984 | 0 | if (set.isMicroSet() || set.isNanoSet()) |
| 985 | 0 | return(this.getMicroSetPicNamesInSet(set.getSid())); |
| 986 | // if (set.isFuncSet()) | |
| 987 | // aborted: return(this.getPicNamesByFunc(set.getSid(), size, rateOp, rateVal)); | |
| 988 | 0 | return(this.filtersDao.getPicNamesBySet(set, size, rateOp, rateVal)); |
| 989 | } | |
| 990 | ||
| 991 | public List<String> getPicNamesByFunc(int func, int size, int rateOp, String operand) { | |
| 992 | 0 | switch (func) { |
| 993 | case Set.FUNC_SID_DATE: | |
| 994 | 0 | if (rateOp == 0) |
| 995 | 0 | return(this.picsDao.getPicNames()); |
| 996 | 0 | if (operand == null) |
| 997 | 0 | operand = "1900-01-01"; |
| 998 | 0 | return(this.picsDao.getPicNamesByDateFunc(MetaSet.rateOps[rateOp], operand)); |
| 999 | // return(new LinkedList<String>()); | |
| 1000 | case Set.FUNC_SID_ROOT: | |
| 1001 | 0 | return(this.picsDao.getPicNamesByRootFunc(MetaSet.rateOps[rateOp], Integer.parseInt(operand))); |
| 1002 | default: | |
| 1003 | 0 | RuntimeException e = new RuntimeException("unknown func: " + func); |
| 1004 | ||
| 1005 | 0 | throw e; |
| 1006 | } | |
| 1007 | ||
| 1008 | } | |
| 1009 | ||
| 1010 | /* (non-Javadoc) | |
| 1011 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getFilterDates() | |
| 1012 | */ | |
| 1013 | public HashMap<String, Date> getSetTimestamps() { | |
| 1014 | 0 | HashMap<String, Date> hm = this.setTimestampsDao.getSetTimestamps(); |
| 1015 | 0 | return(hm); |
| 1016 | } | |
| 1017 | ||
| 1018 | /* (non-Javadoc) | |
| 1019 | * @see com.buckosoft.PicMan.db.DatabaseFacade#addFilter(com.buckosoft.PicMan.domain.Filter) | |
| 1020 | */ | |
| 1021 | public void addFilter(Filter filter) { | |
| 1022 | // Filter oldFilter = this.filtersDao.getFilter(filter.getPicName()); | |
| 1023 | ||
| 1024 | 0 | this.filtersDao.addFilter(filter); |
| 1025 | 0 | this.updateMicroFilters(filter); |
| 1026 | // this.processFilterDates(filter); | |
| 1027 | /* | |
| 1028 | // build a list of changed metaSets | |
| 1029 | LinkedHashMap<String, String> changed = new LinkedHashMap<String, String>(); | |
| 1030 | List<Set> sets = this.getSets(); | |
| 1031 | Iterator<Set> iter = sets.iterator(); | |
| 1032 | int i; | |
| 1033 | while (iter.hasNext()) { | |
| 1034 | Set set = iter.next(); | |
| 1035 | if (!set.isMetaSet()) | |
| 1036 | continue; | |
| 1037 | if (DEBUGMETASETS) { | |
| 1038 | if (set.getName().equals("DickB")) | |
| 1039 | logger.info("DickB"); | |
| 1040 | } | |
| 1041 | ||
| 1042 | boolean[] reto = this.metaSetFilter.isFilterInSet(this.getMetaSet(set.getSid()), oldFilter); | |
| 1043 | boolean[] retn = this.metaSetFilter.isFilterInSet(this.getMetaSet(set.getSid()), filter); | |
| 1044 | | |
| 1045 | if (DEBUGMETASETS) { | |
| 1046 | String s = ""; | |
| 1047 | for (i=0; i<sizeArray.length; i++) | |
| 1048 | s += reto[i] ? "T" : "F"; | |
| 1049 | logger.info("reto=" + s + " - " + set.getName()); | |
| 1050 | s = ""; | |
| 1051 | for (i=0; i<sizeArray.length; i++) | |
| 1052 | s += retn[i] ? "T" : "F"; | |
| 1053 | logger.info("retn=" + s + " - " + set.getName()); | |
| 1054 | } | |
| 1055 | ||
| 1056 | for (i=0; i<sizeArray.length; i++) { | |
| 1057 | if (reto[i] ^ retn[i]) { | |
| 1058 | if (DEBUG) | |
| 1059 | logger.info("set updated: " + set.getName() + " ro=" + reto[i] + " rn=" + retn[i]); | |
| 1060 | changed.put(set.getName() + "_" + sizeArray[i], ""); | |
| 1061 | } | |
| 1062 | } | |
| 1063 | } | |
| 1064 | // if (!changed.isEmpty()) { | |
| 1065 | // this.setTimestampsDao.updateFilterDates(changed); | |
| 1066 | // } | |
| 1067 | 0 | */ } |
| 1068 | /* | |
| 1069 | @SuppressWarnings("unchecked") | |
| 1070 | public void processFilterDates(Filter f) { | |
| 1071 | if (f != null) { | |
| 1072 | LinkedHashMap<String, Integer> oldf = this.getFilter(f.getPicName()).getFilters(); | |
| 1073 | LinkedHashMap<String, Integer> newf = (LinkedHashMap<String, Integer>)f.getFilters().clone(); | |
| 1074 | LinkedHashMap<String, String> changed = new LinkedHashMap<String, String>(); | |
| 1075 | | |
| 1076 | Iterator<String> it = oldf.keySet().iterator(); | |
| 1077 | while (it.hasNext()) { | |
| 1078 | String oldKey = it.next(); | |
| 1079 | if (!newf.containsKey(oldKey)) { | |
| 1080 | if (DEBUG) | |
| 1081 | logger.info("newf !key" + oldKey); | |
| 1082 | if (((Integer)oldf.get(oldKey)).intValue() != 0) { | |
| 1083 | if (DEBUG) | |
| 1084 | logger.info("Add newf" + oldKey); | |
| 1085 | changed.put(oldKey, ""); | |
| 1086 | } | |
| 1087 | } else { | |
| 1088 | if (DEBUG) | |
| 1089 | logger.info("comparing: " + oldKey + " old:" + ((Integer)oldf.get(oldKey)).intValue() + " new: " + ((Integer)newf.get(oldKey)).intValue()); | |
| 1090 | if (((Integer)oldf.get(oldKey)).intValue() != ((Integer)newf.get(oldKey)).intValue()) { | |
| 1091 | changed.put(oldKey, ""); | |
| 1092 | if (DEBUG) | |
| 1093 | logger.info("keys different"); | |
| 1094 | } | |
| 1095 | newf.remove(oldKey); | |
| 1096 | } | |
| 1097 | } | |
| 1098 | it = newf.keySet().iterator(); | |
| 1099 | while (it.hasNext()) { // These are in new, but not old, so update | |
| 1100 | String newKey = (String)it.next(); | |
| 1101 | if (DEBUG) | |
| 1102 | logger.info("newf has key: " + newKey); | |
| 1103 | changed.put(newKey, ""); | |
| 1104 | } | |
| 1105 | // this.setTimestampsDao.updateFilterDates(changed); | |
| 1106 | } | |
| 1107 | } | |
| 1108 | */ | |
| 1109 | ||
| 1110 | ||
| 1111 | /* (non-Javadoc) | |
| 1112 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getFilter(java.lang.String) | |
| 1113 | */ | |
| 1114 | public Filter getFilter(String picName) { | |
| 1115 | 0 | Filter f = this.filtersDao.getFilter(picName); |
| 1116 | 0 | Pic pic = this.getPic(picName); |
| 1117 | 0 | if (pic == null) { |
| 1118 | 0 | throw new RuntimeException("No pic for " + picName); |
| 1119 | } | |
| 1120 | 0 | List<FilterMicroSet> li = this.filtersMicroSetsDao.getFiltersInPid(pic.getPid()); |
| 1121 | 0 | Iterator<FilterMicroSet> iter = li.iterator(); |
| 1122 | 0 | while (iter.hasNext()) { |
| 1123 | 0 | FilterMicroSet fms = iter.next(); |
| 1124 | 0 | f.addFilter(this.setsDao.getSet(fms.getSid()).getName(), fms.getValue()); |
| 1125 | 0 | } |
| 1126 | ||
| 1127 | 0 | return(f); |
| 1128 | } | |
| 1129 | ||
| 1130 | ||
| 1131 | /* (non-Javadoc) | |
| 1132 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicFromFilterMicroSet(int) | |
| 1133 | */ | |
| 1134 | public FilterMicroSet getPicFromFilterMicroSet(int pid, int sid) { | |
| 1135 | 0 | return(this.filtersMicroSetsDao.getFilterMicroSet(pid, sid)); |
| 1136 | } | |
| 1137 | ||
| 1138 | private List<String> getMicroSetPicNamesInSet(int sid) { | |
| 1139 | 0 | List<FilterMicroSet> ll = this.filtersMicroSetsDao.getPicsInSet(sid); |
| 1140 | 0 | List<String> list = new LinkedList<String>(); |
| 1141 | ||
| 1142 | 0 | Iterator<FilterMicroSet> iter = ll.iterator(); |
| 1143 | 0 | while (iter.hasNext()) { |
| 1144 | 0 | FilterMicroSet fms = iter.next(); |
| 1145 | 0 | if (fms.getValue() != 0) |
| 1146 | 0 | list.add(this.getPic(fms.getPid()).getName()); |
| 1147 | 0 | } |
| 1148 | 0 | return(list); |
| 1149 | } | |
| 1150 | ||
| 1151 | private void updateMicroFilters(Filter filter) { | |
| 1152 | 0 | Pic pic = this.getPic(filter.getPicName()); |
| 1153 | 0 | this.filtersMicroSetsDao.deleteFilters(pic.getPid()); |
| 1154 | ||
| 1155 | 0 | LinkedHashMap<String, Integer> map = filter.getFilters(); |
| 1156 | 0 | Iterator<String> it = map.keySet().iterator(); |
| 1157 | String key; | |
| 1158 | Set set; | |
| 1159 | 0 | while (it.hasNext()) { |
| 1160 | 0 | key = (String)it.next(); |
| 1161 | // if (DEBUG) | |
| 1162 | // logger.info("key=" + key); | |
| 1163 | 0 | if (key.indexOf('_') != -1) |
| 1164 | 0 | continue; |
| 1165 | 0 | set = this.getSet(key); |
| 1166 | 0 | this.filtersMicroSetsDao.storeFilter(set.getSid(), pic.getPid(), map.get(key)); |
| 1167 | } | |
| 1168 | ||
| 1169 | 0 | } |
| 1170 | ||
| 1171 | /* (non-Javadoc) | |
| 1172 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getUser(int) | |
| 1173 | */ | |
| 1174 | public User getUser(int userid) throws DataAccessException { | |
| 1175 | 0 | return(this.usersDao.getUser(userid)); |
| 1176 | } | |
| 1177 | ||
| 1178 | /* (non-Javadoc) | |
| 1179 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storeUser(com.buckosoft.PicMan.domain.User) | |
| 1180 | */ | |
| 1181 | public void storeUser(User user) { | |
| 1182 | 0 | this.usersDao.storeUser(user); |
| 1183 | 0 | } |
| 1184 | ||
| 1185 | /////////////////////////////////////////////////////////////////////////// | |
| 1186 | /* Virgin management */ | |
| 1187 | ||
| 1188 | /* (non-Javadoc) | |
| 1189 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getVirgins() | |
| 1190 | */ | |
| 1191 | public List<Virgin> getVirgins() { | |
| 1192 | 0 | return(this.virginsDao.getVirgins()); |
| 1193 | } | |
| 1194 | ||
| 1195 | /* (non-Javadoc) | |
| 1196 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getVirgins(int) | |
| 1197 | */ | |
| 1198 | public List<Virgin> getVirgins(int max) { | |
| 1199 | 0 | return(this.virginsDao.getVirgins(max)); |
| 1200 | } | |
| 1201 | ||
| 1202 | /* (non-Javadoc) | |
| 1203 | * @see com.buckosoft.PicMan.db.DatabaseFacade#isVirgin(java.lang.String) | |
| 1204 | */ | |
| 1205 | public boolean isVirgin(String pic) { | |
| 1206 | 0 | return(this.virginsDao.isVirgin(pic)); |
| 1207 | } | |
| 1208 | ||
| 1209 | /* (non-Javadoc) | |
| 1210 | * @see com.buckosoft.PicMan.db.DatabaseFacade#addVirgin(java.lang.String) | |
| 1211 | */ | |
| 1212 | public void addVirgin(String pic) { | |
| 1213 | 0 | this.virginsDao.addVirgin(pic); |
| 1214 | 0 | } |
| 1215 | ||
| 1216 | /* (non-Javadoc) | |
| 1217 | * @see com.buckosoft.PicMan.db.DatabaseFacade#deleteVirgin(java.lang.String) | |
| 1218 | */ | |
| 1219 | public void deleteVirgin(String pic) { | |
| 1220 | 0 | this.virginsDao.deleteVirgin(pic); |
| 1221 | 0 | } |
| 1222 | ||
| 1223 | /* (non-Javadoc) | |
| 1224 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getVirginCount() | |
| 1225 | */ | |
| 1226 | public int getVirginCount() { | |
| 1227 | 0 | return(this.virginsDao.getVirginCount()); |
| 1228 | } | |
| 1229 | ||
| 1230 | ||
| 1231 | /////////////////////////////////////////////////////////////////////////// | |
| 1232 | /* Pic management */ | |
| 1233 | ||
| 1234 | /* (non-Javadoc) | |
| 1235 | * @see com.buckosoft.PicMan.db.DatabaseFacade#addPic(com.buckosoft.PicMan.domain.Pic) | |
| 1236 | */ | |
| 1237 | public void addPic(Pic pic) { | |
| 1238 | 0 | this.picsDao.addPic(pic); |
| 1239 | 0 | } |
| 1240 | ||
| 1241 | /* (non-Javadoc) | |
| 1242 | * @see com.buckosoft.PicMan.db.DatabaseFacade#updatePic(com.buckosoft.PicMan.domain.Pic) | |
| 1243 | */ | |
| 1244 | public void updatePic(Pic pic) { | |
| 1245 | 0 | this.picsDao.updatePic(pic); |
| 1246 | 0 | } |
| 1247 | ||
| 1248 | /* (non-Javadoc) | |
| 1249 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPic(java.lang.String) | |
| 1250 | */ | |
| 1251 | public Pic getPic(String picName) { | |
| 1252 | 0 | return(this.picsDao.getPic(picName)); |
| 1253 | } | |
| 1254 | ||
| 1255 | /* (non-Javadoc) | |
| 1256 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPic(int) | |
| 1257 | */ | |
| 1258 | public Pic getPic(int pid) { | |
| 1259 | 0 | return(this.picsDao.getPic(pid)); |
| 1260 | } | |
| 1261 | ||
| 1262 | /* | |
| 1263 | * (non-Javadoc) | |
| 1264 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getNewestPic() | |
| 1265 | */ | |
| 1266 | public Pic getNewestPic() { | |
| 1267 | 0 | return(this.picsDao.getNewestPic()); |
| 1268 | } | |
| 1269 | ||
| 1270 | /* (non-Javadoc) | |
| 1271 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getRandomPic() | |
| 1272 | */ | |
| 1273 | public Pic getRandomPic() { | |
| 1274 | 0 | return(this.picsDao.getRandomPic()); |
| 1275 | } | |
| 1276 | ||
| 1277 | /* (non-Javadoc) | |
| 1278 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicsByMD5Sum(long) | |
| 1279 | */ | |
| 1280 | @Override | |
| 1281 | public List<Pic> getPicsByMD5Sum(long md5sum) { | |
| 1282 | 0 | return(this.picsDao.getPicsByMD5Sum(md5sum)); |
| 1283 | } | |
| 1284 | ||
| 1285 | ||
| 1286 | /* (non-Javadoc) | |
| 1287 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getRandomHomePagePic(com.buckosoft.PicMan.domain.User) | |
| 1288 | */ | |
| 1289 | public String getRandomHomePagePicName(User user) { | |
| 1290 | 0 | if (user.getHomeThumbSetName().isEmpty()) |
| 1291 | 0 | return(""); |
| 1292 | 0 | if (homeThumbAttr.homeThumbsUser == null || homeThumbAttr.homeThumbsUser != user |
| 1293 | 0 | || !user.getHomeThumbSetName().equals(homeThumbAttr.homeThumbsForUserSetCached)) { |
| 1294 | 0 | homeThumbAttr.homeThumbsUser = user; |
| 1295 | 0 | homeThumbAttr.homeThumbsForUser = null; |
| 1296 | } | |
| 1297 | 0 | if (homeThumbAttr.homeThumbsForUser == null) { |
| 1298 | 0 | homeThumbAttr.homeThumbsForUserSetCached = user.getHomeThumbSetName(); |
| 1299 | 0 | homeThumbAttr.homeThumbsForUser = new LinkedList<String>(); |
| 1300 | 0 | List<String> ll = this.getPicNamesBySet(user.getHomeThumbSetName(), 75); |
| 1301 | 0 | homeThumbAttr.homeThumbsUserIndex = 0; |
| 1302 | 0 | while (!ll.isEmpty()) { |
| 1303 | 0 | double d = Math.random() * ll.size(); |
| 1304 | 0 | homeThumbAttr.homeThumbsForUser.add(ll.remove((int)d)); |
| 1305 | 0 | } |
| 1306 | } | |
| 1307 | 0 | if (homeThumbAttr.homeThumbsForUser.isEmpty()) |
| 1308 | 0 | return(""); |
| 1309 | 0 | String s = homeThumbAttr.homeThumbsForUser.get(homeThumbAttr.homeThumbsUserIndex++); |
| 1310 | 0 | if (homeThumbAttr.homeThumbsUserIndex >= homeThumbAttr.homeThumbsForUser.size()) |
| 1311 | 0 | homeThumbAttr.homeThumbsUserIndex = 0; |
| 1312 | 0 | return(s); |
| 1313 | } | |
| 1314 | ||
| 1315 | @Override | |
| 1316 | public void onSetChanged(SetSize setSize) { | |
| 1317 | 0 | if (homeThumbAttr.homeThumbsForUserSetCached == setSize.getSetName()) { |
| 1318 | 0 | homeThumbAttr.homeThumbsForUser = null; |
| 1319 | } | |
| 1320 | 0 | } |
| 1321 | ||
| 1322 | /* (non-Javadoc) | |
| 1323 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getHomePageRandomPic() | |
| 1324 | */ | |
| 1325 | /* public Pic getRandomHomePagePic(User user) { | |
| 1326 | return(this.picsDao.getRandomPic(1)); | |
| 1327 | } | |
| 1328 | */ | |
| 1329 | ||
| 1330 | /* (non-Javadoc) | |
| 1331 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicsMap() | |
| 1332 | */ | |
| 1333 | public HashMap<String, Date> getPicsMap() { | |
| 1334 | 0 | return(this.picsDao.getPicsMap()); |
| 1335 | } | |
| 1336 | ||
| 1337 | /* (non-Javadoc) | |
| 1338 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPics() | |
| 1339 | */ | |
| 1340 | public List<Pic> getPics() { | |
| 1341 | 0 | return(this.picsDao.getPics()); |
| 1342 | } | |
| 1343 | ||
| 1344 | /* (non-Javadoc) | |
| 1345 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPics(java.lang.String) | |
| 1346 | */ | |
| 1347 | public List<Pic> getPics(String picName) { | |
| 1348 | 0 | return(this.picsDao.getPics(picName)); |
| 1349 | } | |
| 1350 | ||
| 1351 | /* (non-Javadoc) | |
| 1352 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPics(com.buckosoft.PicMan.domain.Set) | |
| 1353 | */ | |
| 1354 | public List<Pic> getPics(Set set, int size) { | |
| 1355 | 0 | size = normalizeSize(size); |
| 1356 | 0 | List<String> list = this.getPicNamesBySet(set.getName(), size); |
| 1357 | 0 | return(this.picsDao.getPics(list)); |
| 1358 | } | |
| 1359 | ||
| 1360 | /* (non-Javadoc) | |
| 1361 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicsInDir(int, java.lang.String) | |
| 1362 | */ | |
| 1363 | public List<Pic> getPicsInDir(int rid, String dirName) { | |
| 1364 | 0 | return(this.picsDao.getPicsInDir(rid, dirName)); |
| 1365 | } | |
| 1366 | ||
| 1367 | public List<Pic> getPicsNewerThan(Calendar calendar) { | |
| 1368 | 0 | return(this.picsDao.getPicsNewerThan(calendar)); |
| 1369 | } | |
| 1370 | ||
| 1371 | /* (non-Javadoc) | |
| 1372 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicRate(com.buckosoft.PicMan.domain.Pic, com.buckosoft.PicMan.domain.Set, int) | |
| 1373 | */ | |
| 1374 | @Override | |
| 1375 | public double getPicRate(String picName, Set set, int size) { | |
| 1376 | 0 | size = normalizeSize(size); |
| 1377 | 0 | Filter f = this.getFilter(picName); |
| 1378 | 0 | if (!set.isMetaSet()) { |
| 1379 | 0 | return(f.getFilter(set.getName(), size)); |
| 1380 | } else { | |
| 1381 | 0 | return(this.getMetaSetFilter().getPicRate(this.getMetaSet(set.getSid()), f, size)); |
| 1382 | } | |
| 1383 | } | |
| 1384 | ||
| 1385 | @Override | |
| 1386 | public double getPicRate(String picName, MetaSet metaSet, int size) { | |
| 1387 | 0 | size = normalizeSize(size); |
| 1388 | 0 | Filter f = this.getFilter(picName); |
| 1389 | 0 | return(this.getMetaSetFilter().getPicRate(metaSet, f, size)); |
| 1390 | } | |
| 1391 | ||
| 1392 | /* (non-Javadoc) | |
| 1393 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicMaxThumbCacheDirUsed() | |
| 1394 | */ | |
| 1395 | public int getPicMaxThumbCacheDirUsed() { | |
| 1396 | 0 | return(this.picsDao.getMaxThumbCacheDirUsed()); |
| 1397 | } | |
| 1398 | ||
| 1399 | /* (non-Javadoc) | |
| 1400 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getPicThumbCacheFillCount(int) | |
| 1401 | */ | |
| 1402 | public int getPicThumbCacheFillCount(int cacheDir) { | |
| 1403 | 0 | return(this.picsDao.getThumbCacheFillCount(cacheDir)); |
| 1404 | } | |
| 1405 | ||
| 1406 | /* (non-Javadoc) | |
| 1407 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getUuid(java.lang.String, int) | |
| 1408 | */ | |
| 1409 | public String getUuid(String setName, int size) { | |
| 1410 | 0 | DecimalFormat df3 = new DecimalFormat("000"); |
| 1411 | 0 | return(new String(setName + "_" + df3.format(size))); |
| 1412 | } | |
| 1413 | ||
| 1414 | /** Given an arbitrary tile height, return a height that we actually know about. | |
| 1415 | * @param size The size to normalize | |
| 1416 | * @return One of the sizes from our size array of filters | |
| 1417 | */ | |
| 1418 | public int normalizeSize(int size) { | |
| 1419 | 0 | for (int i=0; i<this.sizeArray.length; i++) { |
| 1420 | 0 | if (size <= this.sizeArray[i]) |
| 1421 | 0 | return(this.sizeArray[i]); |
| 1422 | } | |
| 1423 | 0 | return(this.sizeArray[this.sizeArray.length-1]); |
| 1424 | } | |
| 1425 | ||
| 1426 | ||
| 1427 | public Date getClientSyncTimestamp(String host) { | |
| 1428 | 0 | return(this.server_SyncDao.getClientTimestamp(host)); |
| 1429 | } | |
| 1430 | ||
| 1431 | public void setClientSyncTimestamp(String host) { | |
| 1432 | 0 | this.server_SyncDao.setClientTimestamp(host); |
| 1433 | 0 | } |
| 1434 | ||
| 1435 | ||
| 1436 | /* (non-Javadoc) | |
| 1437 | * @see com.buckosoft.PicMan.db.DatabaseFacade#updateSetTimestamp(java.lang.String) | |
| 1438 | */ | |
| 1439 | @Override | |
| 1440 | public void updateSetTimestamp(String setSize) { | |
| 1441 | 0 | this.setTimestampsDao.updateSetTimestamp(setSize); |
| 1442 | 0 | } |
| 1443 | ||
| 1444 | /* (non-Javadoc) | |
| 1445 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storeSyncClient(com.buckosoft.PicMan.domain.SyncClient) | |
| 1446 | */ | |
| 1447 | @Override | |
| 1448 | public void storeSyncClient(SyncClient syncClient) { | |
| 1449 | 0 | Session session = HibernateUtil.getSessionFactory().getCurrentSession(); |
| 1450 | 0 | session.getTransaction().begin(); |
| 1451 | try { | |
| 1452 | 0 | session.saveOrUpdate(syncClient); |
| 1453 | } finally { | |
| 1454 | 0 | session.getTransaction().commit(); |
| 1455 | 0 | } |
| 1456 | 0 | } |
| 1457 | ||
| 1458 | ||
| 1459 | /* (non-Javadoc) | |
| 1460 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSyncClients() | |
| 1461 | */ | |
| 1462 | @SuppressWarnings("unchecked") | |
| 1463 | @Override | |
| 1464 | public List<SyncClient> getSyncClients() { | |
| 1465 | 0 | Session session = HibernateUtil.getSessionFactory().getCurrentSession(); |
| 1466 | 0 | session.getTransaction().begin(); |
| 1467 | 0 | List<SyncClient> result = null; |
| 1468 | try { | |
| 1469 | 0 | result = session.createQuery("from SyncClient").list(); |
| 1470 | 0 | } catch (HibernateException e) { |
| 1471 | 0 | e.printStackTrace(); |
| 1472 | } finally { | |
| 1473 | 0 | session.getTransaction().commit(); |
| 1474 | 0 | } |
| 1475 | 0 | return(result); |
| 1476 | } | |
| 1477 | ||
| 1478 | ||
| 1479 | /* (non-Javadoc) | |
| 1480 | * @see com.buckosoft.PicMan.db.DatabaseFacade#storeSyncServer(com.buckosoft.PicMan.domain.SyncServer) | |
| 1481 | */ | |
| 1482 | @Override | |
| 1483 | public void storeSyncServer(SyncServer syncServer) { | |
| 1484 | 0 | Session session = HibernateUtil.getSessionFactory().getCurrentSession(); |
| 1485 | 0 | session.getTransaction().begin(); |
| 1486 | try { | |
| 1487 | 0 | session.saveOrUpdate(syncServer); |
| 1488 | } finally { | |
| 1489 | 0 | session.getTransaction().commit(); |
| 1490 | 0 | } |
| 1491 | 0 | } |
| 1492 | ||
| 1493 | ||
| 1494 | /* (non-Javadoc) | |
| 1495 | * @see com.buckosoft.PicMan.db.DatabaseFacade#getSyncServers() | |
| 1496 | */ | |
| 1497 | @Override | |
| 1498 | public List<SyncServer> getSyncServers() { | |
| 1499 | 0 | Session session = HibernateUtil.getSessionFactory().getCurrentSession(); |
| 1500 | 0 | session.getTransaction().begin(); |
| 1501 | @SuppressWarnings("unchecked") | |
| 1502 | 0 | List<SyncServer> result = session.createQuery("from SyncServer").list(); |
| 1503 | 0 | session.getTransaction().commit(); |
| 1504 | 0 | return(result); |
| 1505 | } | |
| 1506 | } |