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