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