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