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