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