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