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 * ScaleDetailFactory.java 021 */ 022 023package com.echothree.model.data.scale.server.factory; 024 025import com.echothree.model.data.scale.common.pk.ScalePK; 026import com.echothree.model.data.scale.common.pk.ScaleTypePK; 027import com.echothree.model.data.core.common.pk.ServerServicePK; 028 029import com.echothree.model.data.scale.server.entity.Scale; 030import com.echothree.model.data.scale.server.entity.ScaleType; 031import com.echothree.model.data.core.server.entity.ServerService; 032 033import com.echothree.model.data.scale.common.ScaleDetailConstants; 034import com.echothree.model.data.scale.common.pk.ScaleDetailPK; 035import com.echothree.model.data.scale.server.value.ScaleDetailValue; 036import com.echothree.model.data.scale.server.entity.ScaleDetail; 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 ScaleDetailFactory 066 implements BaseFactory<ScaleDetailPK, ScaleDetail> { 067 068 @Inject 069 Session session; 070 071 //private static final Logger log = LoggerFactory.getLogger(ScaleDetailFactory.class); 072 073 final private static String SQL_SELECT_READ_ONLY = "SELECT scldt_scaledetailid, scldt_scl_scaleid, scldt_scalename, scldt_scltyp_scaletypeid, scldt_servsrv_serverserviceid, scldt_isdefault, scldt_sortorder, scldt_fromtime, scldt_thrutime FROM scaledetails WHERE scldt_scaledetailid = ?"; 074 final private static String SQL_SELECT_READ_WRITE = "SELECT scldt_scaledetailid, scldt_scl_scaleid, scldt_scalename, scldt_scltyp_scaletypeid, scldt_servsrv_serverserviceid, scldt_isdefault, scldt_sortorder, scldt_fromtime, scldt_thrutime FROM scaledetails WHERE scldt_scaledetailid = ? FOR UPDATE"; 075 final private static String SQL_INSERT = "INSERT INTO scaledetails (scldt_scaledetailid, scldt_scl_scaleid, scldt_scalename, scldt_scltyp_scaletypeid, scldt_servsrv_serverserviceid, scldt_isdefault, scldt_sortorder, scldt_fromtime, scldt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"; 076 final private static String SQL_UPDATE = "UPDATE scaledetails SET scldt_scl_scaleid = ?, scldt_scalename = ?, scldt_scltyp_scaletypeid = ?, scldt_servsrv_serverserviceid = ?, scldt_isdefault = ?, scldt_sortorder = ?, scldt_fromtime = ?, scldt_thrutime = ? WHERE scldt_scaledetailid = ?"; 077 final private static String SQL_DELETE = "DELETE FROM scaledetails WHERE scldt_scaledetailid = ?"; 078 final private static String SQL_VALID = "SELECT COUNT(*) FROM scaledetails WHERE scldt_scaledetailid = ?"; 079 080 final private static String PK_COLUMN = "scldt_scaledetailid"; 081 final private static String ALL_COLUMNS = "scldt_scaledetailid, scldt_scl_scaleid, scldt_scalename, scldt_scltyp_scaletypeid, scldt_servsrv_serverserviceid, scldt_isdefault, scldt_sortorder, scldt_fromtime, scldt_thrutime"; 082 final public static String TABLE_NAME = "scaledetails"; 083 084 final public static String SCLDT_SCALEDETAILID = "scldt_scaledetailid"; 085 final public static String SCLDT_SCL_SCALEID = "scldt_scl_scaleid"; 086 final public static String SCLDT_SCALENAME = "scldt_scalename"; 087 final public static String SCLDT_SCLTYP_SCALETYPEID = "scldt_scltyp_scaletypeid"; 088 final public static String SCLDT_SERVSRV_SERVERSERVICEID = "scldt_servsrv_serverserviceid"; 089 final public static String SCLDT_ISDEFAULT = "scldt_isdefault"; 090 final public static String SCLDT_SORTORDER = "scldt_sortorder"; 091 final public static String SCLDT_FROMTIME = "scldt_fromtime"; 092 final public static String SCLDT_THRUTIME = "scldt_thrutime"; 093 094 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ScaleDetailConstants.COMPONENT_VENDOR_NAME, ScaleDetailConstants.ENTITY_TYPE_NAME); 095 096 /** Creates a new instance of ScaleDetailFactory */ 097 protected ScaleDetailFactory() { 098 super(); 099 } 100 101 public static ScaleDetailFactory getInstance() { 102 return CDI.current().select(ScaleDetailFactory.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 ScaleDetailConstants.COMPONENT_VENDOR_NAME; 123 } 124 125 @Override 126 public String getEntityTypeName() { 127 return ScaleDetailConstants.ENTITY_TYPE_NAME; 128 } 129 130 public PreparedStatement prepareStatement(String query) { 131 return session.prepareStatement(ScaleDetailFactory.class, query); 132 } 133 134 public ScaleDetailPK getNextPK() { 135 return new ScaleDetailPK(entityIdGenerator.getNextEntityId()); 136 } 137 138 public Set<ScaleDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 139 throws PersistenceDatabaseException { 140 Set<ScaleDetailPK> _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<ScaleDetailPK> getPKsFromResultSetAsList(ResultSet rs) 154 throws PersistenceDatabaseException { 155 java.util.List<ScaleDetailPK> _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 ScaleDetailPK getPKFromResultSet(ResultSet rs) 169 throws PersistenceDatabaseException { 170 ScaleDetailPK _result; 171 172 try { 173 long scldt_scaledetailid = rs.getLong(SCLDT_SCALEDETAILID); 174 Long _entityId = rs.wasNull() ? null : scldt_scaledetailid; 175 176 _result = new ScaleDetailPK(_entityId); 177 } catch (SQLException se) { 178 throw new PersistenceDatabaseException(se); 179 } 180 181 return _result; 182 } 183 184 public java.util.List<ScaleDetailValue> getValuesFromPKs(Collection<ScaleDetailPK> pks) 185 throws PersistenceDatabaseException { 186 java.util.List<ScaleDetailValue> _values = new ArrayList<>(pks.size()); 187 188 for(ScaleDetailPK _pk: pks) { 189 _values.add(getValueFromPK(_pk)); 190 } 191 192 return _values; 193 } 194 195 public ScaleDetailValue getValueFromPK(ScaleDetailPK pk) 196 throws PersistenceDatabaseException { 197 ScaleDetailValue _value; 198 199 // See if we already have the entity in the session cache 200 ScaleDetail _entity = (ScaleDetail)session.getEntity(pk); 201 if(_entity == null) 202 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getScaleDetailValue(); 203 else 204 _value = _entity.getScaleDetailValue(); 205 206 return _value; 207 } 208 209 public java.util.List<ScaleDetailValue> getValuesFromResultSet(ResultSet rs) 210 throws PersistenceDatabaseException { 211 java.util.List<ScaleDetailValue> _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 ScaleDetailValue getValueFromResultSet(ResultSet rs) 225 throws PersistenceDatabaseException { 226 ScaleDetailValue _value; 227 228 try { 229 Long scldt_scaledetailid = rs.getLong(SCLDT_SCALEDETAILID); 230 ScaleDetailPK _pk = new ScaleDetailPK(scldt_scaledetailid); 231 232 // See if we already have the entity in the session cache 233 ScaleDetail _entity = (ScaleDetail)session.getEntity(_pk); 234 235 if(_entity == null) { 236 Long scldt_scl_scaleid = rs.getLong(SCLDT_SCL_SCALEID); 237 if(rs.wasNull()) 238 scldt_scl_scaleid = null; 239 240 String scldt_scalename = rs.getString(SCLDT_SCALENAME); 241 if(rs.wasNull()) 242 scldt_scalename = null; 243 244 Long scldt_scltyp_scaletypeid = rs.getLong(SCLDT_SCLTYP_SCALETYPEID); 245 if(rs.wasNull()) 246 scldt_scltyp_scaletypeid = null; 247 248 Long scldt_servsrv_serverserviceid = rs.getLong(SCLDT_SERVSRV_SERVERSERVICEID); 249 if(rs.wasNull()) 250 scldt_servsrv_serverserviceid = null; 251 252 Boolean scldt_isdefault = rs.getInt(SCLDT_ISDEFAULT) == 1; 253 if(rs.wasNull()) 254 scldt_isdefault = null; 255 256 Integer scldt_sortorder = rs.getInt(SCLDT_SORTORDER); 257 if(rs.wasNull()) 258 scldt_sortorder = null; 259 260 Long scldt_fromtime = rs.getLong(SCLDT_FROMTIME); 261 if(rs.wasNull()) 262 scldt_fromtime = null; 263 264 Long scldt_thrutime = rs.getLong(SCLDT_THRUTIME); 265 if(rs.wasNull()) 266 scldt_thrutime = null; 267 268 _value = new ScaleDetailValue(_pk, new ScalePK(scldt_scl_scaleid), scldt_scalename, new ScaleTypePK(scldt_scltyp_scaletypeid), new ServerServicePK(scldt_servsrv_serverserviceid), scldt_isdefault, scldt_sortorder, scldt_fromtime, scldt_thrutime); 269 } else 270 _value = _entity.getScaleDetailValue(); 271 } catch (SQLException se) { 272 throw new PersistenceDatabaseException(se); 273 } 274 275 return _value; 276 } 277 278 public java.util.List<ScaleDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ScaleDetailPK> pks) 279 throws PersistenceDatabaseException { 280 java.util.List<ScaleDetail> _entities = new ArrayList<>(pks.size()); 281 282 for(ScaleDetailPK _pk: pks) { 283 _entities.add(getEntityFromPK(entityPermission, _pk)); 284 } 285 286 return _entities; 287 } 288 289 public ScaleDetail getEntityFromValue(EntityPermission entityPermission, ScaleDetailValue value) { 290 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 291 } 292 293 public ScaleDetail getEntityFromCache(ScaleDetailPK pk) { 294 ScaleDetailValue _value = (ScaleDetailValue)session.getValueCache().get(pk); 295 296 return _value == null ? null : new ScaleDetail(_value, EntityPermission.READ_ONLY); 297 } 298 299 public ScaleDetail getEntityFromPK(EntityPermission entityPermission, ScaleDetailPK pk) 300 throws PersistenceDatabaseException { 301 ScaleDetail _entity; 302 303 // See if we already have the entity in the session cache 304 _entity = (ScaleDetail)session.getEntity(pk); 305 if(_entity != null) { 306 // If the requested permission is READ_WRITE, and the cached permission is 307 // READ_ONLY, then pretend that the cached object wasn't found, and create 308 // a new entity that is READ_WRITE. 309 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 310 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 311 _entity = null; 312 } 313 } 314 315 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 316 _entity = getEntityFromCache(pk); 317 } 318 319 if(_entity == null) { 320 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 321 long _entityId = pk.getEntityId(); 322 ResultSet _rs = null; 323 324 try { 325 _ps.setLong(1, _entityId); 326 _rs = _ps.executeQuery(); 327 if(_rs.next()) { 328 _entity = getEntityFromResultSet(entityPermission, _rs); 329 } 330 } catch (SQLException se) { 331 throw new PersistenceDatabaseException(se); 332 } finally { 333 if(_rs != null) { 334 try { 335 _rs.close(); 336 } catch (SQLException se) { 337 // do nothing 338 } 339 } 340 } 341 } 342 343 return _entity; 344 } 345 346 public Set<ScaleDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 347 throws PersistenceDatabaseException { 348 Set<ScaleDetailPK> _pks; 349 ResultSet _rs = null; 350 351 try { 352 if(params.length != 0) { 353 Session.setQueryParams(ps, params); 354 } 355 356 _rs = ps.executeQuery(); 357 _pks = getPKsFromResultSetAsSet(_rs); 358 _rs.close(); 359 } catch (SQLException se) { 360 throw new PersistenceDatabaseException(se); 361 } finally { 362 if(_rs != null) { 363 try { 364 _rs.close(); 365 } catch (SQLException se) { 366 // do nothing 367 } 368 } 369 } 370 371 return _pks; 372 } 373 374 public java.util.List<ScaleDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 375 throws PersistenceDatabaseException { 376 java.util.List<ScaleDetailPK> _pks; 377 ResultSet _rs = null; 378 379 try { 380 if(params.length != 0) { 381 Session.setQueryParams(ps, params); 382 } 383 384 _rs = ps.executeQuery(); 385 _pks = getPKsFromResultSetAsList(_rs); 386 _rs.close(); 387 } catch (SQLException se) { 388 throw new PersistenceDatabaseException(se); 389 } finally { 390 if(_rs != null) { 391 try { 392 _rs.close(); 393 } catch (SQLException se) { 394 // do nothing 395 } 396 } 397 } 398 399 return _pks; 400 } 401 402 public ScaleDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 403 throws PersistenceDatabaseException { 404 ScaleDetailPK _pk = null; 405 ResultSet _rs = null; 406 407 try { 408 if(params.length != 0) { 409 Session.setQueryParams(ps, params); 410 } 411 412 _rs = ps.executeQuery(); 413 if(_rs.next()) { 414 _pk = getPKFromResultSet(_rs); 415 } 416 _rs.close(); 417 } catch (SQLException se) { 418 throw new PersistenceDatabaseException(se); 419 } finally { 420 if(_rs != null) { 421 try { 422 _rs.close(); 423 } catch (SQLException se) { 424 // do nothing 425 } 426 } 427 } 428 429 return _pk; 430 } 431 432 public java.util.List<ScaleDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 433 throws PersistenceDatabaseException { 434 PreparedStatement ps = session.prepareStatement(ScaleDetailFactory.class, queryMap.get(entityPermission)); 435 436 return getEntitiesFromQuery(entityPermission, ps, params); 437 } 438 439 public java.util.List<ScaleDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 440 throws PersistenceDatabaseException { 441 PreparedStatement ps = session.prepareStatement(ScaleDetailFactory.class, queryMap.get(entityPermission)); 442 443 return getEntitiesFromQuery(entityPermission, ps); 444 } 445 446 public java.util.List<ScaleDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 447 throws PersistenceDatabaseException { 448 PreparedStatement ps = session.prepareStatement(ScaleDetailFactory.class, query.getSQL()); 449 450 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 451 } 452 453 public java.util.List<ScaleDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 454 throws PersistenceDatabaseException { 455 java.util.List<ScaleDetail> _entities; 456 ResultSet _rs = null; 457 458 try { 459 if(params.length != 0) { 460 Session.setQueryParams(ps, params); 461 } 462 463 _rs = ps.executeQuery(); 464 _entities = getEntitiesFromResultSet(entityPermission, _rs); 465 _rs.close(); 466 } catch (SQLException se) { 467 throw new PersistenceDatabaseException(se); 468 } finally { 469 if(_rs != null) { 470 try { 471 _rs.close(); 472 } catch (SQLException se) { 473 // do nothing 474 } 475 } 476 } 477 478 return _entities; 479 } 480 481 public ScaleDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 482 throws PersistenceDatabaseException { 483 PreparedStatement ps = session.prepareStatement(ScaleDetailFactory.class, queryMap.get(entityPermission)); 484 485 return getEntityFromQuery(entityPermission, ps, params); 486 } 487 488 public ScaleDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 489 throws PersistenceDatabaseException { 490 PreparedStatement ps = session.prepareStatement(ScaleDetailFactory.class, queryMap.get(entityPermission)); 491 492 return getEntityFromQuery(entityPermission, ps); 493 } 494 495 public ScaleDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 496 throws PersistenceDatabaseException { 497 PreparedStatement ps = session.prepareStatement(ScaleDetailFactory.class, query.getSQL()); 498 499 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 500 } 501 502 public ScaleDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 503 throws PersistenceDatabaseException { 504 ScaleDetail _entity = null; 505 ResultSet _rs = null; 506 507 try { 508 if(params.length != 0) { 509 Session.setQueryParams(ps, params); 510 } 511 512 _rs = ps.executeQuery(); 513 if(_rs.next()) { 514 _entity = getEntityFromResultSet(entityPermission, _rs); 515 } 516 _rs.close(); 517 } catch (SQLException se) { 518 throw new PersistenceDatabaseException(se); 519 } finally { 520 if(_rs != null) { 521 try { 522 _rs.close(); 523 } catch (SQLException se) { 524 // do nothing 525 } 526 } 527 } 528 529 return _entity; 530 } 531 532 public java.util.List<ScaleDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 533 throws PersistenceDatabaseException { 534 java.util.List<ScaleDetail> _result = new ArrayList<>(); 535 536 try { 537 while(rs.next()) { 538 _result.add(getEntityFromResultSet(entityPermission, rs)); 539 } 540 } catch (SQLException se) { 541 throw new PersistenceDatabaseException(se); 542 } 543 544 return _result; 545 } 546 547 public ScaleDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 548 throws PersistenceDatabaseException { 549 ScaleDetail _entity; 550 551 try { 552 Long scldt_scaledetailid = rs.getLong(SCLDT_SCALEDETAILID); 553 ScaleDetailPK _pk = new ScaleDetailPK(scldt_scaledetailid); 554 555 // See if we already have the entity in the session cache 556 _entity = (ScaleDetail)session.getEntity(_pk); 557 if(_entity != null) { 558 // If the requested permission is READ_WRITE, and the cached permission is 559 // READ_ONLY, then pretend that the cached object wasn't found, and create 560 // a new entity that is READ_WRITE. 561 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 562 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 563 _entity = null; 564 } 565 } 566 boolean foundInSessionCache = _entity != null; 567 568 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 569 _entity = getEntityFromCache(_pk); 570 } 571 572 if(_entity == null) { 573 Long scldt_scl_scaleid = rs.getLong(SCLDT_SCL_SCALEID); 574 if(rs.wasNull()) 575 scldt_scl_scaleid = null; 576 577 String scldt_scalename = rs.getString(SCLDT_SCALENAME); 578 if(rs.wasNull()) 579 scldt_scalename = null; 580 581 Long scldt_scltyp_scaletypeid = rs.getLong(SCLDT_SCLTYP_SCALETYPEID); 582 if(rs.wasNull()) 583 scldt_scltyp_scaletypeid = null; 584 585 Long scldt_servsrv_serverserviceid = rs.getLong(SCLDT_SERVSRV_SERVERSERVICEID); 586 if(rs.wasNull()) 587 scldt_servsrv_serverserviceid = null; 588 589 Boolean scldt_isdefault = rs.getInt(SCLDT_ISDEFAULT) == 1; 590 if(rs.wasNull()) 591 scldt_isdefault = null; 592 593 Integer scldt_sortorder = rs.getInt(SCLDT_SORTORDER); 594 if(rs.wasNull()) 595 scldt_sortorder = null; 596 597 Long scldt_fromtime = rs.getLong(SCLDT_FROMTIME); 598 if(rs.wasNull()) 599 scldt_fromtime = null; 600 601 Long scldt_thrutime = rs.getLong(SCLDT_THRUTIME); 602 if(rs.wasNull()) 603 scldt_thrutime = null; 604 605 ScaleDetailValue _value = new ScaleDetailValue(_pk, scldt_scl_scaleid == null? null: new ScalePK(scldt_scl_scaleid), scldt_scalename, scldt_scltyp_scaletypeid == null? null: new ScaleTypePK(scldt_scltyp_scaletypeid), scldt_servsrv_serverserviceid == null? null: new ServerServicePK(scldt_servsrv_serverserviceid), scldt_isdefault, scldt_sortorder, scldt_fromtime, scldt_thrutime); 606 _entity = new ScaleDetail(_value, entityPermission); 607 } 608 609 if(!foundInSessionCache) { 610 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 611 session.putReadOnlyEntity(_pk, _entity); 612 session.getValueCache().put(_entity.getScaleDetailValue()); 613 } else { 614 session.putReadWriteEntity(_pk, _entity); 615 } 616 } 617 } catch (SQLException se) { 618 throw new PersistenceDatabaseException(se); 619 } 620 621 return _entity; 622 } 623 624 public ScaleDetail create(Scale scale, String scaleName, ScaleType scaleType, ServerService serverService, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 625 throws PersistenceDatabaseException, PersistenceNotNullException { 626 return create(scale == null ? null : scale.getPrimaryKey(), scaleName, scaleType == null ? null : scaleType.getPrimaryKey(), serverService == null ? null : serverService.getPrimaryKey(), isDefault, sortOrder, fromTime, thruTime); 627 } 628 629 private void bindForCreate(PreparedStatement _ps, ScaleDetailValue _value) 630 throws SQLException { 631 _ps.setLong(1, _value.getEntityId()); 632 633 ScalePK scldt_scl_scaleid = _value.getScalePK(); 634 if(scldt_scl_scaleid == null) 635 _ps.setNull(2, Types.BIGINT); 636 else 637 _ps.setLong(2, scldt_scl_scaleid.getEntityId()); 638 639 String scldt_scalename = _value.getScaleName(); 640 if(scldt_scalename == null) 641 _ps.setNull(3, Types.VARCHAR); 642 else 643 _ps.setString(3, scldt_scalename); 644 645 ScaleTypePK scldt_scltyp_scaletypeid = _value.getScaleTypePK(); 646 if(scldt_scltyp_scaletypeid == null) 647 _ps.setNull(4, Types.BIGINT); 648 else 649 _ps.setLong(4, scldt_scltyp_scaletypeid.getEntityId()); 650 651 ServerServicePK scldt_servsrv_serverserviceid = _value.getServerServicePK(); 652 if(scldt_servsrv_serverserviceid == null) 653 _ps.setNull(5, Types.BIGINT); 654 else 655 _ps.setLong(5, scldt_servsrv_serverserviceid.getEntityId()); 656 657 Boolean scldt_isdefault = _value.getIsDefault(); 658 if(scldt_isdefault == null) 659 _ps.setNull(6, Types.BIT); 660 else 661 _ps.setInt(6, scldt_isdefault? 1: 0); 662 663 Integer scldt_sortorder = _value.getSortOrder(); 664 if(scldt_sortorder == null) 665 _ps.setNull(7, Types.INTEGER); 666 else 667 _ps.setInt(7, scldt_sortorder); 668 669 Long scldt_fromtime = _value.getFromTime(); 670 if(scldt_fromtime == null) 671 _ps.setNull(8, Types.BIGINT); 672 else 673 _ps.setLong(8, scldt_fromtime); 674 675 Long scldt_thrutime = _value.getThruTime(); 676 if(scldt_thrutime == null) 677 _ps.setNull(9, Types.BIGINT); 678 else 679 _ps.setLong(9, scldt_thrutime); 680 681 } 682 683 public ScaleDetail create(ScalePK scalePK, String scaleName, ScaleTypePK scaleTypePK, ServerServicePK serverServicePK, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 684 throws PersistenceDatabaseException, PersistenceNotNullException { 685 ScaleDetailPK _pk = getNextPK(); 686 ScaleDetailValue _value = new ScaleDetailValue(_pk, scalePK, scaleName, scaleTypePK, serverServicePK, isDefault, sortOrder, 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 ScaleDetail _entity = new ScaleDetail(_value, EntityPermission.READ_ONLY); 709 session.putReadOnlyEntity(_pk, _entity); 710 711 return _entity; 712 } 713 714 public void create(Collection<ScaleDetailValue> _values) 715 throws PersistenceDatabaseException, PersistenceNotNullException { 716 int _size = _values.size(); 717 718 if(_size > 0) { 719 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 720 List<ScaleDetailValue> _cacheValues = new ArrayList<>(_size); 721 722 try { 723 for(ScaleDetailValue _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 ScaleDetail _cacheEntity = new ScaleDetail(_cacheValue, EntityPermission.READ_ONLY); 751 752 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 753 }); 754 } 755 } 756 757 private boolean bindForStore(PreparedStatement _ps, ScaleDetailValue _value) 758 throws SQLException { 759 boolean _hasBeenModified = _value.hasBeenModified(); 760 761 if(_hasBeenModified) { 762 ScalePK scldt_scl_scaleid = _value.getScalePK(); 763 if(scldt_scl_scaleid == null) 764 _ps.setNull(1, Types.BIGINT); 765 else 766 _ps.setLong(1, scldt_scl_scaleid.getEntityId()); 767 768 String scldt_scalename = _value.getScaleName(); 769 if(scldt_scalename == null) 770 _ps.setNull(2, Types.VARCHAR); 771 else 772 _ps.setString(2, scldt_scalename); 773 774 ScaleTypePK scldt_scltyp_scaletypeid = _value.getScaleTypePK(); 775 if(scldt_scltyp_scaletypeid == null) 776 _ps.setNull(3, Types.BIGINT); 777 else 778 _ps.setLong(3, scldt_scltyp_scaletypeid.getEntityId()); 779 780 ServerServicePK scldt_servsrv_serverserviceid = _value.getServerServicePK(); 781 if(scldt_servsrv_serverserviceid == null) 782 _ps.setNull(4, Types.BIGINT); 783 else 784 _ps.setLong(4, scldt_servsrv_serverserviceid.getEntityId()); 785 786 Boolean scldt_isdefault = _value.getIsDefault(); 787 if(scldt_isdefault == null) 788 _ps.setNull(5, Types.BIT); 789 else 790 _ps.setInt(5, scldt_isdefault? 1: 0); 791 792 Integer scldt_sortorder = _value.getSortOrder(); 793 if(scldt_sortorder == null) 794 _ps.setNull(6, Types.INTEGER); 795 else 796 _ps.setInt(6, scldt_sortorder); 797 798 Long scldt_fromtime = _value.getFromTime(); 799 if(scldt_fromtime == null) 800 _ps.setNull(7, Types.BIGINT); 801 else 802 _ps.setLong(7, scldt_fromtime); 803 804 Long scldt_thrutime = _value.getThruTime(); 805 if(scldt_thrutime == null) 806 _ps.setNull(8, Types.BIGINT); 807 else 808 _ps.setLong(8, scldt_thrutime); 809 810 _ps.setLong(9, _value.getPrimaryKey().getEntityId()); 811 812 _value.clearHasBeenModified(); 813 } 814 815 return _hasBeenModified; 816 } 817 818 @Override 819 public void store(ScaleDetail entity) 820 throws PersistenceDatabaseException { 821 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 822 823 try { 824 ScaleDetailValue _value = entity.getScaleDetailValue(); 825 826 if(bindForStore(_ps, _value)) { 827 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 828 int _count = _ps.executeUpdate(); 829 830 if(_count != 1) { 831 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 832 } 833 } else { 834 _ps.executeUpdate(); 835 } 836 837 session.getValueCache().put(_value); 838 } 839 } catch (SQLException se) { 840 throw new PersistenceDatabaseException(se); 841 } 842 } 843 844 @Override 845 public void store(Collection<ScaleDetail> entities) 846 throws PersistenceDatabaseException { 847 if(entities.size() > 0) { 848 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 849 int _modifiedEntities = 0; 850 851 try { 852 for(ScaleDetail entity : entities) { 853 if(bindForStore(_ps, entity.getScaleDetailValue())) { 854 _ps.addBatch(); 855 _modifiedEntities++; 856 } 857 } 858 859 if(_modifiedEntities != 0) { 860 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 861 int[] _counts = _ps.executeBatch(); 862 863 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 864 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 865 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 866 } 867 } 868 } else { 869 _ps.executeBatch(); 870 } 871 872 _ps.clearBatch(); 873 874 entities.forEach((entity) -> { 875 session.getValueCache().put(entity.getScaleDetailValue()); 876 }); 877 } 878 } catch (SQLException se) { 879 throw new PersistenceDatabaseException(se); 880 } 881 } 882 } 883 884 @Override 885 public void remove(ScaleDetail entity) 886 throws PersistenceDatabaseException { 887 remove(entity.getPrimaryKey()); 888 } 889 890 @Override 891 public void remove(ScaleDetailPK pk) 892 throws PersistenceDatabaseException { 893 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 894 long _entityId = pk.getEntityId(); 895 896 try { 897 _ps.setLong(1, _entityId); 898 899 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 900 int _count = _ps.executeUpdate(); 901 902 if(_count != 1) { 903 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 904 } 905 } else { 906 _ps.executeUpdate(); 907 } 908 909 session.getValueCache().remove(pk); 910 } catch (SQLException se) { 911 throw new PersistenceDatabaseException(se); 912 } 913 914 session.removed(pk, false); 915 } 916 917 @Override 918 public void remove(Collection<ScaleDetailPK> pks) 919 throws PersistenceDatabaseException { 920 if(pks.size() > 0) { 921 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 922 int _modifiedEntities = 0; 923 924 try { 925 for(ScaleDetailPK pk : pks) { 926 long _entityId = pk.getEntityId(); 927 928 _ps.setLong(1, _entityId); 929 930 _ps.addBatch(); 931 _modifiedEntities++; 932 } 933 934 if(_modifiedEntities != 0) { 935 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 936 int[] _counts = _ps.executeBatch(); 937 938 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 939 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 940 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 941 } 942 } 943 } else { 944 _ps.executeBatch(); 945 } 946 947 _ps.clearBatch(); 948 949 pks.forEach((pk) -> { 950 session.getValueCache().remove(pk); 951 }); 952 } 953 } catch (SQLException se) { 954 throw new PersistenceDatabaseException(se); 955 } 956 957 pks.forEach((pk) -> { 958 session.removed(pk, true); 959 }); 960 } 961 } 962 963 @Override 964 public boolean validPK(ScaleDetailPK pk) 965 throws PersistenceDatabaseException { 966 boolean valid = false; 967 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 968 ResultSet _rs = null; 969 970 try { 971 _ps.setLong(1, pk.getEntityId()); 972 973 _rs = _ps.executeQuery(); 974 if(_rs.next()) { 975 long _count = _rs.getLong(1); 976 if(_rs.wasNull()) 977 _count = 0; 978 979 if(_count == 1) 980 valid = true; 981 } 982 } catch (SQLException se) { 983 throw new PersistenceDatabaseException(se); 984 } finally { 985 if(_rs != null) { 986 try { 987 _rs.close(); 988 } catch (SQLException se) { 989 // do nothing 990 } 991 } 992 } 993 994 return valid; 995 } 996 997}