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