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