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