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