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