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