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