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