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