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 * ItemDescriptionDetailFactory.java 021 */ 022 023package com.echothree.model.data.item.server.factory; 024 025import com.echothree.model.data.item.common.pk.ItemDescriptionPK; 026import com.echothree.model.data.item.common.pk.ItemDescriptionTypePK; 027import com.echothree.model.data.item.common.pk.ItemPK; 028import com.echothree.model.data.party.common.pk.LanguagePK; 029import com.echothree.model.data.core.common.pk.MimeTypePK; 030 031import com.echothree.model.data.item.server.entity.ItemDescription; 032import com.echothree.model.data.item.server.entity.ItemDescriptionType; 033import com.echothree.model.data.item.server.entity.Item; 034import com.echothree.model.data.party.server.entity.Language; 035import com.echothree.model.data.core.server.entity.MimeType; 036 037import com.echothree.model.data.item.common.ItemDescriptionDetailConstants; 038import com.echothree.model.data.item.common.pk.ItemDescriptionDetailPK; 039import com.echothree.model.data.item.server.value.ItemDescriptionDetailValue; 040import com.echothree.model.data.item.server.entity.ItemDescriptionDetail; 041import com.echothree.util.common.exception.PersistenceDatabaseException; 042import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 043import com.echothree.util.common.exception.PersistenceNotNullException; 044import com.echothree.util.server.persistence.BaseFactory; 045import com.echothree.util.server.persistence.EntityIdGenerator; 046import com.echothree.util.server.persistence.EntityPermission; 047import com.echothree.util.server.persistence.PersistenceDebugFlags; 048import com.echothree.util.server.persistence.Session; 049import java.sql.PreparedStatement; 050import java.sql.ResultSet; 051import java.sql.SQLException; 052import java.sql.Types; 053import java.io.ByteArrayInputStream; 054import java.io.StringReader; 055import java.util.ArrayList; 056import java.util.Collection; 057import java.util.HashSet; 058import java.util.List; 059import java.util.Map; 060import java.util.Set; 061import javax.enterprise.context.ApplicationScoped; 062import javax.enterprise.inject.spi.CDI; 063import javax.inject.Inject; 064import org.jooq.ResultQuery; 065import org.slf4j.Logger; 066import org.slf4j.LoggerFactory; 067 068@ApplicationScoped 069public class ItemDescriptionDetailFactory 070 implements BaseFactory<ItemDescriptionDetailPK, ItemDescriptionDetail> { 071 072 @Inject 073 Session session; 074 075 //private static final Logger log = LoggerFactory.getLogger(ItemDescriptionDetailFactory.class); 076 077 final private static String SQL_SELECT_READ_ONLY = "SELECT idescdt_itemdescriptiondetailid, idescdt_idesc_itemdescriptionid, idescdt_idt_itemdescriptiontypeid, idescdt_itm_itemid, idescdt_lang_languageid, idescdt_mtyp_mimetypeid, idescdt_fromtime, idescdt_thrutime FROM itemdescriptiondetails WHERE idescdt_itemdescriptiondetailid = ?"; 078 final private static String SQL_SELECT_READ_WRITE = "SELECT idescdt_itemdescriptiondetailid, idescdt_idesc_itemdescriptionid, idescdt_idt_itemdescriptiontypeid, idescdt_itm_itemid, idescdt_lang_languageid, idescdt_mtyp_mimetypeid, idescdt_fromtime, idescdt_thrutime FROM itemdescriptiondetails WHERE idescdt_itemdescriptiondetailid = ? FOR UPDATE"; 079 final private static String SQL_INSERT = "INSERT INTO itemdescriptiondetails (idescdt_itemdescriptiondetailid, idescdt_idesc_itemdescriptionid, idescdt_idt_itemdescriptiontypeid, idescdt_itm_itemid, idescdt_lang_languageid, idescdt_mtyp_mimetypeid, idescdt_fromtime, idescdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; 080 final private static String SQL_UPDATE = "UPDATE itemdescriptiondetails SET idescdt_idesc_itemdescriptionid = ?, idescdt_idt_itemdescriptiontypeid = ?, idescdt_itm_itemid = ?, idescdt_lang_languageid = ?, idescdt_mtyp_mimetypeid = ?, idescdt_fromtime = ?, idescdt_thrutime = ? WHERE idescdt_itemdescriptiondetailid = ?"; 081 final private static String SQL_DELETE = "DELETE FROM itemdescriptiondetails WHERE idescdt_itemdescriptiondetailid = ?"; 082 final private static String SQL_VALID = "SELECT COUNT(*) FROM itemdescriptiondetails WHERE idescdt_itemdescriptiondetailid = ?"; 083 084 final public static String IDESCDT_ITEMDESCRIPTIONDETAILID = "idescdt_itemdescriptiondetailid"; 085 final public static String IDESCDT_IDESC_ITEMDESCRIPTIONID = "idescdt_idesc_itemdescriptionid"; 086 final public static String IDESCDT_IDT_ITEMDESCRIPTIONTYPEID = "idescdt_idt_itemdescriptiontypeid"; 087 final public static String IDESCDT_ITM_ITEMID = "idescdt_itm_itemid"; 088 final public static String IDESCDT_LANG_LANGUAGEID = "idescdt_lang_languageid"; 089 final public static String IDESCDT_MTYP_MIMETYPEID = "idescdt_mtyp_mimetypeid"; 090 final public static String IDESCDT_FROMTIME = "idescdt_fromtime"; 091 final public static String IDESCDT_THRUTIME = "idescdt_thrutime"; 092 093 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ItemDescriptionDetailConstants.COMPONENT_VENDOR_NAME, ItemDescriptionDetailConstants.ENTITY_TYPE_NAME); 094 095 /** Creates a new instance of ItemDescriptionDetailFactory */ 096 protected ItemDescriptionDetailFactory() { 097 super(); 098 } 099 100 public static ItemDescriptionDetailFactory getInstance() { 101 return CDI.current().select(ItemDescriptionDetailFactory.class).get(); 102 } 103 104 @Override 105 public String getComponentVendorName() { 106 return ItemDescriptionDetailConstants.COMPONENT_VENDOR_NAME; 107 } 108 109 @Override 110 public String getEntityTypeName() { 111 return ItemDescriptionDetailConstants.ENTITY_TYPE_NAME; 112 } 113 114 public PreparedStatement prepareStatement(String query) { 115 return session.prepareStatement(query); 116 } 117 118 public ItemDescriptionDetailPK getNextPK() { 119 return new ItemDescriptionDetailPK(entityIdGenerator.getNextEntityId()); 120 } 121 122 public Set<ItemDescriptionDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 123 throws PersistenceDatabaseException { 124 Set<ItemDescriptionDetailPK> _result = new HashSet<>(); 125 126 try { 127 while(rs.next()) { 128 _result.add(getPKFromResultSet(rs)); 129 } 130 } catch (SQLException se) { 131 throw new PersistenceDatabaseException(se); 132 } 133 134 return _result; 135 } 136 137 public java.util.List<ItemDescriptionDetailPK> getPKsFromResultSetAsList(ResultSet rs) 138 throws PersistenceDatabaseException { 139 java.util.List<ItemDescriptionDetailPK> _result = new ArrayList<>(); 140 141 try { 142 while(rs.next()) { 143 _result.add(getPKFromResultSet(rs)); 144 } 145 } catch (SQLException se) { 146 throw new PersistenceDatabaseException(se); 147 } 148 149 return _result; 150 } 151 152 public ItemDescriptionDetailPK getPKFromResultSet(ResultSet rs) 153 throws PersistenceDatabaseException { 154 ItemDescriptionDetailPK _result; 155 156 try { 157 long idescdt_itemdescriptiondetailid = rs.getLong(IDESCDT_ITEMDESCRIPTIONDETAILID); 158 Long _entityId = rs.wasNull() ? null : idescdt_itemdescriptiondetailid; 159 160 _result = new ItemDescriptionDetailPK(_entityId); 161 } catch (SQLException se) { 162 throw new PersistenceDatabaseException(se); 163 } 164 165 return _result; 166 } 167 168 public java.util.List<ItemDescriptionDetailValue> getValuesFromPKs(Collection<ItemDescriptionDetailPK> pks) 169 throws PersistenceDatabaseException { 170 java.util.List<ItemDescriptionDetailValue> _values = new ArrayList<>(pks.size()); 171 172 for(ItemDescriptionDetailPK _pk: pks) { 173 _values.add(getValueFromPK(_pk)); 174 } 175 176 return _values; 177 } 178 179 public ItemDescriptionDetailValue getValueFromPK(ItemDescriptionDetailPK pk) 180 throws PersistenceDatabaseException { 181 ItemDescriptionDetailValue _value; 182 183 // See if we already have the entity in the session cache 184 ItemDescriptionDetail _entity = (ItemDescriptionDetail)session.getEntity(pk); 185 if(_entity == null) 186 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getItemDescriptionDetailValue(); 187 else 188 _value = _entity.getItemDescriptionDetailValue(); 189 190 return _value; 191 } 192 193 public java.util.List<ItemDescriptionDetailValue> getValuesFromResultSet(ResultSet rs) 194 throws PersistenceDatabaseException { 195 java.util.List<ItemDescriptionDetailValue> _result = new ArrayList<>(); 196 197 try { 198 while(rs.next()) { 199 _result.add(getValueFromResultSet(rs)); 200 } 201 } catch (SQLException se) { 202 throw new PersistenceDatabaseException(se); 203 } 204 205 return _result; 206 } 207 208 public ItemDescriptionDetailValue getValueFromResultSet(ResultSet rs) 209 throws PersistenceDatabaseException { 210 ItemDescriptionDetailValue _value; 211 212 try { 213 Long idescdt_itemdescriptiondetailid = rs.getLong(IDESCDT_ITEMDESCRIPTIONDETAILID); 214 ItemDescriptionDetailPK _pk = new ItemDescriptionDetailPK(idescdt_itemdescriptiondetailid); 215 216 // See if we already have the entity in the session cache 217 ItemDescriptionDetail _entity = (ItemDescriptionDetail)session.getEntity(_pk); 218 219 if(_entity == null) { 220 Long idescdt_idesc_itemdescriptionid = rs.getLong(IDESCDT_IDESC_ITEMDESCRIPTIONID); 221 if(rs.wasNull()) 222 idescdt_idesc_itemdescriptionid = null; 223 224 Long idescdt_idt_itemdescriptiontypeid = rs.getLong(IDESCDT_IDT_ITEMDESCRIPTIONTYPEID); 225 if(rs.wasNull()) 226 idescdt_idt_itemdescriptiontypeid = null; 227 228 Long idescdt_itm_itemid = rs.getLong(IDESCDT_ITM_ITEMID); 229 if(rs.wasNull()) 230 idescdt_itm_itemid = null; 231 232 Long idescdt_lang_languageid = rs.getLong(IDESCDT_LANG_LANGUAGEID); 233 if(rs.wasNull()) 234 idescdt_lang_languageid = null; 235 236 Long idescdt_mtyp_mimetypeid = rs.getLong(IDESCDT_MTYP_MIMETYPEID); 237 if(rs.wasNull()) 238 idescdt_mtyp_mimetypeid = null; 239 240 Long idescdt_fromtime = rs.getLong(IDESCDT_FROMTIME); 241 if(rs.wasNull()) 242 idescdt_fromtime = null; 243 244 Long idescdt_thrutime = rs.getLong(IDESCDT_THRUTIME); 245 if(rs.wasNull()) 246 idescdt_thrutime = null; 247 248 _value = new ItemDescriptionDetailValue(_pk, new ItemDescriptionPK(idescdt_idesc_itemdescriptionid), new ItemDescriptionTypePK(idescdt_idt_itemdescriptiontypeid), new ItemPK(idescdt_itm_itemid), new LanguagePK(idescdt_lang_languageid), new MimeTypePK(idescdt_mtyp_mimetypeid), idescdt_fromtime, idescdt_thrutime); 249 } else 250 _value = _entity.getItemDescriptionDetailValue(); 251 } catch (SQLException se) { 252 throw new PersistenceDatabaseException(se); 253 } 254 255 return _value; 256 } 257 258 public java.util.List<ItemDescriptionDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ItemDescriptionDetailPK> pks) 259 throws PersistenceDatabaseException { 260 java.util.List<ItemDescriptionDetail> _entities = new ArrayList<>(pks.size()); 261 262 for(ItemDescriptionDetailPK _pk: pks) { 263 _entities.add(getEntityFromPK(entityPermission, _pk)); 264 } 265 266 return _entities; 267 } 268 269 public ItemDescriptionDetail getEntityFromValue(EntityPermission entityPermission, ItemDescriptionDetailValue value) { 270 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 271 } 272 273 public ItemDescriptionDetail getEntityFromCache(ItemDescriptionDetailPK pk) { 274 ItemDescriptionDetailValue _value = (ItemDescriptionDetailValue)session.getValueCache().get(pk); 275 276 return _value == null ? null : new ItemDescriptionDetail(_value, EntityPermission.READ_ONLY); 277 } 278 279 public ItemDescriptionDetail getEntityFromPK(EntityPermission entityPermission, ItemDescriptionDetailPK pk) 280 throws PersistenceDatabaseException { 281 ItemDescriptionDetail _entity; 282 283 // See if we already have the entity in the session cache 284 _entity = (ItemDescriptionDetail)session.getEntity(pk); 285 if(_entity != null) { 286 // If the requested permission is READ_WRITE, and the cached permission is 287 // READ_ONLY, then pretend that the cached object wasn't found, and create 288 // a new entity that is READ_WRITE. 289 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 290 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 291 _entity = null; 292 } 293 } 294 295 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 296 _entity = getEntityFromCache(pk); 297 } 298 299 if(_entity == null) { 300 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 301 long _entityId = pk.getEntityId(); 302 ResultSet _rs = null; 303 304 try { 305 _ps.setLong(1, _entityId); 306 _rs = _ps.executeQuery(); 307 if(_rs.next()) { 308 _entity = getEntityFromResultSet(entityPermission, _rs); 309 } 310 } catch (SQLException se) { 311 throw new PersistenceDatabaseException(se); 312 } finally { 313 if(_rs != null) { 314 try { 315 _rs.close(); 316 } catch (SQLException se) { 317 // do nothing 318 } 319 } 320 } 321 } 322 323 return _entity; 324 } 325 326 public Set<ItemDescriptionDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 327 throws PersistenceDatabaseException { 328 Set<ItemDescriptionDetailPK> _pks; 329 ResultSet _rs = null; 330 331 try { 332 if(params.length != 0) { 333 Session.setQueryParams(ps, params); 334 } 335 336 _rs = ps.executeQuery(); 337 _pks = getPKsFromResultSetAsSet(_rs); 338 _rs.close(); 339 } catch (SQLException se) { 340 throw new PersistenceDatabaseException(se); 341 } finally { 342 if(_rs != null) { 343 try { 344 _rs.close(); 345 } catch (SQLException se) { 346 // do nothing 347 } 348 } 349 } 350 351 return _pks; 352 } 353 354 public java.util.List<ItemDescriptionDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 355 throws PersistenceDatabaseException { 356 java.util.List<ItemDescriptionDetailPK> _pks; 357 ResultSet _rs = null; 358 359 try { 360 if(params.length != 0) { 361 Session.setQueryParams(ps, params); 362 } 363 364 _rs = ps.executeQuery(); 365 _pks = getPKsFromResultSetAsList(_rs); 366 _rs.close(); 367 } catch (SQLException se) { 368 throw new PersistenceDatabaseException(se); 369 } finally { 370 if(_rs != null) { 371 try { 372 _rs.close(); 373 } catch (SQLException se) { 374 // do nothing 375 } 376 } 377 } 378 379 return _pks; 380 } 381 382 public ItemDescriptionDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 383 throws PersistenceDatabaseException { 384 ItemDescriptionDetailPK _pk = null; 385 ResultSet _rs = null; 386 387 try { 388 if(params.length != 0) { 389 Session.setQueryParams(ps, params); 390 } 391 392 _rs = ps.executeQuery(); 393 if(_rs.next()) { 394 _pk = getPKFromResultSet(_rs); 395 } 396 _rs.close(); 397 } catch (SQLException se) { 398 throw new PersistenceDatabaseException(se); 399 } finally { 400 if(_rs != null) { 401 try { 402 _rs.close(); 403 } catch (SQLException se) { 404 // do nothing 405 } 406 } 407 } 408 409 return _pk; 410 } 411 412 public java.util.List<ItemDescriptionDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 413 throws PersistenceDatabaseException { 414 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 415 416 return getEntitiesFromQuery(entityPermission, ps, params); 417 } 418 419 public java.util.List<ItemDescriptionDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 420 throws PersistenceDatabaseException { 421 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 422 423 return getEntitiesFromQuery(entityPermission, ps); 424 } 425 426 public java.util.List<ItemDescriptionDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 427 throws PersistenceDatabaseException { 428 PreparedStatement ps = session.prepareStatement(query.getSQL()); 429 430 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 431 } 432 433 public java.util.List<ItemDescriptionDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 434 throws PersistenceDatabaseException { 435 java.util.List<ItemDescriptionDetail> _entities; 436 ResultSet _rs = null; 437 438 try { 439 if(params.length != 0) { 440 Session.setQueryParams(ps, params); 441 } 442 443 _rs = ps.executeQuery(); 444 _entities = getEntitiesFromResultSet(entityPermission, _rs); 445 _rs.close(); 446 } catch (SQLException se) { 447 throw new PersistenceDatabaseException(se); 448 } finally { 449 if(_rs != null) { 450 try { 451 _rs.close(); 452 } catch (SQLException se) { 453 // do nothing 454 } 455 } 456 } 457 458 return _entities; 459 } 460 461 public ItemDescriptionDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 462 throws PersistenceDatabaseException { 463 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 464 465 return getEntityFromQuery(entityPermission, ps, params); 466 } 467 468 public ItemDescriptionDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 469 throws PersistenceDatabaseException { 470 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 471 472 return getEntityFromQuery(entityPermission, ps); 473 } 474 475 public ItemDescriptionDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 476 throws PersistenceDatabaseException { 477 PreparedStatement ps = session.prepareStatement(query.getSQL()); 478 479 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 480 } 481 482 public ItemDescriptionDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 483 throws PersistenceDatabaseException { 484 ItemDescriptionDetail _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<ItemDescriptionDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 513 throws PersistenceDatabaseException { 514 java.util.List<ItemDescriptionDetail> _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 ItemDescriptionDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 528 throws PersistenceDatabaseException { 529 ItemDescriptionDetail _entity; 530 531 try { 532 Long idescdt_itemdescriptiondetailid = rs.getLong(IDESCDT_ITEMDESCRIPTIONDETAILID); 533 ItemDescriptionDetailPK _pk = new ItemDescriptionDetailPK(idescdt_itemdescriptiondetailid); 534 535 // See if we already have the entity in the session cache 536 _entity = (ItemDescriptionDetail)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 idescdt_idesc_itemdescriptionid = rs.getLong(IDESCDT_IDESC_ITEMDESCRIPTIONID); 554 if(rs.wasNull()) 555 idescdt_idesc_itemdescriptionid = null; 556 557 Long idescdt_idt_itemdescriptiontypeid = rs.getLong(IDESCDT_IDT_ITEMDESCRIPTIONTYPEID); 558 if(rs.wasNull()) 559 idescdt_idt_itemdescriptiontypeid = null; 560 561 Long idescdt_itm_itemid = rs.getLong(IDESCDT_ITM_ITEMID); 562 if(rs.wasNull()) 563 idescdt_itm_itemid = null; 564 565 Long idescdt_lang_languageid = rs.getLong(IDESCDT_LANG_LANGUAGEID); 566 if(rs.wasNull()) 567 idescdt_lang_languageid = null; 568 569 Long idescdt_mtyp_mimetypeid = rs.getLong(IDESCDT_MTYP_MIMETYPEID); 570 if(rs.wasNull()) 571 idescdt_mtyp_mimetypeid = null; 572 573 Long idescdt_fromtime = rs.getLong(IDESCDT_FROMTIME); 574 if(rs.wasNull()) 575 idescdt_fromtime = null; 576 577 Long idescdt_thrutime = rs.getLong(IDESCDT_THRUTIME); 578 if(rs.wasNull()) 579 idescdt_thrutime = null; 580 581 ItemDescriptionDetailValue _value = new ItemDescriptionDetailValue(_pk, idescdt_idesc_itemdescriptionid == null? null: new ItemDescriptionPK(idescdt_idesc_itemdescriptionid), idescdt_idt_itemdescriptiontypeid == null? null: new ItemDescriptionTypePK(idescdt_idt_itemdescriptiontypeid), idescdt_itm_itemid == null? null: new ItemPK(idescdt_itm_itemid), idescdt_lang_languageid == null? null: new LanguagePK(idescdt_lang_languageid), idescdt_mtyp_mimetypeid == null? null: new MimeTypePK(idescdt_mtyp_mimetypeid), idescdt_fromtime, idescdt_thrutime); 582 _entity = new ItemDescriptionDetail(_value, entityPermission); 583 } 584 585 if(!foundInSessionCache) { 586 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 587 session.putReadOnlyEntity(_pk, _entity); 588 session.getValueCache().put(_entity.getItemDescriptionDetailValue()); 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 ItemDescriptionDetail create(ItemDescription itemDescription, ItemDescriptionType itemDescriptionType, Item item, Language language, MimeType mimeType, Long fromTime, Long thruTime) 601 throws PersistenceDatabaseException, PersistenceNotNullException { 602 return create(itemDescription == null ? null : itemDescription.getPrimaryKey(), itemDescriptionType == null ? null : itemDescriptionType.getPrimaryKey(), item == null ? null : item.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), mimeType == null ? null : mimeType.getPrimaryKey(), fromTime, thruTime); 603 } 604 605 private void bindForCreate(PreparedStatement _ps, ItemDescriptionDetailValue _value) 606 throws SQLException { 607 _ps.setLong(1, _value.getEntityId()); 608 609 ItemDescriptionPK idescdt_idesc_itemdescriptionid = _value.getItemDescriptionPK(); 610 if(idescdt_idesc_itemdescriptionid == null) 611 _ps.setNull(2, Types.BIGINT); 612 else 613 _ps.setLong(2, idescdt_idesc_itemdescriptionid.getEntityId()); 614 615 ItemDescriptionTypePK idescdt_idt_itemdescriptiontypeid = _value.getItemDescriptionTypePK(); 616 if(idescdt_idt_itemdescriptiontypeid == null) 617 _ps.setNull(3, Types.BIGINT); 618 else 619 _ps.setLong(3, idescdt_idt_itemdescriptiontypeid.getEntityId()); 620 621 ItemPK idescdt_itm_itemid = _value.getItemPK(); 622 if(idescdt_itm_itemid == null) 623 _ps.setNull(4, Types.BIGINT); 624 else 625 _ps.setLong(4, idescdt_itm_itemid.getEntityId()); 626 627 LanguagePK idescdt_lang_languageid = _value.getLanguagePK(); 628 if(idescdt_lang_languageid == null) 629 _ps.setNull(5, Types.BIGINT); 630 else 631 _ps.setLong(5, idescdt_lang_languageid.getEntityId()); 632 633 MimeTypePK idescdt_mtyp_mimetypeid = _value.getMimeTypePK(); 634 if(idescdt_mtyp_mimetypeid == null) 635 _ps.setNull(6, Types.BIGINT); 636 else 637 _ps.setLong(6, idescdt_mtyp_mimetypeid.getEntityId()); 638 639 Long idescdt_fromtime = _value.getFromTime(); 640 if(idescdt_fromtime == null) 641 _ps.setNull(7, Types.BIGINT); 642 else 643 _ps.setLong(7, idescdt_fromtime); 644 645 Long idescdt_thrutime = _value.getThruTime(); 646 if(idescdt_thrutime == null) 647 _ps.setNull(8, Types.BIGINT); 648 else 649 _ps.setLong(8, idescdt_thrutime); 650 651 } 652 653 public ItemDescriptionDetail create(ItemDescriptionPK itemDescriptionPK, ItemDescriptionTypePK itemDescriptionTypePK, ItemPK itemPK, LanguagePK languagePK, MimeTypePK mimeTypePK, Long fromTime, Long thruTime) 654 throws PersistenceDatabaseException, PersistenceNotNullException { 655 ItemDescriptionDetailPK _pk = getNextPK(); 656 ItemDescriptionDetailValue _value = new ItemDescriptionDetailValue(_pk, itemDescriptionPK, itemDescriptionTypePK, itemPK, languagePK, mimeTypePK, 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 ItemDescriptionDetail _entity = new ItemDescriptionDetail(_value, EntityPermission.READ_ONLY); 679 session.putReadOnlyEntity(_pk, _entity); 680 681 return _entity; 682 } 683 684 public void create(Collection<ItemDescriptionDetailValue> _values) 685 throws PersistenceDatabaseException, PersistenceNotNullException { 686 int _size = _values.size(); 687 688 if(_size > 0) { 689 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 690 List<ItemDescriptionDetailValue> _cacheValues = new ArrayList<>(_size); 691 692 try { 693 for(ItemDescriptionDetailValue _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 ItemDescriptionDetail _cacheEntity = new ItemDescriptionDetail(_cacheValue, EntityPermission.READ_ONLY); 721 722 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 723 }); 724 } 725 } 726 727 private boolean bindForStore(PreparedStatement _ps, ItemDescriptionDetailValue _value) 728 throws SQLException { 729 boolean _hasBeenModified = _value.hasBeenModified(); 730 731 if(_hasBeenModified) { 732 ItemDescriptionPK idescdt_idesc_itemdescriptionid = _value.getItemDescriptionPK(); 733 if(idescdt_idesc_itemdescriptionid == null) 734 _ps.setNull(1, Types.BIGINT); 735 else 736 _ps.setLong(1, idescdt_idesc_itemdescriptionid.getEntityId()); 737 738 ItemDescriptionTypePK idescdt_idt_itemdescriptiontypeid = _value.getItemDescriptionTypePK(); 739 if(idescdt_idt_itemdescriptiontypeid == null) 740 _ps.setNull(2, Types.BIGINT); 741 else 742 _ps.setLong(2, idescdt_idt_itemdescriptiontypeid.getEntityId()); 743 744 ItemPK idescdt_itm_itemid = _value.getItemPK(); 745 if(idescdt_itm_itemid == null) 746 _ps.setNull(3, Types.BIGINT); 747 else 748 _ps.setLong(3, idescdt_itm_itemid.getEntityId()); 749 750 LanguagePK idescdt_lang_languageid = _value.getLanguagePK(); 751 if(idescdt_lang_languageid == null) 752 _ps.setNull(4, Types.BIGINT); 753 else 754 _ps.setLong(4, idescdt_lang_languageid.getEntityId()); 755 756 MimeTypePK idescdt_mtyp_mimetypeid = _value.getMimeTypePK(); 757 if(idescdt_mtyp_mimetypeid == null) 758 _ps.setNull(5, Types.BIGINT); 759 else 760 _ps.setLong(5, idescdt_mtyp_mimetypeid.getEntityId()); 761 762 Long idescdt_fromtime = _value.getFromTime(); 763 if(idescdt_fromtime == null) 764 _ps.setNull(6, Types.BIGINT); 765 else 766 _ps.setLong(6, idescdt_fromtime); 767 768 Long idescdt_thrutime = _value.getThruTime(); 769 if(idescdt_thrutime == null) 770 _ps.setNull(7, Types.BIGINT); 771 else 772 _ps.setLong(7, idescdt_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(ItemDescriptionDetail entity) 784 throws PersistenceDatabaseException { 785 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 786 787 try { 788 ItemDescriptionDetailValue _value = entity.getItemDescriptionDetailValue(); 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<ItemDescriptionDetail> 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(ItemDescriptionDetail entity : entities) { 817 if(bindForStore(_ps, entity.getItemDescriptionDetailValue())) { 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.getItemDescriptionDetailValue()); 840 }); 841 } 842 } catch (SQLException se) { 843 throw new PersistenceDatabaseException(se); 844 } 845 } 846 } 847 848 @Override 849 public void remove(ItemDescriptionDetail entity) 850 throws PersistenceDatabaseException { 851 remove(entity.getPrimaryKey()); 852 } 853 854 @Override 855 public void remove(ItemDescriptionDetailPK 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<ItemDescriptionDetailPK> 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(ItemDescriptionDetailPK 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(ItemDescriptionDetailPK 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}