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