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