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