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