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