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