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