001// -------------------------------------------------------------------------------- 002// Copyright 2002-2024 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * IconDetailFactory.java 021 */ 022 023package com.echothree.model.data.icon.server.factory; 024 025import com.echothree.model.data.icon.common.pk.IconPK; 026import com.echothree.model.data.document.common.pk.DocumentPK; 027 028import com.echothree.model.data.icon.server.entity.Icon; 029import com.echothree.model.data.document.server.entity.Document; 030 031import com.echothree.model.data.icon.common.IconDetailConstants; 032import com.echothree.model.data.icon.common.pk.IconDetailPK; 033import com.echothree.model.data.icon.server.value.IconDetailValue; 034import com.echothree.model.data.icon.server.entity.IconDetail; 035import com.echothree.util.common.exception.PersistenceDatabaseException; 036import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 037import com.echothree.util.common.exception.PersistenceNotNullException; 038import com.echothree.util.server.persistence.BaseFactory; 039import com.echothree.util.server.persistence.EntityIdGenerator; 040import com.echothree.util.server.persistence.EntityPermission; 041import com.echothree.util.server.persistence.PersistenceDebugFlags; 042import com.echothree.util.server.persistence.Session; 043import com.echothree.util.server.persistence.ThreadSession; 044import java.sql.PreparedStatement; 045import java.sql.ResultSet; 046import java.sql.SQLException; 047import java.sql.Types; 048import java.io.ByteArrayInputStream; 049import java.io.StringReader; 050import java.util.ArrayList; 051import java.util.Collection; 052import java.util.HashSet; 053import java.util.List; 054import java.util.Map; 055import java.util.Set; 056import org.apache.commons.logging.Log; 057import org.apache.commons.logging.LogFactory; 058 059public class IconDetailFactory 060 implements BaseFactory<IconDetailPK, IconDetail> { 061 062 //final private static Log log = LogFactory.getLog(IconDetailFactory.class); 063 064 final private static String SQL_SELECT_READ_ONLY = "SELECT icndt_icondetailid, icndt_icn_iconid, icndt_iconname, icndt_dcmnt_documentid, icndt_isdefault, icndt_sortorder, icndt_fromtime, icndt_thrutime FROM icondetails WHERE icndt_icondetailid = ?"; 065 final private static String SQL_SELECT_READ_WRITE = "SELECT icndt_icondetailid, icndt_icn_iconid, icndt_iconname, icndt_dcmnt_documentid, icndt_isdefault, icndt_sortorder, icndt_fromtime, icndt_thrutime FROM icondetails WHERE icndt_icondetailid = ? FOR UPDATE"; 066 final private static String SQL_INSERT = "INSERT INTO icondetails (icndt_icondetailid, icndt_icn_iconid, icndt_iconname, icndt_dcmnt_documentid, icndt_isdefault, icndt_sortorder, icndt_fromtime, icndt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; 067 final private static String SQL_UPDATE = "UPDATE icondetails SET icndt_icn_iconid = ?, icndt_iconname = ?, icndt_dcmnt_documentid = ?, icndt_isdefault = ?, icndt_sortorder = ?, icndt_fromtime = ?, icndt_thrutime = ? WHERE icndt_icondetailid = ?"; 068 final private static String SQL_DELETE = "DELETE FROM icondetails WHERE icndt_icondetailid = ?"; 069 final private static String SQL_VALID = "SELECT COUNT(*) FROM icondetails WHERE icndt_icondetailid = ?"; 070 071 final private static String PK_COLUMN = "icndt_icondetailid"; 072 final private static String ALL_COLUMNS = "icndt_icondetailid, icndt_icn_iconid, icndt_iconname, icndt_dcmnt_documentid, icndt_isdefault, icndt_sortorder, icndt_fromtime, icndt_thrutime"; 073 final public static String TABLE_NAME = "icondetails"; 074 075 final public static String ICNDT_ICONDETAILID = "icndt_icondetailid"; 076 final public static String ICNDT_ICN_ICONID = "icndt_icn_iconid"; 077 final public static String ICNDT_ICONNAME = "icndt_iconname"; 078 final public static String ICNDT_DCMNT_DOCUMENTID = "icndt_dcmnt_documentid"; 079 final public static String ICNDT_ISDEFAULT = "icndt_isdefault"; 080 final public static String ICNDT_SORTORDER = "icndt_sortorder"; 081 final public static String ICNDT_FROMTIME = "icndt_fromtime"; 082 final public static String ICNDT_THRUTIME = "icndt_thrutime"; 083 084 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(IconDetailConstants.COMPONENT_VENDOR_NAME, IconDetailConstants.ENTITY_TYPE_NAME); 085 086 /** Creates a new instance of IconDetailFactory */ 087 private IconDetailFactory() { 088 super(); 089 } 090 091 private static class IconDetailFactoryHolder { 092 static IconDetailFactory instance = new IconDetailFactory(); 093 } 094 095 public static IconDetailFactory getInstance() { 096 return IconDetailFactoryHolder.instance; 097 } 098 099 @Override 100 public String getPKColumn() { 101 return PK_COLUMN; 102 } 103 104 @Override 105 public String getAllColumns() { 106 return ALL_COLUMNS; 107 } 108 109 @Override 110 public String getTableName() { 111 return TABLE_NAME; 112 } 113 114 @Override 115 public String getComponentVendorName() { 116 return IconDetailConstants.COMPONENT_VENDOR_NAME; 117 } 118 119 @Override 120 public String getEntityTypeName() { 121 return IconDetailConstants.ENTITY_TYPE_NAME; 122 } 123 124 public PreparedStatement prepareStatement(String query) { 125 return ThreadSession.currentSession().prepareStatement(IconDetailFactory.class, query); 126 } 127 128 public IconDetailPK getNextPK() { 129 return new IconDetailPK(entityIdGenerator.getNextEntityId()); 130 } 131 132 public Set<IconDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 133 throws PersistenceDatabaseException { 134 Set<IconDetailPK> _result = new HashSet<>(); 135 136 try { 137 while(rs.next()) { 138 _result.add(getPKFromResultSet(rs)); 139 } 140 } catch (SQLException se) { 141 throw new PersistenceDatabaseException(se); 142 } 143 144 return _result; 145 } 146 147 public java.util.List<IconDetailPK> getPKsFromResultSetAsList(ResultSet rs) 148 throws PersistenceDatabaseException { 149 java.util.List<IconDetailPK> _result = new ArrayList<>(); 150 151 try { 152 while(rs.next()) { 153 _result.add(getPKFromResultSet(rs)); 154 } 155 } catch (SQLException se) { 156 throw new PersistenceDatabaseException(se); 157 } 158 159 return _result; 160 } 161 162 public IconDetailPK getPKFromResultSet(ResultSet rs) 163 throws PersistenceDatabaseException { 164 IconDetailPK _result; 165 166 try { 167 long icndt_icondetailid = rs.getLong(ICNDT_ICONDETAILID); 168 Long _entityId = rs.wasNull() ? null : icndt_icondetailid; 169 170 _result = new IconDetailPK(_entityId); 171 } catch (SQLException se) { 172 throw new PersistenceDatabaseException(se); 173 } 174 175 return _result; 176 } 177 178 public java.util.List<IconDetailValue> getValuesFromPKs(Session session, Collection<IconDetailPK> pks) 179 throws PersistenceDatabaseException { 180 java.util.List<IconDetailValue> _values = new ArrayList<>(pks.size()); 181 182 for(IconDetailPK _pk: pks) { 183 _values.add(getValueFromPK(session, _pk)); 184 } 185 186 return _values; 187 } 188 189 public IconDetailValue getValueFromPK(Session session, IconDetailPK pk) 190 throws PersistenceDatabaseException { 191 IconDetailValue _value; 192 193 // See if we already have the entity in the session cache 194 IconDetail _entity = (IconDetail)session.getEntity(pk); 195 if(_entity == null) 196 _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getIconDetailValue(); 197 else 198 _value = _entity.getIconDetailValue(); 199 200 return _value; 201 } 202 203 public java.util.List<IconDetailValue> getValuesFromResultSet(Session session, ResultSet rs) 204 throws PersistenceDatabaseException { 205 java.util.List<IconDetailValue> _result = new ArrayList<>(); 206 207 try { 208 while(rs.next()) { 209 _result.add(getValueFromResultSet(session, rs)); 210 } 211 } catch (SQLException se) { 212 throw new PersistenceDatabaseException(se); 213 } 214 215 return _result; 216 } 217 218 public IconDetailValue getValueFromResultSet(Session session, ResultSet rs) 219 throws PersistenceDatabaseException { 220 IconDetailValue _value; 221 222 try { 223 Long icndt_icondetailid = rs.getLong(ICNDT_ICONDETAILID); 224 IconDetailPK _pk = new IconDetailPK(icndt_icondetailid); 225 226 // See if we already have the entity in the session cache 227 IconDetail _entity = (IconDetail)session.getEntity(_pk); 228 229 if(_entity == null) { 230 Long icndt_icn_iconid = rs.getLong(ICNDT_ICN_ICONID); 231 if(rs.wasNull()) 232 icndt_icn_iconid = null; 233 234 String icndt_iconname = rs.getString(ICNDT_ICONNAME); 235 if(rs.wasNull()) 236 icndt_iconname = null; 237 238 Long icndt_dcmnt_documentid = rs.getLong(ICNDT_DCMNT_DOCUMENTID); 239 if(rs.wasNull()) 240 icndt_dcmnt_documentid = null; 241 242 Boolean icndt_isdefault = rs.getInt(ICNDT_ISDEFAULT) == 1; 243 if(rs.wasNull()) 244 icndt_isdefault = null; 245 246 Integer icndt_sortorder = rs.getInt(ICNDT_SORTORDER); 247 if(rs.wasNull()) 248 icndt_sortorder = null; 249 250 Long icndt_fromtime = rs.getLong(ICNDT_FROMTIME); 251 if(rs.wasNull()) 252 icndt_fromtime = null; 253 254 Long icndt_thrutime = rs.getLong(ICNDT_THRUTIME); 255 if(rs.wasNull()) 256 icndt_thrutime = null; 257 258 _value = new IconDetailValue(_pk, new IconPK(icndt_icn_iconid), icndt_iconname, new DocumentPK(icndt_dcmnt_documentid), icndt_isdefault, icndt_sortorder, icndt_fromtime, icndt_thrutime); 259 } else 260 _value = _entity.getIconDetailValue(); 261 } catch (SQLException se) { 262 throw new PersistenceDatabaseException(se); 263 } 264 265 return _value; 266 } 267 268 public java.util.List<IconDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<IconDetailPK> pks) 269 throws PersistenceDatabaseException { 270 return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks); 271 } 272 273 public java.util.List<IconDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<IconDetailPK> pks) 274 throws PersistenceDatabaseException { 275 java.util.List<IconDetail> _entities = new ArrayList<>(pks.size()); 276 277 for(IconDetailPK _pk: pks) { 278 _entities.add(getEntityFromPK(session, entityPermission, _pk)); 279 } 280 281 return _entities; 282 } 283 284 public IconDetail getEntityFromValue(EntityPermission entityPermission, IconDetailValue value) { 285 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey()); 286 } 287 288 public IconDetail getEntityFromValue(Session session, EntityPermission entityPermission, IconDetailValue value) { 289 return getEntityFromPK(session, entityPermission, value.getPrimaryKey()); 290 } 291 292 public IconDetail getEntityFromPK(EntityPermission entityPermission, IconDetailPK pk) 293 throws PersistenceDatabaseException { 294 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk); 295 } 296 297 public IconDetail getEntityFromCache(Session session, IconDetailPK pk) { 298 IconDetailValue _value = (IconDetailValue)session.getValueCache().get(pk); 299 300 return _value == null ? null : new IconDetail(_value, EntityPermission.READ_ONLY); 301 } 302 303 public IconDetail getEntityFromPK(Session session, EntityPermission entityPermission, IconDetailPK pk) 304 throws PersistenceDatabaseException { 305 IconDetail _entity; 306 307 // See if we already have the entity in the session cache 308 _entity = (IconDetail)session.getEntity(pk); 309 if(_entity != null) { 310 // If the requested permission is READ_WRITE, and the cached permission is 311 // READ_ONLY, then pretend that the cached object wasn't found, and create 312 // a new entity that is READ_WRITE. 313 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 314 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 315 _entity = null; 316 } 317 } 318 319 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 320 _entity = getEntityFromCache(session, pk); 321 } 322 323 if(_entity == null) { 324 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 325 long _entityId = pk.getEntityId(); 326 ResultSet _rs = null; 327 328 try { 329 _ps.setLong(1, _entityId); 330 _rs = _ps.executeQuery(); 331 if(_rs.next()) { 332 _entity = getEntityFromResultSet(session, entityPermission, _rs); 333 } 334 } catch (SQLException se) { 335 throw new PersistenceDatabaseException(se); 336 } finally { 337 if(_rs != null) { 338 try { 339 _rs.close(); 340 } catch (SQLException se) { 341 // do nothing 342 } 343 } 344 } 345 } 346 347 return _entity; 348 } 349 350 public Set<IconDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 351 throws PersistenceDatabaseException { 352 Set<IconDetailPK> _pks; 353 ResultSet _rs = null; 354 355 try { 356 if(params.length != 0) { 357 Session.setQueryParams(ps, params); 358 } 359 360 _rs = ps.executeQuery(); 361 _pks = getPKsFromResultSetAsSet(_rs); 362 _rs.close(); 363 } catch (SQLException se) { 364 throw new PersistenceDatabaseException(se); 365 } finally { 366 if(_rs != null) { 367 try { 368 _rs.close(); 369 } catch (SQLException se) { 370 // do nothing 371 } 372 } 373 } 374 375 return _pks; 376 } 377 378 public java.util.List<IconDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 379 throws PersistenceDatabaseException { 380 java.util.List<IconDetailPK> _pks; 381 ResultSet _rs = null; 382 383 try { 384 if(params.length != 0) { 385 Session.setQueryParams(ps, params); 386 } 387 388 _rs = ps.executeQuery(); 389 _pks = getPKsFromResultSetAsList(_rs); 390 _rs.close(); 391 } catch (SQLException se) { 392 throw new PersistenceDatabaseException(se); 393 } finally { 394 if(_rs != null) { 395 try { 396 _rs.close(); 397 } catch (SQLException se) { 398 // do nothing 399 } 400 } 401 } 402 403 return _pks; 404 } 405 406 public IconDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 407 throws PersistenceDatabaseException { 408 IconDetailPK _pk = null; 409 ResultSet _rs = null; 410 411 try { 412 if(params.length != 0) { 413 Session.setQueryParams(ps, params); 414 } 415 416 _rs = ps.executeQuery(); 417 if(_rs.next()) { 418 _pk = getPKFromResultSet(_rs); 419 } 420 _rs.close(); 421 } catch (SQLException se) { 422 throw new PersistenceDatabaseException(se); 423 } finally { 424 if(_rs != null) { 425 try { 426 _rs.close(); 427 } catch (SQLException se) { 428 // do nothing 429 } 430 } 431 } 432 433 return _pk; 434 } 435 436 public java.util.List<IconDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 437 throws PersistenceDatabaseException { 438 PreparedStatement ps = session.prepareStatement(IconDetailFactory.class, queryMap.get(entityPermission)); 439 440 return getEntitiesFromQuery(session, entityPermission, ps, params); 441 } 442 443 public java.util.List<IconDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 444 throws PersistenceDatabaseException { 445 Session session = ThreadSession.currentSession(); 446 PreparedStatement ps = session.prepareStatement(IconDetailFactory.class, queryMap.get(entityPermission)); 447 448 return getEntitiesFromQuery(session, entityPermission, ps, params); 449 } 450 451 public java.util.List<IconDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 452 throws PersistenceDatabaseException { 453 PreparedStatement ps = session.prepareStatement(IconDetailFactory.class, queryMap.get(entityPermission)); 454 455 return getEntitiesFromQuery(session, entityPermission, ps); 456 } 457 458 public java.util.List<IconDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 459 throws PersistenceDatabaseException { 460 Session session = ThreadSession.currentSession(); 461 PreparedStatement ps = session.prepareStatement(IconDetailFactory.class, queryMap.get(entityPermission)); 462 463 return getEntitiesFromQuery(session, entityPermission, ps); 464 } 465 466 public java.util.List<IconDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps) 467 throws PersistenceDatabaseException { 468 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps); 469 } 470 471 public java.util.List<IconDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 472 throws PersistenceDatabaseException { 473 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 474 } 475 476 public java.util.List<IconDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 477 throws PersistenceDatabaseException { 478 java.util.List<IconDetail> _entities; 479 ResultSet _rs = null; 480 481 try { 482 if(params.length != 0) { 483 Session.setQueryParams(ps, params); 484 } 485 486 _rs = ps.executeQuery(); 487 _entities = getEntitiesFromResultSet(session, entityPermission, _rs); 488 _rs.close(); 489 } catch (SQLException se) { 490 throw new PersistenceDatabaseException(se); 491 } finally { 492 if(_rs != null) { 493 try { 494 _rs.close(); 495 } catch (SQLException se) { 496 // do nothing 497 } 498 } 499 } 500 501 return _entities; 502 } 503 504 public IconDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 505 throws PersistenceDatabaseException { 506 PreparedStatement ps = session.prepareStatement(IconDetailFactory.class, queryMap.get(entityPermission)); 507 508 return getEntityFromQuery(session, entityPermission, ps, params); 509 } 510 511 public IconDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 512 throws PersistenceDatabaseException { 513 Session session = ThreadSession.currentSession(); 514 PreparedStatement ps = session.prepareStatement(IconDetailFactory.class, queryMap.get(entityPermission)); 515 516 return getEntityFromQuery(session, entityPermission, ps, params); 517 } 518 519 public IconDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 520 throws PersistenceDatabaseException { 521 PreparedStatement ps = session.prepareStatement(IconDetailFactory.class, queryMap.get(entityPermission)); 522 523 return getEntityFromQuery(session, entityPermission, ps); 524 } 525 526 public IconDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 527 throws PersistenceDatabaseException { 528 Session session = ThreadSession.currentSession(); 529 PreparedStatement ps = session.prepareStatement(IconDetailFactory.class, queryMap.get(entityPermission)); 530 531 return getEntityFromQuery(session, entityPermission, ps); 532 } 533 534 public IconDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps) 535 throws PersistenceDatabaseException { 536 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps); 537 } 538 539 public IconDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 540 throws PersistenceDatabaseException { 541 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 542 } 543 544 public IconDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 545 throws PersistenceDatabaseException { 546 IconDetail _entity = null; 547 ResultSet _rs = null; 548 549 try { 550 if(params.length != 0) { 551 Session.setQueryParams(ps, params); 552 } 553 554 _rs = ps.executeQuery(); 555 if(_rs.next()) { 556 _entity = getEntityFromResultSet(session, entityPermission, _rs); 557 } 558 _rs.close(); 559 } catch (SQLException se) { 560 throw new PersistenceDatabaseException(se); 561 } finally { 562 if(_rs != null) { 563 try { 564 _rs.close(); 565 } catch (SQLException se) { 566 // do nothing 567 } 568 } 569 } 570 571 return _entity; 572 } 573 574 public java.util.List<IconDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 575 throws PersistenceDatabaseException { 576 return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 577 } 578 579 public java.util.List<IconDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 580 throws PersistenceDatabaseException { 581 java.util.List<IconDetail> _result = new ArrayList<>(); 582 583 try { 584 while(rs.next()) { 585 _result.add(getEntityFromResultSet(session, entityPermission, rs)); 586 } 587 } catch (SQLException se) { 588 throw new PersistenceDatabaseException(se); 589 } 590 591 return _result; 592 } 593 594 public IconDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 595 throws PersistenceDatabaseException { 596 return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 597 } 598 599 public IconDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 600 throws PersistenceDatabaseException { 601 IconDetail _entity; 602 603 try { 604 Long icndt_icondetailid = rs.getLong(ICNDT_ICONDETAILID); 605 IconDetailPK _pk = new IconDetailPK(icndt_icondetailid); 606 607 // See if we already have the entity in the session cache 608 _entity = (IconDetail)session.getEntity(_pk); 609 if(_entity != null) { 610 // If the requested permission is READ_WRITE, and the cached permission is 611 // READ_ONLY, then pretend that the cached object wasn't found, and create 612 // a new entity that is READ_WRITE. 613 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 614 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 615 _entity = null; 616 } 617 } 618 boolean foundInSessionCache = _entity != null; 619 620 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 621 _entity = getEntityFromCache(session, _pk); 622 } 623 624 if(_entity == null) { 625 Long icndt_icn_iconid = rs.getLong(ICNDT_ICN_ICONID); 626 if(rs.wasNull()) 627 icndt_icn_iconid = null; 628 629 String icndt_iconname = rs.getString(ICNDT_ICONNAME); 630 if(rs.wasNull()) 631 icndt_iconname = null; 632 633 Long icndt_dcmnt_documentid = rs.getLong(ICNDT_DCMNT_DOCUMENTID); 634 if(rs.wasNull()) 635 icndt_dcmnt_documentid = null; 636 637 Boolean icndt_isdefault = rs.getInt(ICNDT_ISDEFAULT) == 1; 638 if(rs.wasNull()) 639 icndt_isdefault = null; 640 641 Integer icndt_sortorder = rs.getInt(ICNDT_SORTORDER); 642 if(rs.wasNull()) 643 icndt_sortorder = null; 644 645 Long icndt_fromtime = rs.getLong(ICNDT_FROMTIME); 646 if(rs.wasNull()) 647 icndt_fromtime = null; 648 649 Long icndt_thrutime = rs.getLong(ICNDT_THRUTIME); 650 if(rs.wasNull()) 651 icndt_thrutime = null; 652 653 IconDetailValue _value = new IconDetailValue(_pk, icndt_icn_iconid == null? null: new IconPK(icndt_icn_iconid), icndt_iconname, icndt_dcmnt_documentid == null? null: new DocumentPK(icndt_dcmnt_documentid), icndt_isdefault, icndt_sortorder, icndt_fromtime, icndt_thrutime); 654 _entity = new IconDetail(_value, entityPermission); 655 } 656 657 if(!foundInSessionCache) { 658 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 659 session.putReadOnlyEntity(_pk, _entity); 660 session.getValueCache().put(_entity.getIconDetailValue()); 661 } else { 662 session.putReadWriteEntity(_pk, _entity); 663 } 664 } 665 } catch (SQLException se) { 666 throw new PersistenceDatabaseException(se); 667 } 668 669 return _entity; 670 } 671 672 public IconDetail create(Session session, Icon icon, String iconName, Document document, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 673 throws PersistenceDatabaseException, PersistenceNotNullException { 674 return create(session, icon == null ? null : icon.getPrimaryKey(), iconName, document == null ? null : document.getPrimaryKey(), isDefault, sortOrder, fromTime, thruTime); 675 } 676 677 public IconDetail create(Icon icon, String iconName, Document document, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 678 throws PersistenceDatabaseException, PersistenceNotNullException { 679 return create(ThreadSession.currentSession(), icon == null ? null : icon.getPrimaryKey(), iconName, document == null ? null : document.getPrimaryKey(), isDefault, sortOrder, fromTime, thruTime); 680 } 681 682 private void bindForCreate(PreparedStatement _ps, IconDetailValue _value) 683 throws SQLException { 684 _ps.setLong(1, _value.getEntityId()); 685 686 IconPK icndt_icn_iconid = _value.getIconPK(); 687 if(icndt_icn_iconid == null) 688 _ps.setNull(2, Types.BIGINT); 689 else 690 _ps.setLong(2, icndt_icn_iconid.getEntityId()); 691 692 String icndt_iconname = _value.getIconName(); 693 if(icndt_iconname == null) 694 _ps.setNull(3, Types.VARCHAR); 695 else 696 _ps.setString(3, icndt_iconname); 697 698 DocumentPK icndt_dcmnt_documentid = _value.getDocumentPK(); 699 if(icndt_dcmnt_documentid == null) 700 _ps.setNull(4, Types.BIGINT); 701 else 702 _ps.setLong(4, icndt_dcmnt_documentid.getEntityId()); 703 704 Boolean icndt_isdefault = _value.getIsDefault(); 705 if(icndt_isdefault == null) 706 _ps.setNull(5, Types.BIT); 707 else 708 _ps.setInt(5, icndt_isdefault? 1: 0); 709 710 Integer icndt_sortorder = _value.getSortOrder(); 711 if(icndt_sortorder == null) 712 _ps.setNull(6, Types.INTEGER); 713 else 714 _ps.setInt(6, icndt_sortorder); 715 716 Long icndt_fromtime = _value.getFromTime(); 717 if(icndt_fromtime == null) 718 _ps.setNull(7, Types.BIGINT); 719 else 720 _ps.setLong(7, icndt_fromtime); 721 722 Long icndt_thrutime = _value.getThruTime(); 723 if(icndt_thrutime == null) 724 _ps.setNull(8, Types.BIGINT); 725 else 726 _ps.setLong(8, icndt_thrutime); 727 728 } 729 730 public IconDetail create(Session session, IconPK iconPK, String iconName, DocumentPK documentPK, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 731 throws PersistenceDatabaseException, PersistenceNotNullException { 732 IconDetailPK _pk = getNextPK(); 733 IconDetailValue _value = new IconDetailValue(_pk, iconPK, iconName, documentPK, isDefault, sortOrder, fromTime, thruTime); 734 735 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 736 737 try { 738 bindForCreate(_ps, _value); 739 740 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 741 int _count = _ps.executeUpdate(); 742 743 if(_count != 1) { 744 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 745 } 746 } else { 747 _ps.executeUpdate(); 748 } 749 750 session.getValueCache().put(_value); 751 } catch (SQLException se) { 752 throw new PersistenceDatabaseException(se); 753 } 754 755 IconDetail _entity = new IconDetail(_value, EntityPermission.READ_ONLY); 756 session.putReadOnlyEntity(_pk, _entity); 757 758 return _entity; 759 } 760 761 public IconDetail create(IconPK iconPK, String iconName, DocumentPK documentPK, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 762 throws PersistenceDatabaseException, PersistenceNotNullException { 763 return create(ThreadSession.currentSession(), iconPK, iconName, documentPK, isDefault, sortOrder, fromTime, thruTime); 764 } 765 766 public void create(Session session, Collection<IconDetailValue> _values) 767 throws PersistenceDatabaseException, PersistenceNotNullException { 768 int _size = _values.size(); 769 770 if(_size > 0) { 771 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 772 List<IconDetailValue> _cacheValues = new ArrayList<>(_size); 773 774 try { 775 for(IconDetailValue _value : _values) { 776 _value.setEntityId(entityIdGenerator.getNextEntityId()); 777 bindForCreate(_ps, _value); 778 779 _ps.addBatch(); 780 781 _cacheValues.add(_value); 782 } 783 784 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 785 int[] _counts = _ps.executeBatch(); 786 787 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 788 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 789 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 790 } 791 } 792 } else { 793 _ps.executeBatch(); 794 } 795 796 _ps.clearBatch(); 797 } catch (SQLException se) { 798 throw new PersistenceDatabaseException(se); 799 } 800 801 _cacheValues.forEach((_cacheValue) -> { 802 IconDetail _cacheEntity = new IconDetail(_cacheValue, EntityPermission.READ_ONLY); 803 804 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 805 }); 806 } 807 } 808 809 public void create(Collection<IconDetailValue> _values) 810 throws PersistenceDatabaseException, PersistenceNotNullException { 811 create(ThreadSession.currentSession(), _values); 812 } 813 814 private boolean bindForStore(PreparedStatement _ps, IconDetailValue _value) 815 throws SQLException { 816 boolean _hasBeenModified = _value.hasBeenModified(); 817 818 if(_hasBeenModified) { 819 IconPK icndt_icn_iconid = _value.getIconPK(); 820 if(icndt_icn_iconid == null) 821 _ps.setNull(1, Types.BIGINT); 822 else 823 _ps.setLong(1, icndt_icn_iconid.getEntityId()); 824 825 String icndt_iconname = _value.getIconName(); 826 if(icndt_iconname == null) 827 _ps.setNull(2, Types.VARCHAR); 828 else 829 _ps.setString(2, icndt_iconname); 830 831 DocumentPK icndt_dcmnt_documentid = _value.getDocumentPK(); 832 if(icndt_dcmnt_documentid == null) 833 _ps.setNull(3, Types.BIGINT); 834 else 835 _ps.setLong(3, icndt_dcmnt_documentid.getEntityId()); 836 837 Boolean icndt_isdefault = _value.getIsDefault(); 838 if(icndt_isdefault == null) 839 _ps.setNull(4, Types.BIT); 840 else 841 _ps.setInt(4, icndt_isdefault? 1: 0); 842 843 Integer icndt_sortorder = _value.getSortOrder(); 844 if(icndt_sortorder == null) 845 _ps.setNull(5, Types.INTEGER); 846 else 847 _ps.setInt(5, icndt_sortorder); 848 849 Long icndt_fromtime = _value.getFromTime(); 850 if(icndt_fromtime == null) 851 _ps.setNull(6, Types.BIGINT); 852 else 853 _ps.setLong(6, icndt_fromtime); 854 855 Long icndt_thrutime = _value.getThruTime(); 856 if(icndt_thrutime == null) 857 _ps.setNull(7, Types.BIGINT); 858 else 859 _ps.setLong(7, icndt_thrutime); 860 861 _ps.setLong(8, _value.getPrimaryKey().getEntityId()); 862 863 _value.clearHasBeenModified(); 864 } 865 866 return _hasBeenModified; 867 } 868 869 @Override 870 public void store(Session session, IconDetail entity) 871 throws PersistenceDatabaseException { 872 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 873 874 try { 875 IconDetailValue _value = entity.getIconDetailValue(); 876 877 if(bindForStore(_ps, _value)) { 878 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 879 int _count = _ps.executeUpdate(); 880 881 if(_count != 1) { 882 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 883 } 884 } else { 885 _ps.executeUpdate(); 886 } 887 888 session.getValueCache().put(_value); 889 } 890 } catch (SQLException se) { 891 throw new PersistenceDatabaseException(se); 892 } 893 } 894 895 @Override 896 public void store(Session session, Collection<IconDetail> entities) 897 throws PersistenceDatabaseException { 898 if(entities.size() > 0) { 899 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 900 int _modifiedEntities = 0; 901 902 try { 903 for(IconDetail entity : entities) { 904 if(bindForStore(_ps, entity.getIconDetailValue())) { 905 _ps.addBatch(); 906 _modifiedEntities++; 907 } 908 } 909 910 if(_modifiedEntities != 0) { 911 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 912 int[] _counts = _ps.executeBatch(); 913 914 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 915 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 916 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 917 } 918 } 919 } else { 920 _ps.executeBatch(); 921 } 922 923 _ps.clearBatch(); 924 925 entities.forEach((entity) -> { 926 session.getValueCache().put(entity.getIconDetailValue()); 927 }); 928 } 929 } catch (SQLException se) { 930 throw new PersistenceDatabaseException(se); 931 } 932 } 933 } 934 935 @Override 936 public void store(Collection<IconDetail> entities) 937 throws PersistenceDatabaseException { 938 store(ThreadSession.currentSession(), entities); 939 } 940 941 @Override 942 public void remove(Session session, IconDetail entity) 943 throws PersistenceDatabaseException { 944 remove(session, entity.getPrimaryKey()); 945 } 946 947 @Override 948 public void remove(Session session, IconDetailPK pk) 949 throws PersistenceDatabaseException { 950 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 951 long _entityId = pk.getEntityId(); 952 953 try { 954 _ps.setLong(1, _entityId); 955 956 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 957 int _count = _ps.executeUpdate(); 958 959 if(_count != 1) { 960 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 961 } 962 } else { 963 _ps.executeUpdate(); 964 } 965 966 session.getValueCache().remove(pk); 967 } catch (SQLException se) { 968 throw new PersistenceDatabaseException(se); 969 } 970 971 session.removed(pk, false); 972 } 973 974 @Override 975 public void remove(Session session, Collection<IconDetailPK> pks) 976 throws PersistenceDatabaseException { 977 if(pks.size() > 0) { 978 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 979 int _modifiedEntities = 0; 980 981 try { 982 for(IconDetailPK pk : pks) { 983 long _entityId = pk.getEntityId(); 984 985 _ps.setLong(1, _entityId); 986 987 _ps.addBatch(); 988 _modifiedEntities++; 989 } 990 991 if(_modifiedEntities != 0) { 992 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 993 int[] _counts = _ps.executeBatch(); 994 995 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 996 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 997 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 998 } 999 } 1000 } else { 1001 _ps.executeBatch(); 1002 } 1003 1004 _ps.clearBatch(); 1005 1006 pks.forEach((pk) -> { 1007 session.getValueCache().remove(pk); 1008 }); 1009 } 1010 } catch (SQLException se) { 1011 throw new PersistenceDatabaseException(se); 1012 } 1013 1014 pks.forEach((pk) -> { 1015 session.removed(pk, true); 1016 }); 1017 } 1018 } 1019 1020 @Override 1021 public void remove(Collection<IconDetailPK> pks) 1022 throws PersistenceDatabaseException { 1023 remove(ThreadSession.currentSession(), pks); 1024 } 1025 1026 @Override 1027 public boolean validPK(Session session, IconDetailPK pk) 1028 throws PersistenceDatabaseException { 1029 boolean valid = false; 1030 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1031 ResultSet _rs = null; 1032 1033 try { 1034 _ps.setLong(1, pk.getEntityId()); 1035 1036 _rs = _ps.executeQuery(); 1037 if(_rs.next()) { 1038 long _count = _rs.getLong(1); 1039 if(_rs.wasNull()) 1040 _count = 0; 1041 1042 if(_count == 1) 1043 valid = true; 1044 } 1045 } catch (SQLException se) { 1046 throw new PersistenceDatabaseException(se); 1047 } finally { 1048 if(_rs != null) { 1049 try { 1050 _rs.close(); 1051 } catch (SQLException se) { 1052 // do nothing 1053 } 1054 } 1055 } 1056 1057 return valid; 1058 } 1059 1060}