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