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