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