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