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