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