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