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