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