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