001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * CommunicationEventPurposeDescriptionFactory.java 021 */ 022 023package com.echothree.model.data.communication.server.factory; 024 025import com.echothree.model.data.communication.common.pk.CommunicationEventPurposePK; 026import com.echothree.model.data.party.common.pk.LanguagePK; 027 028import com.echothree.model.data.communication.server.entity.CommunicationEventPurpose; 029import com.echothree.model.data.party.server.entity.Language; 030 031import com.echothree.model.data.communication.common.CommunicationEventPurposeDescriptionConstants; 032import com.echothree.model.data.communication.common.pk.CommunicationEventPurposeDescriptionPK; 033import com.echothree.model.data.communication.server.value.CommunicationEventPurposeDescriptionValue; 034import com.echothree.model.data.communication.server.entity.CommunicationEventPurposeDescription; 035import com.echothree.util.common.exception.PersistenceDatabaseException; 036import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 037import com.echothree.util.common.exception.PersistenceNotNullException; 038import com.echothree.util.server.persistence.BaseFactory; 039import com.echothree.util.server.persistence.EntityIdGenerator; 040import com.echothree.util.server.persistence.EntityPermission; 041import com.echothree.util.server.persistence.PersistenceDebugFlags; 042import com.echothree.util.server.persistence.Session; 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 javax.inject.Inject; 058import org.slf4j.Logger; 059import org.slf4j.LoggerFactory; 060 061@ApplicationScoped 062public class CommunicationEventPurposeDescriptionFactory 063 implements BaseFactory<CommunicationEventPurposeDescriptionPK, CommunicationEventPurposeDescription> { 064 065 @Inject 066 Session session; 067 068 //private static final Logger log = LoggerFactory.getLogger(CommunicationEventPurposeDescriptionFactory.class); 069 070 final private static String SQL_SELECT_READ_ONLY = "SELECT cmmnevprd_communicationeventpurposedescriptionid, cmmnevprd_cmmnevpr_communicationeventpurposeid, cmmnevprd_lang_languageid, cmmnevprd_description, cmmnevprd_fromtime, cmmnevprd_thrutime FROM communicationeventpurposedescriptions WHERE cmmnevprd_communicationeventpurposedescriptionid = ?"; 071 final private static String SQL_SELECT_READ_WRITE = "SELECT cmmnevprd_communicationeventpurposedescriptionid, cmmnevprd_cmmnevpr_communicationeventpurposeid, cmmnevprd_lang_languageid, cmmnevprd_description, cmmnevprd_fromtime, cmmnevprd_thrutime FROM communicationeventpurposedescriptions WHERE cmmnevprd_communicationeventpurposedescriptionid = ? FOR UPDATE"; 072 final private static String SQL_INSERT = "INSERT INTO communicationeventpurposedescriptions (cmmnevprd_communicationeventpurposedescriptionid, cmmnevprd_cmmnevpr_communicationeventpurposeid, cmmnevprd_lang_languageid, cmmnevprd_description, cmmnevprd_fromtime, cmmnevprd_thrutime) VALUES (?, ?, ?, ?, ?, ?)"; 073 final private static String SQL_UPDATE = "UPDATE communicationeventpurposedescriptions SET cmmnevprd_cmmnevpr_communicationeventpurposeid = ?, cmmnevprd_lang_languageid = ?, cmmnevprd_description = ?, cmmnevprd_fromtime = ?, cmmnevprd_thrutime = ? WHERE cmmnevprd_communicationeventpurposedescriptionid = ?"; 074 final private static String SQL_DELETE = "DELETE FROM communicationeventpurposedescriptions WHERE cmmnevprd_communicationeventpurposedescriptionid = ?"; 075 final private static String SQL_VALID = "SELECT COUNT(*) FROM communicationeventpurposedescriptions WHERE cmmnevprd_communicationeventpurposedescriptionid = ?"; 076 077 final private static String PK_COLUMN = "cmmnevprd_communicationeventpurposedescriptionid"; 078 final private static String ALL_COLUMNS = "cmmnevprd_communicationeventpurposedescriptionid, cmmnevprd_cmmnevpr_communicationeventpurposeid, cmmnevprd_lang_languageid, cmmnevprd_description, cmmnevprd_fromtime, cmmnevprd_thrutime"; 079 final public static String TABLE_NAME = "communicationeventpurposedescriptions"; 080 081 final public static String CMMNEVPRD_COMMUNICATIONEVENTPURPOSEDESCRIPTIONID = "cmmnevprd_communicationeventpurposedescriptionid"; 082 final public static String CMMNEVPRD_CMMNEVPR_COMMUNICATIONEVENTPURPOSEID = "cmmnevprd_cmmnevpr_communicationeventpurposeid"; 083 final public static String CMMNEVPRD_LANG_LANGUAGEID = "cmmnevprd_lang_languageid"; 084 final public static String CMMNEVPRD_DESCRIPTION = "cmmnevprd_description"; 085 final public static String CMMNEVPRD_FROMTIME = "cmmnevprd_fromtime"; 086 final public static String CMMNEVPRD_THRUTIME = "cmmnevprd_thrutime"; 087 088 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(CommunicationEventPurposeDescriptionConstants.COMPONENT_VENDOR_NAME, CommunicationEventPurposeDescriptionConstants.ENTITY_TYPE_NAME); 089 090 /** Creates a new instance of CommunicationEventPurposeDescriptionFactory */ 091 protected CommunicationEventPurposeDescriptionFactory() { 092 super(); 093 } 094 095 public static CommunicationEventPurposeDescriptionFactory getInstance() { 096 return CDI.current().select(CommunicationEventPurposeDescriptionFactory.class).get(); 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 CommunicationEventPurposeDescriptionConstants.COMPONENT_VENDOR_NAME; 117 } 118 119 @Override 120 public String getEntityTypeName() { 121 return CommunicationEventPurposeDescriptionConstants.ENTITY_TYPE_NAME; 122 } 123 124 public PreparedStatement prepareStatement(String query) { 125 return session.prepareStatement(CommunicationEventPurposeDescriptionFactory.class, query); 126 } 127 128 public CommunicationEventPurposeDescriptionPK getNextPK() { 129 return new CommunicationEventPurposeDescriptionPK(entityIdGenerator.getNextEntityId()); 130 } 131 132 public Set<CommunicationEventPurposeDescriptionPK> getPKsFromResultSetAsSet(ResultSet rs) 133 throws PersistenceDatabaseException { 134 Set<CommunicationEventPurposeDescriptionPK> _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<CommunicationEventPurposeDescriptionPK> getPKsFromResultSetAsList(ResultSet rs) 148 throws PersistenceDatabaseException { 149 java.util.List<CommunicationEventPurposeDescriptionPK> _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 CommunicationEventPurposeDescriptionPK getPKFromResultSet(ResultSet rs) 163 throws PersistenceDatabaseException { 164 CommunicationEventPurposeDescriptionPK _result; 165 166 try { 167 long cmmnevprd_communicationeventpurposedescriptionid = rs.getLong(CMMNEVPRD_COMMUNICATIONEVENTPURPOSEDESCRIPTIONID); 168 Long _entityId = rs.wasNull() ? null : cmmnevprd_communicationeventpurposedescriptionid; 169 170 _result = new CommunicationEventPurposeDescriptionPK(_entityId); 171 } catch (SQLException se) { 172 throw new PersistenceDatabaseException(se); 173 } 174 175 return _result; 176 } 177 178 public java.util.List<CommunicationEventPurposeDescriptionValue> getValuesFromPKs(Collection<CommunicationEventPurposeDescriptionPK> pks) 179 throws PersistenceDatabaseException { 180 java.util.List<CommunicationEventPurposeDescriptionValue> _values = new ArrayList<>(pks.size()); 181 182 for(CommunicationEventPurposeDescriptionPK _pk: pks) { 183 _values.add(getValueFromPK(_pk)); 184 } 185 186 return _values; 187 } 188 189 public CommunicationEventPurposeDescriptionValue getValueFromPK(CommunicationEventPurposeDescriptionPK pk) 190 throws PersistenceDatabaseException { 191 CommunicationEventPurposeDescriptionValue _value; 192 193 // See if we already have the entity in the session cache 194 CommunicationEventPurposeDescription _entity = (CommunicationEventPurposeDescription)session.getEntity(pk); 195 if(_entity == null) 196 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getCommunicationEventPurposeDescriptionValue(); 197 else 198 _value = _entity.getCommunicationEventPurposeDescriptionValue(); 199 200 return _value; 201 } 202 203 public java.util.List<CommunicationEventPurposeDescriptionValue> getValuesFromResultSet(ResultSet rs) 204 throws PersistenceDatabaseException { 205 java.util.List<CommunicationEventPurposeDescriptionValue> _result = new ArrayList<>(); 206 207 try { 208 while(rs.next()) { 209 _result.add(getValueFromResultSet(rs)); 210 } 211 } catch (SQLException se) { 212 throw new PersistenceDatabaseException(se); 213 } 214 215 return _result; 216 } 217 218 public CommunicationEventPurposeDescriptionValue getValueFromResultSet(ResultSet rs) 219 throws PersistenceDatabaseException { 220 CommunicationEventPurposeDescriptionValue _value; 221 222 try { 223 Long cmmnevprd_communicationeventpurposedescriptionid = rs.getLong(CMMNEVPRD_COMMUNICATIONEVENTPURPOSEDESCRIPTIONID); 224 CommunicationEventPurposeDescriptionPK _pk = new CommunicationEventPurposeDescriptionPK(cmmnevprd_communicationeventpurposedescriptionid); 225 226 // See if we already have the entity in the session cache 227 CommunicationEventPurposeDescription _entity = (CommunicationEventPurposeDescription)session.getEntity(_pk); 228 229 if(_entity == null) { 230 Long cmmnevprd_cmmnevpr_communicationeventpurposeid = rs.getLong(CMMNEVPRD_CMMNEVPR_COMMUNICATIONEVENTPURPOSEID); 231 if(rs.wasNull()) 232 cmmnevprd_cmmnevpr_communicationeventpurposeid = null; 233 234 Long cmmnevprd_lang_languageid = rs.getLong(CMMNEVPRD_LANG_LANGUAGEID); 235 if(rs.wasNull()) 236 cmmnevprd_lang_languageid = null; 237 238 String cmmnevprd_description = rs.getString(CMMNEVPRD_DESCRIPTION); 239 if(rs.wasNull()) 240 cmmnevprd_description = null; 241 242 Long cmmnevprd_fromtime = rs.getLong(CMMNEVPRD_FROMTIME); 243 if(rs.wasNull()) 244 cmmnevprd_fromtime = null; 245 246 Long cmmnevprd_thrutime = rs.getLong(CMMNEVPRD_THRUTIME); 247 if(rs.wasNull()) 248 cmmnevprd_thrutime = null; 249 250 _value = new CommunicationEventPurposeDescriptionValue(_pk, new CommunicationEventPurposePK(cmmnevprd_cmmnevpr_communicationeventpurposeid), new LanguagePK(cmmnevprd_lang_languageid), cmmnevprd_description, cmmnevprd_fromtime, cmmnevprd_thrutime); 251 } else 252 _value = _entity.getCommunicationEventPurposeDescriptionValue(); 253 } catch (SQLException se) { 254 throw new PersistenceDatabaseException(se); 255 } 256 257 return _value; 258 } 259 260 public java.util.List<CommunicationEventPurposeDescription> getEntitiesFromPKs(EntityPermission entityPermission, Collection<CommunicationEventPurposeDescriptionPK> pks) 261 throws PersistenceDatabaseException { 262 java.util.List<CommunicationEventPurposeDescription> _entities = new ArrayList<>(pks.size()); 263 264 for(CommunicationEventPurposeDescriptionPK _pk: pks) { 265 _entities.add(getEntityFromPK(entityPermission, _pk)); 266 } 267 268 return _entities; 269 } 270 271 public CommunicationEventPurposeDescription getEntityFromValue(EntityPermission entityPermission, CommunicationEventPurposeDescriptionValue value) { 272 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 273 } 274 275 public CommunicationEventPurposeDescription getEntityFromCache(CommunicationEventPurposeDescriptionPK pk) { 276 CommunicationEventPurposeDescriptionValue _value = (CommunicationEventPurposeDescriptionValue)session.getValueCache().get(pk); 277 278 return _value == null ? null : new CommunicationEventPurposeDescription(_value, EntityPermission.READ_ONLY); 279 } 280 281 public CommunicationEventPurposeDescription getEntityFromPK(EntityPermission entityPermission, CommunicationEventPurposeDescriptionPK pk) 282 throws PersistenceDatabaseException { 283 CommunicationEventPurposeDescription _entity; 284 285 // See if we already have the entity in the session cache 286 _entity = (CommunicationEventPurposeDescription)session.getEntity(pk); 287 if(_entity != null) { 288 // If the requested permission is READ_WRITE, and the cached permission is 289 // READ_ONLY, then pretend that the cached object wasn't found, and create 290 // a new entity that is READ_WRITE. 291 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 292 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 293 _entity = null; 294 } 295 } 296 297 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 298 _entity = getEntityFromCache(pk); 299 } 300 301 if(_entity == null) { 302 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 303 long _entityId = pk.getEntityId(); 304 ResultSet _rs = null; 305 306 try { 307 _ps.setLong(1, _entityId); 308 _rs = _ps.executeQuery(); 309 if(_rs.next()) { 310 _entity = getEntityFromResultSet(entityPermission, _rs); 311 } 312 } catch (SQLException se) { 313 throw new PersistenceDatabaseException(se); 314 } finally { 315 if(_rs != null) { 316 try { 317 _rs.close(); 318 } catch (SQLException se) { 319 // do nothing 320 } 321 } 322 } 323 } 324 325 return _entity; 326 } 327 328 public Set<CommunicationEventPurposeDescriptionPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 329 throws PersistenceDatabaseException { 330 Set<CommunicationEventPurposeDescriptionPK> _pks; 331 ResultSet _rs = null; 332 333 try { 334 if(params.length != 0) { 335 Session.setQueryParams(ps, params); 336 } 337 338 _rs = ps.executeQuery(); 339 _pks = getPKsFromResultSetAsSet(_rs); 340 _rs.close(); 341 } catch (SQLException se) { 342 throw new PersistenceDatabaseException(se); 343 } finally { 344 if(_rs != null) { 345 try { 346 _rs.close(); 347 } catch (SQLException se) { 348 // do nothing 349 } 350 } 351 } 352 353 return _pks; 354 } 355 356 public java.util.List<CommunicationEventPurposeDescriptionPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 357 throws PersistenceDatabaseException { 358 java.util.List<CommunicationEventPurposeDescriptionPK> _pks; 359 ResultSet _rs = null; 360 361 try { 362 if(params.length != 0) { 363 Session.setQueryParams(ps, params); 364 } 365 366 _rs = ps.executeQuery(); 367 _pks = getPKsFromResultSetAsList(_rs); 368 _rs.close(); 369 } catch (SQLException se) { 370 throw new PersistenceDatabaseException(se); 371 } finally { 372 if(_rs != null) { 373 try { 374 _rs.close(); 375 } catch (SQLException se) { 376 // do nothing 377 } 378 } 379 } 380 381 return _pks; 382 } 383 384 public CommunicationEventPurposeDescriptionPK getPKFromQuery(PreparedStatement ps, final Object... params) 385 throws PersistenceDatabaseException { 386 CommunicationEventPurposeDescriptionPK _pk = null; 387 ResultSet _rs = null; 388 389 try { 390 if(params.length != 0) { 391 Session.setQueryParams(ps, params); 392 } 393 394 _rs = ps.executeQuery(); 395 if(_rs.next()) { 396 _pk = getPKFromResultSet(_rs); 397 } 398 _rs.close(); 399 } catch (SQLException se) { 400 throw new PersistenceDatabaseException(se); 401 } finally { 402 if(_rs != null) { 403 try { 404 _rs.close(); 405 } catch (SQLException se) { 406 // do nothing 407 } 408 } 409 } 410 411 return _pk; 412 } 413 414 public java.util.List<CommunicationEventPurposeDescription> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 415 throws PersistenceDatabaseException { 416 PreparedStatement ps = session.prepareStatement(CommunicationEventPurposeDescriptionFactory.class, queryMap.get(entityPermission)); 417 418 return getEntitiesFromQuery(entityPermission, ps, params); 419 } 420 421 public java.util.List<CommunicationEventPurposeDescription> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 422 throws PersistenceDatabaseException { 423 PreparedStatement ps = session.prepareStatement(CommunicationEventPurposeDescriptionFactory.class, queryMap.get(entityPermission)); 424 425 return getEntitiesFromQuery(entityPermission, ps); 426 } 427 428 public java.util.List<CommunicationEventPurposeDescription> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 429 throws PersistenceDatabaseException { 430 java.util.List<CommunicationEventPurposeDescription> _entities; 431 ResultSet _rs = null; 432 433 try { 434 if(params.length != 0) { 435 Session.setQueryParams(ps, params); 436 } 437 438 _rs = ps.executeQuery(); 439 _entities = getEntitiesFromResultSet(entityPermission, _rs); 440 _rs.close(); 441 } catch (SQLException se) { 442 throw new PersistenceDatabaseException(se); 443 } finally { 444 if(_rs != null) { 445 try { 446 _rs.close(); 447 } catch (SQLException se) { 448 // do nothing 449 } 450 } 451 } 452 453 return _entities; 454 } 455 456 public CommunicationEventPurposeDescription getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 457 throws PersistenceDatabaseException { 458 PreparedStatement ps = session.prepareStatement(CommunicationEventPurposeDescriptionFactory.class, queryMap.get(entityPermission)); 459 460 return getEntityFromQuery(entityPermission, ps, params); 461 } 462 463 public CommunicationEventPurposeDescription getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 464 throws PersistenceDatabaseException { 465 PreparedStatement ps = session.prepareStatement(CommunicationEventPurposeDescriptionFactory.class, queryMap.get(entityPermission)); 466 467 return getEntityFromQuery(entityPermission, ps); 468 } 469 470 public CommunicationEventPurposeDescription getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 471 throws PersistenceDatabaseException { 472 CommunicationEventPurposeDescription _entity = null; 473 ResultSet _rs = null; 474 475 try { 476 if(params.length != 0) { 477 Session.setQueryParams(ps, params); 478 } 479 480 _rs = ps.executeQuery(); 481 if(_rs.next()) { 482 _entity = getEntityFromResultSet(entityPermission, _rs); 483 } 484 _rs.close(); 485 } catch (SQLException se) { 486 throw new PersistenceDatabaseException(se); 487 } finally { 488 if(_rs != null) { 489 try { 490 _rs.close(); 491 } catch (SQLException se) { 492 // do nothing 493 } 494 } 495 } 496 497 return _entity; 498 } 499 500 public java.util.List<CommunicationEventPurposeDescription> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 501 throws PersistenceDatabaseException { 502 java.util.List<CommunicationEventPurposeDescription> _result = new ArrayList<>(); 503 504 try { 505 while(rs.next()) { 506 _result.add(getEntityFromResultSet(entityPermission, rs)); 507 } 508 } catch (SQLException se) { 509 throw new PersistenceDatabaseException(se); 510 } 511 512 return _result; 513 } 514 515 public CommunicationEventPurposeDescription getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 516 throws PersistenceDatabaseException { 517 CommunicationEventPurposeDescription _entity; 518 519 try { 520 Long cmmnevprd_communicationeventpurposedescriptionid = rs.getLong(CMMNEVPRD_COMMUNICATIONEVENTPURPOSEDESCRIPTIONID); 521 CommunicationEventPurposeDescriptionPK _pk = new CommunicationEventPurposeDescriptionPK(cmmnevprd_communicationeventpurposedescriptionid); 522 523 // See if we already have the entity in the session cache 524 _entity = (CommunicationEventPurposeDescription)session.getEntity(_pk); 525 if(_entity != null) { 526 // If the requested permission is READ_WRITE, and the cached permission is 527 // READ_ONLY, then pretend that the cached object wasn't found, and create 528 // a new entity that is READ_WRITE. 529 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 530 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 531 _entity = null; 532 } 533 } 534 boolean foundInSessionCache = _entity != null; 535 536 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 537 _entity = getEntityFromCache(_pk); 538 } 539 540 if(_entity == null) { 541 Long cmmnevprd_cmmnevpr_communicationeventpurposeid = rs.getLong(CMMNEVPRD_CMMNEVPR_COMMUNICATIONEVENTPURPOSEID); 542 if(rs.wasNull()) 543 cmmnevprd_cmmnevpr_communicationeventpurposeid = null; 544 545 Long cmmnevprd_lang_languageid = rs.getLong(CMMNEVPRD_LANG_LANGUAGEID); 546 if(rs.wasNull()) 547 cmmnevprd_lang_languageid = null; 548 549 String cmmnevprd_description = rs.getString(CMMNEVPRD_DESCRIPTION); 550 if(rs.wasNull()) 551 cmmnevprd_description = null; 552 553 Long cmmnevprd_fromtime = rs.getLong(CMMNEVPRD_FROMTIME); 554 if(rs.wasNull()) 555 cmmnevprd_fromtime = null; 556 557 Long cmmnevprd_thrutime = rs.getLong(CMMNEVPRD_THRUTIME); 558 if(rs.wasNull()) 559 cmmnevprd_thrutime = null; 560 561 CommunicationEventPurposeDescriptionValue _value = new CommunicationEventPurposeDescriptionValue(_pk, cmmnevprd_cmmnevpr_communicationeventpurposeid == null? null: new CommunicationEventPurposePK(cmmnevprd_cmmnevpr_communicationeventpurposeid), cmmnevprd_lang_languageid == null? null: new LanguagePK(cmmnevprd_lang_languageid), cmmnevprd_description, cmmnevprd_fromtime, cmmnevprd_thrutime); 562 _entity = new CommunicationEventPurposeDescription(_value, entityPermission); 563 } 564 565 if(!foundInSessionCache) { 566 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 567 session.putReadOnlyEntity(_pk, _entity); 568 session.getValueCache().put(_entity.getCommunicationEventPurposeDescriptionValue()); 569 } else { 570 session.putReadWriteEntity(_pk, _entity); 571 } 572 } 573 } catch (SQLException se) { 574 throw new PersistenceDatabaseException(se); 575 } 576 577 return _entity; 578 } 579 580 public CommunicationEventPurposeDescription create(CommunicationEventPurpose communicationEventPurpose, Language language, String description, Long fromTime, Long thruTime) 581 throws PersistenceDatabaseException, PersistenceNotNullException { 582 return create(communicationEventPurpose == null ? null : communicationEventPurpose.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, fromTime, thruTime); 583 } 584 585 private void bindForCreate(PreparedStatement _ps, CommunicationEventPurposeDescriptionValue _value) 586 throws SQLException { 587 _ps.setLong(1, _value.getEntityId()); 588 589 CommunicationEventPurposePK cmmnevprd_cmmnevpr_communicationeventpurposeid = _value.getCommunicationEventPurposePK(); 590 if(cmmnevprd_cmmnevpr_communicationeventpurposeid == null) 591 _ps.setNull(2, Types.BIGINT); 592 else 593 _ps.setLong(2, cmmnevprd_cmmnevpr_communicationeventpurposeid.getEntityId()); 594 595 LanguagePK cmmnevprd_lang_languageid = _value.getLanguagePK(); 596 if(cmmnevprd_lang_languageid == null) 597 _ps.setNull(3, Types.BIGINT); 598 else 599 _ps.setLong(3, cmmnevprd_lang_languageid.getEntityId()); 600 601 String cmmnevprd_description = _value.getDescription(); 602 if(cmmnevprd_description == null) 603 _ps.setNull(4, Types.VARCHAR); 604 else 605 _ps.setString(4, cmmnevprd_description); 606 607 Long cmmnevprd_fromtime = _value.getFromTime(); 608 if(cmmnevprd_fromtime == null) 609 _ps.setNull(5, Types.BIGINT); 610 else 611 _ps.setLong(5, cmmnevprd_fromtime); 612 613 Long cmmnevprd_thrutime = _value.getThruTime(); 614 if(cmmnevprd_thrutime == null) 615 _ps.setNull(6, Types.BIGINT); 616 else 617 _ps.setLong(6, cmmnevprd_thrutime); 618 619 } 620 621 public CommunicationEventPurposeDescription create(CommunicationEventPurposePK communicationEventPurposePK, LanguagePK languagePK, String description, Long fromTime, Long thruTime) 622 throws PersistenceDatabaseException, PersistenceNotNullException { 623 CommunicationEventPurposeDescriptionPK _pk = getNextPK(); 624 CommunicationEventPurposeDescriptionValue _value = new CommunicationEventPurposeDescriptionValue(_pk, communicationEventPurposePK, languagePK, description, fromTime, thruTime); 625 626 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 627 628 try { 629 bindForCreate(_ps, _value); 630 631 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 632 int _count = _ps.executeUpdate(); 633 634 if(_count != 1) { 635 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 636 } 637 } else { 638 _ps.executeUpdate(); 639 } 640 641 session.getValueCache().put(_value); 642 } catch (SQLException se) { 643 throw new PersistenceDatabaseException(se); 644 } 645 646 CommunicationEventPurposeDescription _entity = new CommunicationEventPurposeDescription(_value, EntityPermission.READ_ONLY); 647 session.putReadOnlyEntity(_pk, _entity); 648 649 return _entity; 650 } 651 652 public void create(Collection<CommunicationEventPurposeDescriptionValue> _values) 653 throws PersistenceDatabaseException, PersistenceNotNullException { 654 int _size = _values.size(); 655 656 if(_size > 0) { 657 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 658 List<CommunicationEventPurposeDescriptionValue> _cacheValues = new ArrayList<>(_size); 659 660 try { 661 for(CommunicationEventPurposeDescriptionValue _value : _values) { 662 _value.setEntityId(entityIdGenerator.getNextEntityId()); 663 bindForCreate(_ps, _value); 664 665 _ps.addBatch(); 666 667 _cacheValues.add(_value); 668 } 669 670 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 671 int[] _counts = _ps.executeBatch(); 672 673 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 674 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 675 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 676 } 677 } 678 } else { 679 _ps.executeBatch(); 680 } 681 682 _ps.clearBatch(); 683 } catch (SQLException se) { 684 throw new PersistenceDatabaseException(se); 685 } 686 687 _cacheValues.forEach((_cacheValue) -> { 688 CommunicationEventPurposeDescription _cacheEntity = new CommunicationEventPurposeDescription(_cacheValue, EntityPermission.READ_ONLY); 689 690 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 691 }); 692 } 693 } 694 695 private boolean bindForStore(PreparedStatement _ps, CommunicationEventPurposeDescriptionValue _value) 696 throws SQLException { 697 boolean _hasBeenModified = _value.hasBeenModified(); 698 699 if(_hasBeenModified) { 700 CommunicationEventPurposePK cmmnevprd_cmmnevpr_communicationeventpurposeid = _value.getCommunicationEventPurposePK(); 701 if(cmmnevprd_cmmnevpr_communicationeventpurposeid == null) 702 _ps.setNull(1, Types.BIGINT); 703 else 704 _ps.setLong(1, cmmnevprd_cmmnevpr_communicationeventpurposeid.getEntityId()); 705 706 LanguagePK cmmnevprd_lang_languageid = _value.getLanguagePK(); 707 if(cmmnevprd_lang_languageid == null) 708 _ps.setNull(2, Types.BIGINT); 709 else 710 _ps.setLong(2, cmmnevprd_lang_languageid.getEntityId()); 711 712 String cmmnevprd_description = _value.getDescription(); 713 if(cmmnevprd_description == null) 714 _ps.setNull(3, Types.VARCHAR); 715 else 716 _ps.setString(3, cmmnevprd_description); 717 718 Long cmmnevprd_fromtime = _value.getFromTime(); 719 if(cmmnevprd_fromtime == null) 720 _ps.setNull(4, Types.BIGINT); 721 else 722 _ps.setLong(4, cmmnevprd_fromtime); 723 724 Long cmmnevprd_thrutime = _value.getThruTime(); 725 if(cmmnevprd_thrutime == null) 726 _ps.setNull(5, Types.BIGINT); 727 else 728 _ps.setLong(5, cmmnevprd_thrutime); 729 730 _ps.setLong(6, _value.getPrimaryKey().getEntityId()); 731 732 _value.clearHasBeenModified(); 733 } 734 735 return _hasBeenModified; 736 } 737 738 @Override 739 public void store(CommunicationEventPurposeDescription entity) 740 throws PersistenceDatabaseException { 741 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 742 743 try { 744 CommunicationEventPurposeDescriptionValue _value = entity.getCommunicationEventPurposeDescriptionValue(); 745 746 if(bindForStore(_ps, _value)) { 747 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 748 int _count = _ps.executeUpdate(); 749 750 if(_count != 1) { 751 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 752 } 753 } else { 754 _ps.executeUpdate(); 755 } 756 757 session.getValueCache().put(_value); 758 } 759 } catch (SQLException se) { 760 throw new PersistenceDatabaseException(se); 761 } 762 } 763 764 @Override 765 public void store(Collection<CommunicationEventPurposeDescription> entities) 766 throws PersistenceDatabaseException { 767 if(entities.size() > 0) { 768 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 769 int _modifiedEntities = 0; 770 771 try { 772 for(CommunicationEventPurposeDescription entity : entities) { 773 if(bindForStore(_ps, entity.getCommunicationEventPurposeDescriptionValue())) { 774 _ps.addBatch(); 775 _modifiedEntities++; 776 } 777 } 778 779 if(_modifiedEntities != 0) { 780 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 781 int[] _counts = _ps.executeBatch(); 782 783 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 784 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 785 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 786 } 787 } 788 } else { 789 _ps.executeBatch(); 790 } 791 792 _ps.clearBatch(); 793 794 entities.forEach((entity) -> { 795 session.getValueCache().put(entity.getCommunicationEventPurposeDescriptionValue()); 796 }); 797 } 798 } catch (SQLException se) { 799 throw new PersistenceDatabaseException(se); 800 } 801 } 802 } 803 804 @Override 805 public void remove(CommunicationEventPurposeDescription entity) 806 throws PersistenceDatabaseException { 807 remove(entity.getPrimaryKey()); 808 } 809 810 @Override 811 public void remove(CommunicationEventPurposeDescriptionPK pk) 812 throws PersistenceDatabaseException { 813 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 814 long _entityId = pk.getEntityId(); 815 816 try { 817 _ps.setLong(1, _entityId); 818 819 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 820 int _count = _ps.executeUpdate(); 821 822 if(_count != 1) { 823 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 824 } 825 } else { 826 _ps.executeUpdate(); 827 } 828 829 session.getValueCache().remove(pk); 830 } catch (SQLException se) { 831 throw new PersistenceDatabaseException(se); 832 } 833 834 session.removed(pk, false); 835 } 836 837 @Override 838 public void remove(Collection<CommunicationEventPurposeDescriptionPK> pks) 839 throws PersistenceDatabaseException { 840 if(pks.size() > 0) { 841 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 842 int _modifiedEntities = 0; 843 844 try { 845 for(CommunicationEventPurposeDescriptionPK pk : pks) { 846 long _entityId = pk.getEntityId(); 847 848 _ps.setLong(1, _entityId); 849 850 _ps.addBatch(); 851 _modifiedEntities++; 852 } 853 854 if(_modifiedEntities != 0) { 855 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 856 int[] _counts = _ps.executeBatch(); 857 858 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 859 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 860 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 861 } 862 } 863 } else { 864 _ps.executeBatch(); 865 } 866 867 _ps.clearBatch(); 868 869 pks.forEach((pk) -> { 870 session.getValueCache().remove(pk); 871 }); 872 } 873 } catch (SQLException se) { 874 throw new PersistenceDatabaseException(se); 875 } 876 877 pks.forEach((pk) -> { 878 session.removed(pk, true); 879 }); 880 } 881 } 882 883 @Override 884 public boolean validPK(CommunicationEventPurposeDescriptionPK pk) 885 throws PersistenceDatabaseException { 886 boolean valid = false; 887 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 888 ResultSet _rs = null; 889 890 try { 891 _ps.setLong(1, pk.getEntityId()); 892 893 _rs = _ps.executeQuery(); 894 if(_rs.next()) { 895 long _count = _rs.getLong(1); 896 if(_rs.wasNull()) 897 _count = 0; 898 899 if(_count == 1) 900 valid = true; 901 } 902 } catch (SQLException se) { 903 throw new PersistenceDatabaseException(se); 904 } finally { 905 if(_rs != null) { 906 try { 907 _rs.close(); 908 } catch (SQLException se) { 909 // do nothing 910 } 911 } 912 } 913 914 return valid; 915 } 916 917}