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