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