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