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