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