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