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