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 * CampaignTermDetailFactory.java 021 */ 022 023package com.echothree.model.data.campaign.server.factory; 024 025import com.echothree.model.data.campaign.common.pk.CampaignTermPK; 026 027import com.echothree.model.data.campaign.server.entity.CampaignTerm; 028 029import com.echothree.model.data.campaign.common.CampaignTermDetailConstants; 030import com.echothree.model.data.campaign.common.pk.CampaignTermDetailPK; 031import com.echothree.model.data.campaign.server.value.CampaignTermDetailValue; 032import com.echothree.model.data.campaign.server.entity.CampaignTermDetail; 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 CampaignTermDetailFactory 063 implements BaseFactory<CampaignTermDetailPK, CampaignTermDetail> { 064 065 @Inject 066 Session session; 067 068 //private static final Logger log = LoggerFactory.getLogger(CampaignTermDetailFactory.class); 069 070 final private static String SQL_SELECT_READ_ONLY = "SELECT cmpgntrmdt_campaigntermdetailid, cmpgntrmdt_cmpgntrm_campaigntermid, cmpgntrmdt_campaigntermname, cmpgntrmdt_valuesha1hash, cmpgntrmdt_value, cmpgntrmdt_isdefault, cmpgntrmdt_sortorder, cmpgntrmdt_fromtime, cmpgntrmdt_thrutime FROM campaigntermdetails WHERE cmpgntrmdt_campaigntermdetailid = ?"; 071 final private static String SQL_SELECT_READ_WRITE = "SELECT cmpgntrmdt_campaigntermdetailid, cmpgntrmdt_cmpgntrm_campaigntermid, cmpgntrmdt_campaigntermname, cmpgntrmdt_valuesha1hash, cmpgntrmdt_value, cmpgntrmdt_isdefault, cmpgntrmdt_sortorder, cmpgntrmdt_fromtime, cmpgntrmdt_thrutime FROM campaigntermdetails WHERE cmpgntrmdt_campaigntermdetailid = ? FOR UPDATE"; 072 final private static String SQL_INSERT = "INSERT INTO campaigntermdetails (cmpgntrmdt_campaigntermdetailid, cmpgntrmdt_cmpgntrm_campaigntermid, cmpgntrmdt_campaigntermname, cmpgntrmdt_valuesha1hash, cmpgntrmdt_value, cmpgntrmdt_isdefault, cmpgntrmdt_sortorder, cmpgntrmdt_fromtime, cmpgntrmdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; 073 final private static String SQL_UPDATE = "UPDATE campaigntermdetails SET cmpgntrmdt_cmpgntrm_campaigntermid = ?, cmpgntrmdt_campaigntermname = ?, cmpgntrmdt_valuesha1hash = ?, cmpgntrmdt_value = ?, cmpgntrmdt_isdefault = ?, cmpgntrmdt_sortorder = ?, cmpgntrmdt_fromtime = ?, cmpgntrmdt_thrutime = ? WHERE cmpgntrmdt_campaigntermdetailid = ?"; 074 final private static String SQL_DELETE = "DELETE FROM campaigntermdetails WHERE cmpgntrmdt_campaigntermdetailid = ?"; 075 final private static String SQL_VALID = "SELECT COUNT(*) FROM campaigntermdetails WHERE cmpgntrmdt_campaigntermdetailid = ?"; 076 077 final public static String CMPGNTRMDT_CAMPAIGNTERMDETAILID = "cmpgntrmdt_campaigntermdetailid"; 078 final public static String CMPGNTRMDT_CMPGNTRM_CAMPAIGNTERMID = "cmpgntrmdt_cmpgntrm_campaigntermid"; 079 final public static String CMPGNTRMDT_CAMPAIGNTERMNAME = "cmpgntrmdt_campaigntermname"; 080 final public static String CMPGNTRMDT_VALUESHA1HASH = "cmpgntrmdt_valuesha1hash"; 081 final public static String CMPGNTRMDT_VALUE = "cmpgntrmdt_value"; 082 final public static String CMPGNTRMDT_ISDEFAULT = "cmpgntrmdt_isdefault"; 083 final public static String CMPGNTRMDT_SORTORDER = "cmpgntrmdt_sortorder"; 084 final public static String CMPGNTRMDT_FROMTIME = "cmpgntrmdt_fromtime"; 085 final public static String CMPGNTRMDT_THRUTIME = "cmpgntrmdt_thrutime"; 086 087 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(CampaignTermDetailConstants.COMPONENT_VENDOR_NAME, CampaignTermDetailConstants.ENTITY_TYPE_NAME); 088 089 /** Creates a new instance of CampaignTermDetailFactory */ 090 protected CampaignTermDetailFactory() { 091 super(); 092 } 093 094 public static CampaignTermDetailFactory getInstance() { 095 return CDI.current().select(CampaignTermDetailFactory.class).get(); 096 } 097 098 @Override 099 public String getComponentVendorName() { 100 return CampaignTermDetailConstants.COMPONENT_VENDOR_NAME; 101 } 102 103 @Override 104 public String getEntityTypeName() { 105 return CampaignTermDetailConstants.ENTITY_TYPE_NAME; 106 } 107 108 public PreparedStatement prepareStatement(String query) { 109 return session.prepareStatement(query); 110 } 111 112 public CampaignTermDetailPK getNextPK() { 113 return new CampaignTermDetailPK(entityIdGenerator.getNextEntityId()); 114 } 115 116 public Set<CampaignTermDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 117 throws PersistenceDatabaseException { 118 Set<CampaignTermDetailPK> _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<CampaignTermDetailPK> getPKsFromResultSetAsList(ResultSet rs) 132 throws PersistenceDatabaseException { 133 java.util.List<CampaignTermDetailPK> _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 CampaignTermDetailPK getPKFromResultSet(ResultSet rs) 147 throws PersistenceDatabaseException { 148 CampaignTermDetailPK _result; 149 150 try { 151 long cmpgntrmdt_campaigntermdetailid = rs.getLong(CMPGNTRMDT_CAMPAIGNTERMDETAILID); 152 Long _entityId = rs.wasNull() ? null : cmpgntrmdt_campaigntermdetailid; 153 154 _result = new CampaignTermDetailPK(_entityId); 155 } catch (SQLException se) { 156 throw new PersistenceDatabaseException(se); 157 } 158 159 return _result; 160 } 161 162 public java.util.List<CampaignTermDetailValue> getValuesFromPKs(Collection<CampaignTermDetailPK> pks) 163 throws PersistenceDatabaseException { 164 java.util.List<CampaignTermDetailValue> _values = new ArrayList<>(pks.size()); 165 166 for(CampaignTermDetailPK _pk: pks) { 167 _values.add(getValueFromPK(_pk)); 168 } 169 170 return _values; 171 } 172 173 public CampaignTermDetailValue getValueFromPK(CampaignTermDetailPK pk) 174 throws PersistenceDatabaseException { 175 CampaignTermDetailValue _value; 176 177 // See if we already have the entity in the session cache 178 CampaignTermDetail _entity = (CampaignTermDetail)session.getEntity(pk); 179 if(_entity == null) 180 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getCampaignTermDetailValue(); 181 else 182 _value = _entity.getCampaignTermDetailValue(); 183 184 return _value; 185 } 186 187 public java.util.List<CampaignTermDetailValue> getValuesFromResultSet(ResultSet rs) 188 throws PersistenceDatabaseException { 189 java.util.List<CampaignTermDetailValue> _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 CampaignTermDetailValue getValueFromResultSet(ResultSet rs) 203 throws PersistenceDatabaseException { 204 CampaignTermDetailValue _value; 205 206 try { 207 Long cmpgntrmdt_campaigntermdetailid = rs.getLong(CMPGNTRMDT_CAMPAIGNTERMDETAILID); 208 CampaignTermDetailPK _pk = new CampaignTermDetailPK(cmpgntrmdt_campaigntermdetailid); 209 210 // See if we already have the entity in the session cache 211 CampaignTermDetail _entity = (CampaignTermDetail)session.getEntity(_pk); 212 213 if(_entity == null) { 214 Long cmpgntrmdt_cmpgntrm_campaigntermid = rs.getLong(CMPGNTRMDT_CMPGNTRM_CAMPAIGNTERMID); 215 if(rs.wasNull()) 216 cmpgntrmdt_cmpgntrm_campaigntermid = null; 217 218 String cmpgntrmdt_campaigntermname = rs.getString(CMPGNTRMDT_CAMPAIGNTERMNAME); 219 if(rs.wasNull()) 220 cmpgntrmdt_campaigntermname = null; 221 222 String cmpgntrmdt_valuesha1hash = rs.getString(CMPGNTRMDT_VALUESHA1HASH); 223 if(rs.wasNull()) 224 cmpgntrmdt_valuesha1hash = null; 225 226 Clob cmpgntrmdt_value = rs.getClob(CMPGNTRMDT_VALUE); 227 if(rs.wasNull()) 228 cmpgntrmdt_value = null; 229 230 Boolean cmpgntrmdt_isdefault = rs.getInt(CMPGNTRMDT_ISDEFAULT) == 1; 231 if(rs.wasNull()) 232 cmpgntrmdt_isdefault = null; 233 234 Integer cmpgntrmdt_sortorder = rs.getInt(CMPGNTRMDT_SORTORDER); 235 if(rs.wasNull()) 236 cmpgntrmdt_sortorder = null; 237 238 Long cmpgntrmdt_fromtime = rs.getLong(CMPGNTRMDT_FROMTIME); 239 if(rs.wasNull()) 240 cmpgntrmdt_fromtime = null; 241 242 Long cmpgntrmdt_thrutime = rs.getLong(CMPGNTRMDT_THRUTIME); 243 if(rs.wasNull()) 244 cmpgntrmdt_thrutime = null; 245 246 _value = new CampaignTermDetailValue(_pk, new CampaignTermPK(cmpgntrmdt_cmpgntrm_campaigntermid), cmpgntrmdt_campaigntermname, cmpgntrmdt_valuesha1hash, cmpgntrmdt_value == null? null: cmpgntrmdt_value.getSubString(1L, (int)cmpgntrmdt_value.length()), cmpgntrmdt_isdefault, cmpgntrmdt_sortorder, cmpgntrmdt_fromtime, cmpgntrmdt_thrutime); 247 } else 248 _value = _entity.getCampaignTermDetailValue(); 249 } catch (SQLException se) { 250 throw new PersistenceDatabaseException(se); 251 } 252 253 return _value; 254 } 255 256 public java.util.List<CampaignTermDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<CampaignTermDetailPK> pks) 257 throws PersistenceDatabaseException { 258 java.util.List<CampaignTermDetail> _entities = new ArrayList<>(pks.size()); 259 260 for(CampaignTermDetailPK _pk: pks) { 261 _entities.add(getEntityFromPK(entityPermission, _pk)); 262 } 263 264 return _entities; 265 } 266 267 public CampaignTermDetail getEntityFromValue(EntityPermission entityPermission, CampaignTermDetailValue value) { 268 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 269 } 270 271 public CampaignTermDetail getEntityFromCache(CampaignTermDetailPK pk) { 272 CampaignTermDetailValue _value = (CampaignTermDetailValue)session.getValueCache().get(pk); 273 274 return _value == null ? null : new CampaignTermDetail(_value, EntityPermission.READ_ONLY); 275 } 276 277 public CampaignTermDetail getEntityFromPK(EntityPermission entityPermission, CampaignTermDetailPK pk) 278 throws PersistenceDatabaseException { 279 CampaignTermDetail _entity; 280 281 // See if we already have the entity in the session cache 282 _entity = (CampaignTermDetail)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<CampaignTermDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 325 throws PersistenceDatabaseException { 326 Set<CampaignTermDetailPK> _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<CampaignTermDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 353 throws PersistenceDatabaseException { 354 java.util.List<CampaignTermDetailPK> _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 CampaignTermDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 381 throws PersistenceDatabaseException { 382 CampaignTermDetailPK _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<CampaignTermDetail> 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<CampaignTermDetail> 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<CampaignTermDetail> 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<CampaignTermDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 432 throws PersistenceDatabaseException { 433 java.util.List<CampaignTermDetail> _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 CampaignTermDetail 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 CampaignTermDetail 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 CampaignTermDetail 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 CampaignTermDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 481 throws PersistenceDatabaseException { 482 CampaignTermDetail _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<CampaignTermDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 511 throws PersistenceDatabaseException { 512 java.util.List<CampaignTermDetail> _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 CampaignTermDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 526 throws PersistenceDatabaseException { 527 CampaignTermDetail _entity; 528 529 try { 530 Long cmpgntrmdt_campaigntermdetailid = rs.getLong(CMPGNTRMDT_CAMPAIGNTERMDETAILID); 531 CampaignTermDetailPK _pk = new CampaignTermDetailPK(cmpgntrmdt_campaigntermdetailid); 532 533 // See if we already have the entity in the session cache 534 _entity = (CampaignTermDetail)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 cmpgntrmdt_cmpgntrm_campaigntermid = rs.getLong(CMPGNTRMDT_CMPGNTRM_CAMPAIGNTERMID); 552 if(rs.wasNull()) 553 cmpgntrmdt_cmpgntrm_campaigntermid = null; 554 555 String cmpgntrmdt_campaigntermname = rs.getString(CMPGNTRMDT_CAMPAIGNTERMNAME); 556 if(rs.wasNull()) 557 cmpgntrmdt_campaigntermname = null; 558 559 String cmpgntrmdt_valuesha1hash = rs.getString(CMPGNTRMDT_VALUESHA1HASH); 560 if(rs.wasNull()) 561 cmpgntrmdt_valuesha1hash = null; 562 563 Clob cmpgntrmdt_value = rs.getClob(CMPGNTRMDT_VALUE); 564 if(rs.wasNull()) 565 cmpgntrmdt_value = null; 566 567 Boolean cmpgntrmdt_isdefault = rs.getInt(CMPGNTRMDT_ISDEFAULT) == 1; 568 if(rs.wasNull()) 569 cmpgntrmdt_isdefault = null; 570 571 Integer cmpgntrmdt_sortorder = rs.getInt(CMPGNTRMDT_SORTORDER); 572 if(rs.wasNull()) 573 cmpgntrmdt_sortorder = null; 574 575 Long cmpgntrmdt_fromtime = rs.getLong(CMPGNTRMDT_FROMTIME); 576 if(rs.wasNull()) 577 cmpgntrmdt_fromtime = null; 578 579 Long cmpgntrmdt_thrutime = rs.getLong(CMPGNTRMDT_THRUTIME); 580 if(rs.wasNull()) 581 cmpgntrmdt_thrutime = null; 582 583 CampaignTermDetailValue _value = new CampaignTermDetailValue(_pk, cmpgntrmdt_cmpgntrm_campaigntermid == null? null: new CampaignTermPK(cmpgntrmdt_cmpgntrm_campaigntermid), cmpgntrmdt_campaigntermname, cmpgntrmdt_valuesha1hash, cmpgntrmdt_value == null? null: cmpgntrmdt_value.getSubString(1L, (int)cmpgntrmdt_value.length()), cmpgntrmdt_isdefault, cmpgntrmdt_sortorder, cmpgntrmdt_fromtime, cmpgntrmdt_thrutime); 584 _entity = new CampaignTermDetail(_value, entityPermission); 585 } 586 587 if(!foundInSessionCache) { 588 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 589 session.putReadOnlyEntity(_pk, _entity); 590 session.getValueCache().put(_entity.getCampaignTermDetailValue()); 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 CampaignTermDetail create(CampaignTerm campaignTerm, String campaignTermName, String valueSha1Hash, String value, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 603 throws PersistenceDatabaseException, PersistenceNotNullException { 604 return create(campaignTerm == null ? null : campaignTerm.getPrimaryKey(), campaignTermName, valueSha1Hash, value, isDefault, sortOrder, fromTime, thruTime); 605 } 606 607 private void bindForCreate(PreparedStatement _ps, CampaignTermDetailValue _value) 608 throws SQLException { 609 _ps.setLong(1, _value.getEntityId()); 610 611 CampaignTermPK cmpgntrmdt_cmpgntrm_campaigntermid = _value.getCampaignTermPK(); 612 if(cmpgntrmdt_cmpgntrm_campaigntermid == null) 613 _ps.setNull(2, Types.BIGINT); 614 else 615 _ps.setLong(2, cmpgntrmdt_cmpgntrm_campaigntermid.getEntityId()); 616 617 String cmpgntrmdt_campaigntermname = _value.getCampaignTermName(); 618 if(cmpgntrmdt_campaigntermname == null) 619 _ps.setNull(3, Types.VARCHAR); 620 else 621 _ps.setString(3, cmpgntrmdt_campaigntermname); 622 623 String cmpgntrmdt_valuesha1hash = _value.getValueSha1Hash(); 624 if(cmpgntrmdt_valuesha1hash == null) 625 _ps.setNull(4, Types.VARCHAR); 626 else 627 _ps.setString(4, cmpgntrmdt_valuesha1hash); 628 629 String cmpgntrmdt_value = _value.getValue(); 630 if(cmpgntrmdt_value == null) 631 _ps.setNull(5, Types.CLOB); 632 else 633 _ps.setCharacterStream(5, new StringReader(cmpgntrmdt_value), cmpgntrmdt_value.length()); 634 635 Boolean cmpgntrmdt_isdefault = _value.getIsDefault(); 636 if(cmpgntrmdt_isdefault == null) 637 _ps.setNull(6, Types.BIT); 638 else 639 _ps.setInt(6, cmpgntrmdt_isdefault? 1: 0); 640 641 Integer cmpgntrmdt_sortorder = _value.getSortOrder(); 642 if(cmpgntrmdt_sortorder == null) 643 _ps.setNull(7, Types.INTEGER); 644 else 645 _ps.setInt(7, cmpgntrmdt_sortorder); 646 647 Long cmpgntrmdt_fromtime = _value.getFromTime(); 648 if(cmpgntrmdt_fromtime == null) 649 _ps.setNull(8, Types.BIGINT); 650 else 651 _ps.setLong(8, cmpgntrmdt_fromtime); 652 653 Long cmpgntrmdt_thrutime = _value.getThruTime(); 654 if(cmpgntrmdt_thrutime == null) 655 _ps.setNull(9, Types.BIGINT); 656 else 657 _ps.setLong(9, cmpgntrmdt_thrutime); 658 659 } 660 661 public CampaignTermDetail create(CampaignTermPK campaignTermPK, String campaignTermName, String valueSha1Hash, String value, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 662 throws PersistenceDatabaseException, PersistenceNotNullException { 663 CampaignTermDetailPK _pk = getNextPK(); 664 CampaignTermDetailValue _value = new CampaignTermDetailValue(_pk, campaignTermPK, campaignTermName, 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 CampaignTermDetail _entity = new CampaignTermDetail(_value, EntityPermission.READ_ONLY); 687 session.putReadOnlyEntity(_pk, _entity); 688 689 return _entity; 690 } 691 692 public void create(Collection<CampaignTermDetailValue> _values) 693 throws PersistenceDatabaseException, PersistenceNotNullException { 694 int _size = _values.size(); 695 696 if(_size > 0) { 697 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 698 List<CampaignTermDetailValue> _cacheValues = new ArrayList<>(_size); 699 700 try { 701 for(CampaignTermDetailValue _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 CampaignTermDetail _cacheEntity = new CampaignTermDetail(_cacheValue, EntityPermission.READ_ONLY); 729 730 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 731 }); 732 } 733 } 734 735 private boolean bindForStore(PreparedStatement _ps, CampaignTermDetailValue _value) 736 throws SQLException { 737 boolean _hasBeenModified = _value.hasBeenModified(); 738 739 if(_hasBeenModified) { 740 CampaignTermPK cmpgntrmdt_cmpgntrm_campaigntermid = _value.getCampaignTermPK(); 741 if(cmpgntrmdt_cmpgntrm_campaigntermid == null) 742 _ps.setNull(1, Types.BIGINT); 743 else 744 _ps.setLong(1, cmpgntrmdt_cmpgntrm_campaigntermid.getEntityId()); 745 746 String cmpgntrmdt_campaigntermname = _value.getCampaignTermName(); 747 if(cmpgntrmdt_campaigntermname == null) 748 _ps.setNull(2, Types.VARCHAR); 749 else 750 _ps.setString(2, cmpgntrmdt_campaigntermname); 751 752 String cmpgntrmdt_valuesha1hash = _value.getValueSha1Hash(); 753 if(cmpgntrmdt_valuesha1hash == null) 754 _ps.setNull(3, Types.VARCHAR); 755 else 756 _ps.setString(3, cmpgntrmdt_valuesha1hash); 757 758 String cmpgntrmdt_value = _value.getValue(); 759 if(cmpgntrmdt_value == null) 760 _ps.setNull(4, Types.CLOB); 761 else 762 _ps.setCharacterStream(4, new StringReader(cmpgntrmdt_value), cmpgntrmdt_value.length()); 763 764 Boolean cmpgntrmdt_isdefault = _value.getIsDefault(); 765 if(cmpgntrmdt_isdefault == null) 766 _ps.setNull(5, Types.BIT); 767 else 768 _ps.setInt(5, cmpgntrmdt_isdefault? 1: 0); 769 770 Integer cmpgntrmdt_sortorder = _value.getSortOrder(); 771 if(cmpgntrmdt_sortorder == null) 772 _ps.setNull(6, Types.INTEGER); 773 else 774 _ps.setInt(6, cmpgntrmdt_sortorder); 775 776 Long cmpgntrmdt_fromtime = _value.getFromTime(); 777 if(cmpgntrmdt_fromtime == null) 778 _ps.setNull(7, Types.BIGINT); 779 else 780 _ps.setLong(7, cmpgntrmdt_fromtime); 781 782 Long cmpgntrmdt_thrutime = _value.getThruTime(); 783 if(cmpgntrmdt_thrutime == null) 784 _ps.setNull(8, Types.BIGINT); 785 else 786 _ps.setLong(8, cmpgntrmdt_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(CampaignTermDetail entity) 798 throws PersistenceDatabaseException { 799 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 800 801 try { 802 CampaignTermDetailValue _value = entity.getCampaignTermDetailValue(); 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<CampaignTermDetail> 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(CampaignTermDetail entity : entities) { 831 if(bindForStore(_ps, entity.getCampaignTermDetailValue())) { 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.getCampaignTermDetailValue()); 854 }); 855 } 856 } catch (SQLException se) { 857 throw new PersistenceDatabaseException(se); 858 } 859 } 860 } 861 862 @Override 863 public void remove(CampaignTermDetail entity) 864 throws PersistenceDatabaseException { 865 remove(entity.getPrimaryKey()); 866 } 867 868 @Override 869 public void remove(CampaignTermDetailPK 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<CampaignTermDetailPK> 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(CampaignTermDetailPK 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(CampaignTermDetailPK 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}