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