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