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