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