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