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 * TaxClassificationTranslationFactory.java 021 */ 022 023package com.echothree.model.data.tax.server.factory; 024 025import com.echothree.model.data.tax.common.pk.TaxClassificationPK; 026import com.echothree.model.data.party.common.pk.LanguagePK; 027import com.echothree.model.data.core.common.pk.MimeTypePK; 028 029import com.echothree.model.data.tax.server.entity.TaxClassification; 030import com.echothree.model.data.party.server.entity.Language; 031import com.echothree.model.data.core.server.entity.MimeType; 032 033import com.echothree.model.data.tax.common.TaxClassificationTranslationConstants; 034import com.echothree.model.data.tax.common.pk.TaxClassificationTranslationPK; 035import com.echothree.model.data.tax.server.value.TaxClassificationTranslationValue; 036import com.echothree.model.data.tax.server.entity.TaxClassificationTranslation; 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 TaxClassificationTranslationFactory 066 implements BaseFactory<TaxClassificationTranslationPK, TaxClassificationTranslation> { 067 068 @Inject 069 Session session; 070 071 //private static final Logger log = LoggerFactory.getLogger(TaxClassificationTranslationFactory.class); 072 073 final private static String SQL_SELECT_READ_ONLY = "SELECT txclsfntr_taxclassificationtranslationid, txclsfntr_txclsfn_taxclassificationid, txclsfntr_lang_languageid, txclsfntr_description, txclsfntr_overviewmimetypeid, txclsfntr_overview, txclsfntr_fromtime, txclsfntr_thrutime FROM taxclassificationtranslations WHERE txclsfntr_taxclassificationtranslationid = ?"; 074 final private static String SQL_SELECT_READ_WRITE = "SELECT txclsfntr_taxclassificationtranslationid, txclsfntr_txclsfn_taxclassificationid, txclsfntr_lang_languageid, txclsfntr_description, txclsfntr_overviewmimetypeid, txclsfntr_overview, txclsfntr_fromtime, txclsfntr_thrutime FROM taxclassificationtranslations WHERE txclsfntr_taxclassificationtranslationid = ? FOR UPDATE"; 075 final private static String SQL_INSERT = "INSERT INTO taxclassificationtranslations (txclsfntr_taxclassificationtranslationid, txclsfntr_txclsfn_taxclassificationid, txclsfntr_lang_languageid, txclsfntr_description, txclsfntr_overviewmimetypeid, txclsfntr_overview, txclsfntr_fromtime, txclsfntr_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; 076 final private static String SQL_UPDATE = "UPDATE taxclassificationtranslations SET txclsfntr_txclsfn_taxclassificationid = ?, txclsfntr_lang_languageid = ?, txclsfntr_description = ?, txclsfntr_overviewmimetypeid = ?, txclsfntr_overview = ?, txclsfntr_fromtime = ?, txclsfntr_thrutime = ? WHERE txclsfntr_taxclassificationtranslationid = ?"; 077 final private static String SQL_DELETE = "DELETE FROM taxclassificationtranslations WHERE txclsfntr_taxclassificationtranslationid = ?"; 078 final private static String SQL_VALID = "SELECT COUNT(*) FROM taxclassificationtranslations WHERE txclsfntr_taxclassificationtranslationid = ?"; 079 080 final private static String PK_COLUMN = "txclsfntr_taxclassificationtranslationid"; 081 final private static String ALL_COLUMNS = "txclsfntr_taxclassificationtranslationid, txclsfntr_txclsfn_taxclassificationid, txclsfntr_lang_languageid, txclsfntr_description, txclsfntr_overviewmimetypeid, txclsfntr_overview, txclsfntr_fromtime, txclsfntr_thrutime"; 082 final public static String TABLE_NAME = "taxclassificationtranslations"; 083 084 final public static String TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID = "txclsfntr_taxclassificationtranslationid"; 085 final public static String TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID = "txclsfntr_txclsfn_taxclassificationid"; 086 final public static String TXCLSFNTR_LANG_LANGUAGEID = "txclsfntr_lang_languageid"; 087 final public static String TXCLSFNTR_DESCRIPTION = "txclsfntr_description"; 088 final public static String TXCLSFNTR_OVERVIEWMIMETYPEID = "txclsfntr_overviewmimetypeid"; 089 final public static String TXCLSFNTR_OVERVIEW = "txclsfntr_overview"; 090 final public static String TXCLSFNTR_FROMTIME = "txclsfntr_fromtime"; 091 final public static String TXCLSFNTR_THRUTIME = "txclsfntr_thrutime"; 092 093 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(TaxClassificationTranslationConstants.COMPONENT_VENDOR_NAME, TaxClassificationTranslationConstants.ENTITY_TYPE_NAME); 094 095 /** Creates a new instance of TaxClassificationTranslationFactory */ 096 protected TaxClassificationTranslationFactory() { 097 super(); 098 } 099 100 public static TaxClassificationTranslationFactory getInstance() { 101 return CDI.current().select(TaxClassificationTranslationFactory.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 TaxClassificationTranslationConstants.COMPONENT_VENDOR_NAME; 122 } 123 124 @Override 125 public String getEntityTypeName() { 126 return TaxClassificationTranslationConstants.ENTITY_TYPE_NAME; 127 } 128 129 public PreparedStatement prepareStatement(String query) { 130 return session.prepareStatement(TaxClassificationTranslationFactory.class, query); 131 } 132 133 public TaxClassificationTranslationPK getNextPK() { 134 return new TaxClassificationTranslationPK(entityIdGenerator.getNextEntityId()); 135 } 136 137 public Set<TaxClassificationTranslationPK> getPKsFromResultSetAsSet(ResultSet rs) 138 throws PersistenceDatabaseException { 139 Set<TaxClassificationTranslationPK> _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<TaxClassificationTranslationPK> getPKsFromResultSetAsList(ResultSet rs) 153 throws PersistenceDatabaseException { 154 java.util.List<TaxClassificationTranslationPK> _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 TaxClassificationTranslationPK getPKFromResultSet(ResultSet rs) 168 throws PersistenceDatabaseException { 169 TaxClassificationTranslationPK _result; 170 171 try { 172 long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID); 173 Long _entityId = rs.wasNull() ? null : txclsfntr_taxclassificationtranslationid; 174 175 _result = new TaxClassificationTranslationPK(_entityId); 176 } catch (SQLException se) { 177 throw new PersistenceDatabaseException(se); 178 } 179 180 return _result; 181 } 182 183 public java.util.List<TaxClassificationTranslationValue> getValuesFromPKs(Collection<TaxClassificationTranslationPK> pks) 184 throws PersistenceDatabaseException { 185 java.util.List<TaxClassificationTranslationValue> _values = new ArrayList<>(pks.size()); 186 187 for(TaxClassificationTranslationPK _pk: pks) { 188 _values.add(getValueFromPK(_pk)); 189 } 190 191 return _values; 192 } 193 194 public TaxClassificationTranslationValue getValueFromPK(TaxClassificationTranslationPK pk) 195 throws PersistenceDatabaseException { 196 TaxClassificationTranslationValue _value; 197 198 // See if we already have the entity in the session cache 199 TaxClassificationTranslation _entity = (TaxClassificationTranslation)session.getEntity(pk); 200 if(_entity == null) 201 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getTaxClassificationTranslationValue(); 202 else 203 _value = _entity.getTaxClassificationTranslationValue(); 204 205 return _value; 206 } 207 208 public java.util.List<TaxClassificationTranslationValue> getValuesFromResultSet(ResultSet rs) 209 throws PersistenceDatabaseException { 210 java.util.List<TaxClassificationTranslationValue> _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 TaxClassificationTranslationValue getValueFromResultSet(ResultSet rs) 224 throws PersistenceDatabaseException { 225 TaxClassificationTranslationValue _value; 226 227 try { 228 Long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID); 229 TaxClassificationTranslationPK _pk = new TaxClassificationTranslationPK(txclsfntr_taxclassificationtranslationid); 230 231 // See if we already have the entity in the session cache 232 TaxClassificationTranslation _entity = (TaxClassificationTranslation)session.getEntity(_pk); 233 234 if(_entity == null) { 235 Long txclsfntr_txclsfn_taxclassificationid = rs.getLong(TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID); 236 if(rs.wasNull()) 237 txclsfntr_txclsfn_taxclassificationid = null; 238 239 Long txclsfntr_lang_languageid = rs.getLong(TXCLSFNTR_LANG_LANGUAGEID); 240 if(rs.wasNull()) 241 txclsfntr_lang_languageid = null; 242 243 String txclsfntr_description = rs.getString(TXCLSFNTR_DESCRIPTION); 244 if(rs.wasNull()) 245 txclsfntr_description = null; 246 247 Long txclsfntr_overviewmimetypeid = rs.getLong(TXCLSFNTR_OVERVIEWMIMETYPEID); 248 if(rs.wasNull()) 249 txclsfntr_overviewmimetypeid = null; 250 251 Clob txclsfntr_overview = rs.getClob(TXCLSFNTR_OVERVIEW); 252 if(rs.wasNull()) 253 txclsfntr_overview = null; 254 255 Long txclsfntr_fromtime = rs.getLong(TXCLSFNTR_FROMTIME); 256 if(rs.wasNull()) 257 txclsfntr_fromtime = null; 258 259 Long txclsfntr_thrutime = rs.getLong(TXCLSFNTR_THRUTIME); 260 if(rs.wasNull()) 261 txclsfntr_thrutime = null; 262 263 _value = new TaxClassificationTranslationValue(_pk, new TaxClassificationPK(txclsfntr_txclsfn_taxclassificationid), new LanguagePK(txclsfntr_lang_languageid), txclsfntr_description, new MimeTypePK(txclsfntr_overviewmimetypeid), txclsfntr_overview == null? null: txclsfntr_overview.getSubString(1L, (int)txclsfntr_overview.length()), txclsfntr_fromtime, txclsfntr_thrutime); 264 } else 265 _value = _entity.getTaxClassificationTranslationValue(); 266 } catch (SQLException se) { 267 throw new PersistenceDatabaseException(se); 268 } 269 270 return _value; 271 } 272 273 public java.util.List<TaxClassificationTranslation> getEntitiesFromPKs(EntityPermission entityPermission, Collection<TaxClassificationTranslationPK> pks) 274 throws PersistenceDatabaseException { 275 java.util.List<TaxClassificationTranslation> _entities = new ArrayList<>(pks.size()); 276 277 for(TaxClassificationTranslationPK _pk: pks) { 278 _entities.add(getEntityFromPK(entityPermission, _pk)); 279 } 280 281 return _entities; 282 } 283 284 public TaxClassificationTranslation getEntityFromValue(EntityPermission entityPermission, TaxClassificationTranslationValue value) { 285 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 286 } 287 288 public TaxClassificationTranslation getEntityFromCache(TaxClassificationTranslationPK pk) { 289 TaxClassificationTranslationValue _value = (TaxClassificationTranslationValue)session.getValueCache().get(pk); 290 291 return _value == null ? null : new TaxClassificationTranslation(_value, EntityPermission.READ_ONLY); 292 } 293 294 public TaxClassificationTranslation getEntityFromPK(EntityPermission entityPermission, TaxClassificationTranslationPK pk) 295 throws PersistenceDatabaseException { 296 TaxClassificationTranslation _entity; 297 298 // See if we already have the entity in the session cache 299 _entity = (TaxClassificationTranslation)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<TaxClassificationTranslationPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 342 throws PersistenceDatabaseException { 343 Set<TaxClassificationTranslationPK> _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<TaxClassificationTranslationPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 370 throws PersistenceDatabaseException { 371 java.util.List<TaxClassificationTranslationPK> _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 TaxClassificationTranslationPK getPKFromQuery(PreparedStatement ps, final Object... params) 398 throws PersistenceDatabaseException { 399 TaxClassificationTranslationPK _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<TaxClassificationTranslation> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 428 throws PersistenceDatabaseException { 429 PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, queryMap.get(entityPermission)); 430 431 return getEntitiesFromQuery(entityPermission, ps, params); 432 } 433 434 public java.util.List<TaxClassificationTranslation> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 435 throws PersistenceDatabaseException { 436 PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, queryMap.get(entityPermission)); 437 438 return getEntitiesFromQuery(entityPermission, ps); 439 } 440 441 public java.util.List<TaxClassificationTranslation> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 442 throws PersistenceDatabaseException { 443 java.util.List<TaxClassificationTranslation> _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 TaxClassificationTranslation getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 470 throws PersistenceDatabaseException { 471 PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, queryMap.get(entityPermission)); 472 473 return getEntityFromQuery(entityPermission, ps, params); 474 } 475 476 public TaxClassificationTranslation getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 477 throws PersistenceDatabaseException { 478 PreparedStatement ps = session.prepareStatement(TaxClassificationTranslationFactory.class, queryMap.get(entityPermission)); 479 480 return getEntityFromQuery(entityPermission, ps); 481 } 482 483 public TaxClassificationTranslation getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 484 throws PersistenceDatabaseException { 485 TaxClassificationTranslation _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<TaxClassificationTranslation> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 514 throws PersistenceDatabaseException { 515 java.util.List<TaxClassificationTranslation> _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 TaxClassificationTranslation getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 529 throws PersistenceDatabaseException { 530 TaxClassificationTranslation _entity; 531 532 try { 533 Long txclsfntr_taxclassificationtranslationid = rs.getLong(TXCLSFNTR_TAXCLASSIFICATIONTRANSLATIONID); 534 TaxClassificationTranslationPK _pk = new TaxClassificationTranslationPK(txclsfntr_taxclassificationtranslationid); 535 536 // See if we already have the entity in the session cache 537 _entity = (TaxClassificationTranslation)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 txclsfntr_txclsfn_taxclassificationid = rs.getLong(TXCLSFNTR_TXCLSFN_TAXCLASSIFICATIONID); 555 if(rs.wasNull()) 556 txclsfntr_txclsfn_taxclassificationid = null; 557 558 Long txclsfntr_lang_languageid = rs.getLong(TXCLSFNTR_LANG_LANGUAGEID); 559 if(rs.wasNull()) 560 txclsfntr_lang_languageid = null; 561 562 String txclsfntr_description = rs.getString(TXCLSFNTR_DESCRIPTION); 563 if(rs.wasNull()) 564 txclsfntr_description = null; 565 566 Long txclsfntr_overviewmimetypeid = rs.getLong(TXCLSFNTR_OVERVIEWMIMETYPEID); 567 if(rs.wasNull()) 568 txclsfntr_overviewmimetypeid = null; 569 570 Clob txclsfntr_overview = rs.getClob(TXCLSFNTR_OVERVIEW); 571 if(rs.wasNull()) 572 txclsfntr_overview = null; 573 574 Long txclsfntr_fromtime = rs.getLong(TXCLSFNTR_FROMTIME); 575 if(rs.wasNull()) 576 txclsfntr_fromtime = null; 577 578 Long txclsfntr_thrutime = rs.getLong(TXCLSFNTR_THRUTIME); 579 if(rs.wasNull()) 580 txclsfntr_thrutime = null; 581 582 TaxClassificationTranslationValue _value = new TaxClassificationTranslationValue(_pk, txclsfntr_txclsfn_taxclassificationid == null? null: new TaxClassificationPK(txclsfntr_txclsfn_taxclassificationid), txclsfntr_lang_languageid == null? null: new LanguagePK(txclsfntr_lang_languageid), txclsfntr_description, txclsfntr_overviewmimetypeid == null? null: new MimeTypePK(txclsfntr_overviewmimetypeid), txclsfntr_overview == null? null: txclsfntr_overview.getSubString(1L, (int)txclsfntr_overview.length()), txclsfntr_fromtime, txclsfntr_thrutime); 583 _entity = new TaxClassificationTranslation(_value, entityPermission); 584 } 585 586 if(!foundInSessionCache) { 587 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 588 session.putReadOnlyEntity(_pk, _entity); 589 session.getValueCache().put(_entity.getTaxClassificationTranslationValue()); 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 TaxClassificationTranslation create(TaxClassification taxClassification, Language language, String description, MimeType overviewMimeType, String overview, Long fromTime, Long thruTime) 602 throws PersistenceDatabaseException, PersistenceNotNullException { 603 return create(taxClassification == null ? null : taxClassification.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, overviewMimeType == null ? null : overviewMimeType.getPrimaryKey(), overview, fromTime, thruTime); 604 } 605 606 private void bindForCreate(PreparedStatement _ps, TaxClassificationTranslationValue _value) 607 throws SQLException { 608 _ps.setLong(1, _value.getEntityId()); 609 610 TaxClassificationPK txclsfntr_txclsfn_taxclassificationid = _value.getTaxClassificationPK(); 611 if(txclsfntr_txclsfn_taxclassificationid == null) 612 _ps.setNull(2, Types.BIGINT); 613 else 614 _ps.setLong(2, txclsfntr_txclsfn_taxclassificationid.getEntityId()); 615 616 LanguagePK txclsfntr_lang_languageid = _value.getLanguagePK(); 617 if(txclsfntr_lang_languageid == null) 618 _ps.setNull(3, Types.BIGINT); 619 else 620 _ps.setLong(3, txclsfntr_lang_languageid.getEntityId()); 621 622 String txclsfntr_description = _value.getDescription(); 623 if(txclsfntr_description == null) 624 _ps.setNull(4, Types.VARCHAR); 625 else 626 _ps.setString(4, txclsfntr_description); 627 628 MimeTypePK txclsfntr_overviewmimetypeid = _value.getOverviewMimeTypePK(); 629 if(txclsfntr_overviewmimetypeid == null) 630 _ps.setNull(5, Types.BIGINT); 631 else 632 _ps.setLong(5, txclsfntr_overviewmimetypeid.getEntityId()); 633 634 String txclsfntr_overview = _value.getOverview(); 635 if(txclsfntr_overview == null) 636 _ps.setNull(6, Types.CLOB); 637 else 638 _ps.setCharacterStream(6, new StringReader(txclsfntr_overview), txclsfntr_overview.length()); 639 640 Long txclsfntr_fromtime = _value.getFromTime(); 641 if(txclsfntr_fromtime == null) 642 _ps.setNull(7, Types.BIGINT); 643 else 644 _ps.setLong(7, txclsfntr_fromtime); 645 646 Long txclsfntr_thrutime = _value.getThruTime(); 647 if(txclsfntr_thrutime == null) 648 _ps.setNull(8, Types.BIGINT); 649 else 650 _ps.setLong(8, txclsfntr_thrutime); 651 652 } 653 654 public TaxClassificationTranslation create(TaxClassificationPK taxClassificationPK, LanguagePK languagePK, String description, MimeTypePK overviewMimeTypePK, String overview, Long fromTime, Long thruTime) 655 throws PersistenceDatabaseException, PersistenceNotNullException { 656 TaxClassificationTranslationPK _pk = getNextPK(); 657 TaxClassificationTranslationValue _value = new TaxClassificationTranslationValue(_pk, taxClassificationPK, 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 TaxClassificationTranslation _entity = new TaxClassificationTranslation(_value, EntityPermission.READ_ONLY); 680 session.putReadOnlyEntity(_pk, _entity); 681 682 return _entity; 683 } 684 685 public void create(Collection<TaxClassificationTranslationValue> _values) 686 throws PersistenceDatabaseException, PersistenceNotNullException { 687 int _size = _values.size(); 688 689 if(_size > 0) { 690 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 691 List<TaxClassificationTranslationValue> _cacheValues = new ArrayList<>(_size); 692 693 try { 694 for(TaxClassificationTranslationValue _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 TaxClassificationTranslation _cacheEntity = new TaxClassificationTranslation(_cacheValue, EntityPermission.READ_ONLY); 722 723 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 724 }); 725 } 726 } 727 728 private boolean bindForStore(PreparedStatement _ps, TaxClassificationTranslationValue _value) 729 throws SQLException { 730 boolean _hasBeenModified = _value.hasBeenModified(); 731 732 if(_hasBeenModified) { 733 TaxClassificationPK txclsfntr_txclsfn_taxclassificationid = _value.getTaxClassificationPK(); 734 if(txclsfntr_txclsfn_taxclassificationid == null) 735 _ps.setNull(1, Types.BIGINT); 736 else 737 _ps.setLong(1, txclsfntr_txclsfn_taxclassificationid.getEntityId()); 738 739 LanguagePK txclsfntr_lang_languageid = _value.getLanguagePK(); 740 if(txclsfntr_lang_languageid == null) 741 _ps.setNull(2, Types.BIGINT); 742 else 743 _ps.setLong(2, txclsfntr_lang_languageid.getEntityId()); 744 745 String txclsfntr_description = _value.getDescription(); 746 if(txclsfntr_description == null) 747 _ps.setNull(3, Types.VARCHAR); 748 else 749 _ps.setString(3, txclsfntr_description); 750 751 MimeTypePK txclsfntr_overviewmimetypeid = _value.getOverviewMimeTypePK(); 752 if(txclsfntr_overviewmimetypeid == null) 753 _ps.setNull(4, Types.BIGINT); 754 else 755 _ps.setLong(4, txclsfntr_overviewmimetypeid.getEntityId()); 756 757 String txclsfntr_overview = _value.getOverview(); 758 if(txclsfntr_overview == null) 759 _ps.setNull(5, Types.CLOB); 760 else 761 _ps.setCharacterStream(5, new StringReader(txclsfntr_overview), txclsfntr_overview.length()); 762 763 Long txclsfntr_fromtime = _value.getFromTime(); 764 if(txclsfntr_fromtime == null) 765 _ps.setNull(6, Types.BIGINT); 766 else 767 _ps.setLong(6, txclsfntr_fromtime); 768 769 Long txclsfntr_thrutime = _value.getThruTime(); 770 if(txclsfntr_thrutime == null) 771 _ps.setNull(7, Types.BIGINT); 772 else 773 _ps.setLong(7, txclsfntr_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(TaxClassificationTranslation entity) 785 throws PersistenceDatabaseException { 786 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 787 788 try { 789 TaxClassificationTranslationValue _value = entity.getTaxClassificationTranslationValue(); 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<TaxClassificationTranslation> 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(TaxClassificationTranslation entity : entities) { 818 if(bindForStore(_ps, entity.getTaxClassificationTranslationValue())) { 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.getTaxClassificationTranslationValue()); 841 }); 842 } 843 } catch (SQLException se) { 844 throw new PersistenceDatabaseException(se); 845 } 846 } 847 } 848 849 @Override 850 public void remove(TaxClassificationTranslation entity) 851 throws PersistenceDatabaseException { 852 remove(entity.getPrimaryKey()); 853 } 854 855 @Override 856 public void remove(TaxClassificationTranslationPK 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<TaxClassificationTranslationPK> 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(TaxClassificationTranslationPK 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(TaxClassificationTranslationPK 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}