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