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