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