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