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