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