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