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