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