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