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