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