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