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