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