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