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