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