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