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