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