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