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