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