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 * CommentDetailFactory.java 021 */ 022 023package com.echothree.model.data.comment.server.factory; 024 025import com.echothree.model.data.comment.common.pk.CommentPK; 026import com.echothree.model.data.comment.common.pk.CommentTypePK; 027import com.echothree.model.data.core.common.pk.EntityInstancePK; 028import com.echothree.model.data.party.common.pk.LanguagePK; 029import com.echothree.model.data.core.common.pk.MimeTypePK; 030 031import com.echothree.model.data.comment.server.entity.Comment; 032import com.echothree.model.data.comment.server.entity.CommentType; 033import com.echothree.model.data.core.server.entity.EntityInstance; 034import com.echothree.model.data.party.server.entity.Language; 035import com.echothree.model.data.core.server.entity.MimeType; 036 037import com.echothree.model.data.comment.common.CommentDetailConstants; 038import com.echothree.model.data.comment.common.pk.CommentDetailPK; 039import com.echothree.model.data.comment.server.value.CommentDetailValue; 040import com.echothree.model.data.comment.server.entity.CommentDetail; 041import com.echothree.util.common.exception.PersistenceDatabaseException; 042import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 043import com.echothree.util.common.exception.PersistenceNotNullException; 044import com.echothree.util.server.persistence.BaseFactory; 045import com.echothree.util.server.persistence.EntityIdGenerator; 046import com.echothree.util.server.persistence.EntityPermission; 047import com.echothree.util.server.persistence.PersistenceDebugFlags; 048import com.echothree.util.server.persistence.Session; 049import java.sql.PreparedStatement; 050import java.sql.ResultSet; 051import java.sql.SQLException; 052import java.sql.Types; 053import java.io.ByteArrayInputStream; 054import java.io.StringReader; 055import java.util.ArrayList; 056import java.util.Collection; 057import java.util.HashSet; 058import java.util.List; 059import java.util.Map; 060import java.util.Set; 061import javax.enterprise.context.ApplicationScoped; 062import javax.enterprise.inject.spi.CDI; 063import javax.inject.Inject; 064import org.jooq.ResultQuery; 065import org.slf4j.Logger; 066import org.slf4j.LoggerFactory; 067 068@ApplicationScoped 069public class CommentDetailFactory 070 implements BaseFactory<CommentDetailPK, CommentDetail> { 071 072 @Inject 073 Session session; 074 075 //private static final Logger log = LoggerFactory.getLogger(CommentDetailFactory.class); 076 077 final private static String SQL_SELECT_READ_ONLY = "SELECT cmntdt_commentdetailid, cmntdt_cmnt_commentid, cmntdt_commentname, cmntdt_cmnttyp_commenttypeid, cmntdt_commentedentityinstanceid, cmntdt_commentedbyentityinstanceid, cmntdt_lang_languageid, cmntdt_description, cmntdt_mtyp_mimetypeid, cmntdt_fromtime, cmntdt_thrutime FROM commentdetails WHERE cmntdt_commentdetailid = ?"; 078 final private static String SQL_SELECT_READ_WRITE = "SELECT cmntdt_commentdetailid, cmntdt_cmnt_commentid, cmntdt_commentname, cmntdt_cmnttyp_commenttypeid, cmntdt_commentedentityinstanceid, cmntdt_commentedbyentityinstanceid, cmntdt_lang_languageid, cmntdt_description, cmntdt_mtyp_mimetypeid, cmntdt_fromtime, cmntdt_thrutime FROM commentdetails WHERE cmntdt_commentdetailid = ? FOR UPDATE"; 079 final private static String SQL_INSERT = "INSERT INTO commentdetails (cmntdt_commentdetailid, cmntdt_cmnt_commentid, cmntdt_commentname, cmntdt_cmnttyp_commenttypeid, cmntdt_commentedentityinstanceid, cmntdt_commentedbyentityinstanceid, cmntdt_lang_languageid, cmntdt_description, cmntdt_mtyp_mimetypeid, cmntdt_fromtime, cmntdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 080 final private static String SQL_UPDATE = "UPDATE commentdetails SET cmntdt_cmnt_commentid = ?, cmntdt_commentname = ?, cmntdt_cmnttyp_commenttypeid = ?, cmntdt_commentedentityinstanceid = ?, cmntdt_commentedbyentityinstanceid = ?, cmntdt_lang_languageid = ?, cmntdt_description = ?, cmntdt_mtyp_mimetypeid = ?, cmntdt_fromtime = ?, cmntdt_thrutime = ? WHERE cmntdt_commentdetailid = ?"; 081 final private static String SQL_DELETE = "DELETE FROM commentdetails WHERE cmntdt_commentdetailid = ?"; 082 final private static String SQL_VALID = "SELECT COUNT(*) FROM commentdetails WHERE cmntdt_commentdetailid = ?"; 083 084 final public static String CMNTDT_COMMENTDETAILID = "cmntdt_commentdetailid"; 085 final public static String CMNTDT_CMNT_COMMENTID = "cmntdt_cmnt_commentid"; 086 final public static String CMNTDT_COMMENTNAME = "cmntdt_commentname"; 087 final public static String CMNTDT_CMNTTYP_COMMENTTYPEID = "cmntdt_cmnttyp_commenttypeid"; 088 final public static String CMNTDT_COMMENTEDENTITYINSTANCEID = "cmntdt_commentedentityinstanceid"; 089 final public static String CMNTDT_COMMENTEDBYENTITYINSTANCEID = "cmntdt_commentedbyentityinstanceid"; 090 final public static String CMNTDT_LANG_LANGUAGEID = "cmntdt_lang_languageid"; 091 final public static String CMNTDT_DESCRIPTION = "cmntdt_description"; 092 final public static String CMNTDT_MTYP_MIMETYPEID = "cmntdt_mtyp_mimetypeid"; 093 final public static String CMNTDT_FROMTIME = "cmntdt_fromtime"; 094 final public static String CMNTDT_THRUTIME = "cmntdt_thrutime"; 095 096 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(CommentDetailConstants.COMPONENT_VENDOR_NAME, CommentDetailConstants.ENTITY_TYPE_NAME); 097 098 /** Creates a new instance of CommentDetailFactory */ 099 protected CommentDetailFactory() { 100 super(); 101 } 102 103 public static CommentDetailFactory getInstance() { 104 return CDI.current().select(CommentDetailFactory.class).get(); 105 } 106 107 @Override 108 public String getComponentVendorName() { 109 return CommentDetailConstants.COMPONENT_VENDOR_NAME; 110 } 111 112 @Override 113 public String getEntityTypeName() { 114 return CommentDetailConstants.ENTITY_TYPE_NAME; 115 } 116 117 public PreparedStatement prepareStatement(String query) { 118 return session.prepareStatement(query); 119 } 120 121 public CommentDetailPK getNextPK() { 122 return new CommentDetailPK(entityIdGenerator.getNextEntityId()); 123 } 124 125 public Set<CommentDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 126 throws PersistenceDatabaseException { 127 Set<CommentDetailPK> _result = new HashSet<>(); 128 129 try { 130 while(rs.next()) { 131 _result.add(getPKFromResultSet(rs)); 132 } 133 } catch (SQLException se) { 134 throw new PersistenceDatabaseException(se); 135 } 136 137 return _result; 138 } 139 140 public java.util.List<CommentDetailPK> getPKsFromResultSetAsList(ResultSet rs) 141 throws PersistenceDatabaseException { 142 java.util.List<CommentDetailPK> _result = new ArrayList<>(); 143 144 try { 145 while(rs.next()) { 146 _result.add(getPKFromResultSet(rs)); 147 } 148 } catch (SQLException se) { 149 throw new PersistenceDatabaseException(se); 150 } 151 152 return _result; 153 } 154 155 public CommentDetailPK getPKFromResultSet(ResultSet rs) 156 throws PersistenceDatabaseException { 157 CommentDetailPK _result; 158 159 try { 160 long cmntdt_commentdetailid = rs.getLong(CMNTDT_COMMENTDETAILID); 161 Long _entityId = rs.wasNull() ? null : cmntdt_commentdetailid; 162 163 _result = new CommentDetailPK(_entityId); 164 } catch (SQLException se) { 165 throw new PersistenceDatabaseException(se); 166 } 167 168 return _result; 169 } 170 171 public java.util.List<CommentDetailValue> getValuesFromPKs(Collection<CommentDetailPK> pks) 172 throws PersistenceDatabaseException { 173 java.util.List<CommentDetailValue> _values = new ArrayList<>(pks.size()); 174 175 for(CommentDetailPK _pk: pks) { 176 _values.add(getValueFromPK(_pk)); 177 } 178 179 return _values; 180 } 181 182 public CommentDetailValue getValueFromPK(CommentDetailPK pk) 183 throws PersistenceDatabaseException { 184 CommentDetailValue _value; 185 186 // See if we already have the entity in the session cache 187 CommentDetail _entity = (CommentDetail)session.getEntity(pk); 188 if(_entity == null) 189 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getCommentDetailValue(); 190 else 191 _value = _entity.getCommentDetailValue(); 192 193 return _value; 194 } 195 196 public java.util.List<CommentDetailValue> getValuesFromResultSet(ResultSet rs) 197 throws PersistenceDatabaseException { 198 java.util.List<CommentDetailValue> _result = new ArrayList<>(); 199 200 try { 201 while(rs.next()) { 202 _result.add(getValueFromResultSet(rs)); 203 } 204 } catch (SQLException se) { 205 throw new PersistenceDatabaseException(se); 206 } 207 208 return _result; 209 } 210 211 public CommentDetailValue getValueFromResultSet(ResultSet rs) 212 throws PersistenceDatabaseException { 213 CommentDetailValue _value; 214 215 try { 216 Long cmntdt_commentdetailid = rs.getLong(CMNTDT_COMMENTDETAILID); 217 CommentDetailPK _pk = new CommentDetailPK(cmntdt_commentdetailid); 218 219 // See if we already have the entity in the session cache 220 CommentDetail _entity = (CommentDetail)session.getEntity(_pk); 221 222 if(_entity == null) { 223 Long cmntdt_cmnt_commentid = rs.getLong(CMNTDT_CMNT_COMMENTID); 224 if(rs.wasNull()) 225 cmntdt_cmnt_commentid = null; 226 227 String cmntdt_commentname = rs.getString(CMNTDT_COMMENTNAME); 228 if(rs.wasNull()) 229 cmntdt_commentname = null; 230 231 Long cmntdt_cmnttyp_commenttypeid = rs.getLong(CMNTDT_CMNTTYP_COMMENTTYPEID); 232 if(rs.wasNull()) 233 cmntdt_cmnttyp_commenttypeid = null; 234 235 Long cmntdt_commentedentityinstanceid = rs.getLong(CMNTDT_COMMENTEDENTITYINSTANCEID); 236 if(rs.wasNull()) 237 cmntdt_commentedentityinstanceid = null; 238 239 Long cmntdt_commentedbyentityinstanceid = rs.getLong(CMNTDT_COMMENTEDBYENTITYINSTANCEID); 240 if(rs.wasNull()) 241 cmntdt_commentedbyentityinstanceid = null; 242 243 Long cmntdt_lang_languageid = rs.getLong(CMNTDT_LANG_LANGUAGEID); 244 if(rs.wasNull()) 245 cmntdt_lang_languageid = null; 246 247 String cmntdt_description = rs.getString(CMNTDT_DESCRIPTION); 248 if(rs.wasNull()) 249 cmntdt_description = null; 250 251 Long cmntdt_mtyp_mimetypeid = rs.getLong(CMNTDT_MTYP_MIMETYPEID); 252 if(rs.wasNull()) 253 cmntdt_mtyp_mimetypeid = null; 254 255 Long cmntdt_fromtime = rs.getLong(CMNTDT_FROMTIME); 256 if(rs.wasNull()) 257 cmntdt_fromtime = null; 258 259 Long cmntdt_thrutime = rs.getLong(CMNTDT_THRUTIME); 260 if(rs.wasNull()) 261 cmntdt_thrutime = null; 262 263 _value = new CommentDetailValue(_pk, new CommentPK(cmntdt_cmnt_commentid), cmntdt_commentname, new CommentTypePK(cmntdt_cmnttyp_commenttypeid), new EntityInstancePK(cmntdt_commentedentityinstanceid), new EntityInstancePK(cmntdt_commentedbyentityinstanceid), new LanguagePK(cmntdt_lang_languageid), cmntdt_description, new MimeTypePK(cmntdt_mtyp_mimetypeid), cmntdt_fromtime, cmntdt_thrutime); 264 } else 265 _value = _entity.getCommentDetailValue(); 266 } catch (SQLException se) { 267 throw new PersistenceDatabaseException(se); 268 } 269 270 return _value; 271 } 272 273 public java.util.List<CommentDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<CommentDetailPK> pks) 274 throws PersistenceDatabaseException { 275 java.util.List<CommentDetail> _entities = new ArrayList<>(pks.size()); 276 277 for(CommentDetailPK _pk: pks) { 278 _entities.add(getEntityFromPK(entityPermission, _pk)); 279 } 280 281 return _entities; 282 } 283 284 public CommentDetail getEntityFromValue(EntityPermission entityPermission, CommentDetailValue value) { 285 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 286 } 287 288 public CommentDetail getEntityFromCache(CommentDetailPK pk) { 289 CommentDetailValue _value = (CommentDetailValue)session.getValueCache().get(pk); 290 291 return _value == null ? null : new CommentDetail(_value, EntityPermission.READ_ONLY); 292 } 293 294 public CommentDetail getEntityFromPK(EntityPermission entityPermission, CommentDetailPK pk) 295 throws PersistenceDatabaseException { 296 CommentDetail _entity; 297 298 // See if we already have the entity in the session cache 299 _entity = (CommentDetail)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<CommentDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 342 throws PersistenceDatabaseException { 343 Set<CommentDetailPK> _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<CommentDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 370 throws PersistenceDatabaseException { 371 java.util.List<CommentDetailPK> _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 CommentDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 398 throws PersistenceDatabaseException { 399 CommentDetailPK _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<CommentDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 428 throws PersistenceDatabaseException { 429 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 430 431 return getEntitiesFromQuery(entityPermission, ps, params); 432 } 433 434 public java.util.List<CommentDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 435 throws PersistenceDatabaseException { 436 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 437 438 return getEntitiesFromQuery(entityPermission, ps); 439 } 440 441 public java.util.List<CommentDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 442 throws PersistenceDatabaseException { 443 PreparedStatement ps = session.prepareStatement(query.getSQL()); 444 445 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 446 } 447 448 public java.util.List<CommentDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 449 throws PersistenceDatabaseException { 450 java.util.List<CommentDetail> _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 CommentDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 477 throws PersistenceDatabaseException { 478 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 479 480 return getEntityFromQuery(entityPermission, ps, params); 481 } 482 483 public CommentDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 484 throws PersistenceDatabaseException { 485 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 486 487 return getEntityFromQuery(entityPermission, ps); 488 } 489 490 public CommentDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 491 throws PersistenceDatabaseException { 492 PreparedStatement ps = session.prepareStatement(query.getSQL()); 493 494 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 495 } 496 497 public CommentDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 498 throws PersistenceDatabaseException { 499 CommentDetail _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<CommentDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 528 throws PersistenceDatabaseException { 529 java.util.List<CommentDetail> _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 CommentDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 543 throws PersistenceDatabaseException { 544 CommentDetail _entity; 545 546 try { 547 Long cmntdt_commentdetailid = rs.getLong(CMNTDT_COMMENTDETAILID); 548 CommentDetailPK _pk = new CommentDetailPK(cmntdt_commentdetailid); 549 550 // See if we already have the entity in the session cache 551 _entity = (CommentDetail)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 cmntdt_cmnt_commentid = rs.getLong(CMNTDT_CMNT_COMMENTID); 569 if(rs.wasNull()) 570 cmntdt_cmnt_commentid = null; 571 572 String cmntdt_commentname = rs.getString(CMNTDT_COMMENTNAME); 573 if(rs.wasNull()) 574 cmntdt_commentname = null; 575 576 Long cmntdt_cmnttyp_commenttypeid = rs.getLong(CMNTDT_CMNTTYP_COMMENTTYPEID); 577 if(rs.wasNull()) 578 cmntdt_cmnttyp_commenttypeid = null; 579 580 Long cmntdt_commentedentityinstanceid = rs.getLong(CMNTDT_COMMENTEDENTITYINSTANCEID); 581 if(rs.wasNull()) 582 cmntdt_commentedentityinstanceid = null; 583 584 Long cmntdt_commentedbyentityinstanceid = rs.getLong(CMNTDT_COMMENTEDBYENTITYINSTANCEID); 585 if(rs.wasNull()) 586 cmntdt_commentedbyentityinstanceid = null; 587 588 Long cmntdt_lang_languageid = rs.getLong(CMNTDT_LANG_LANGUAGEID); 589 if(rs.wasNull()) 590 cmntdt_lang_languageid = null; 591 592 String cmntdt_description = rs.getString(CMNTDT_DESCRIPTION); 593 if(rs.wasNull()) 594 cmntdt_description = null; 595 596 Long cmntdt_mtyp_mimetypeid = rs.getLong(CMNTDT_MTYP_MIMETYPEID); 597 if(rs.wasNull()) 598 cmntdt_mtyp_mimetypeid = null; 599 600 Long cmntdt_fromtime = rs.getLong(CMNTDT_FROMTIME); 601 if(rs.wasNull()) 602 cmntdt_fromtime = null; 603 604 Long cmntdt_thrutime = rs.getLong(CMNTDT_THRUTIME); 605 if(rs.wasNull()) 606 cmntdt_thrutime = null; 607 608 CommentDetailValue _value = new CommentDetailValue(_pk, cmntdt_cmnt_commentid == null? null: new CommentPK(cmntdt_cmnt_commentid), cmntdt_commentname, cmntdt_cmnttyp_commenttypeid == null? null: new CommentTypePK(cmntdt_cmnttyp_commenttypeid), cmntdt_commentedentityinstanceid == null? null: new EntityInstancePK(cmntdt_commentedentityinstanceid), cmntdt_commentedbyentityinstanceid == null? null: new EntityInstancePK(cmntdt_commentedbyentityinstanceid), cmntdt_lang_languageid == null? null: new LanguagePK(cmntdt_lang_languageid), cmntdt_description, cmntdt_mtyp_mimetypeid == null? null: new MimeTypePK(cmntdt_mtyp_mimetypeid), cmntdt_fromtime, cmntdt_thrutime); 609 _entity = new CommentDetail(_value, entityPermission); 610 } 611 612 if(!foundInSessionCache) { 613 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 614 session.putReadOnlyEntity(_pk, _entity); 615 session.getValueCache().put(_entity.getCommentDetailValue()); 616 } else { 617 session.putReadWriteEntity(_pk, _entity); 618 } 619 } 620 } catch (SQLException se) { 621 throw new PersistenceDatabaseException(se); 622 } 623 624 return _entity; 625 } 626 627 public CommentDetail create(Comment comment, String commentName, CommentType commentType, EntityInstance commentedEntityInstance, EntityInstance commentedByEntityInstance, Language language, String description, MimeType mimeType, Long fromTime, Long thruTime) 628 throws PersistenceDatabaseException, PersistenceNotNullException { 629 return create(comment == null ? null : comment.getPrimaryKey(), commentName, commentType == null ? null : commentType.getPrimaryKey(), commentedEntityInstance == null ? null : commentedEntityInstance.getPrimaryKey(), commentedByEntityInstance == null ? null : commentedByEntityInstance.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, mimeType == null ? null : mimeType.getPrimaryKey(), fromTime, thruTime); 630 } 631 632 private void bindForCreate(PreparedStatement _ps, CommentDetailValue _value) 633 throws SQLException { 634 _ps.setLong(1, _value.getEntityId()); 635 636 CommentPK cmntdt_cmnt_commentid = _value.getCommentPK(); 637 if(cmntdt_cmnt_commentid == null) 638 _ps.setNull(2, Types.BIGINT); 639 else 640 _ps.setLong(2, cmntdt_cmnt_commentid.getEntityId()); 641 642 String cmntdt_commentname = _value.getCommentName(); 643 if(cmntdt_commentname == null) 644 _ps.setNull(3, Types.VARCHAR); 645 else 646 _ps.setString(3, cmntdt_commentname); 647 648 CommentTypePK cmntdt_cmnttyp_commenttypeid = _value.getCommentTypePK(); 649 if(cmntdt_cmnttyp_commenttypeid == null) 650 _ps.setNull(4, Types.BIGINT); 651 else 652 _ps.setLong(4, cmntdt_cmnttyp_commenttypeid.getEntityId()); 653 654 EntityInstancePK cmntdt_commentedentityinstanceid = _value.getCommentedEntityInstancePK(); 655 if(cmntdt_commentedentityinstanceid == null) 656 _ps.setNull(5, Types.BIGINT); 657 else 658 _ps.setLong(5, cmntdt_commentedentityinstanceid.getEntityId()); 659 660 EntityInstancePK cmntdt_commentedbyentityinstanceid = _value.getCommentedByEntityInstancePK(); 661 if(cmntdt_commentedbyentityinstanceid == null) 662 _ps.setNull(6, Types.BIGINT); 663 else 664 _ps.setLong(6, cmntdt_commentedbyentityinstanceid.getEntityId()); 665 666 LanguagePK cmntdt_lang_languageid = _value.getLanguagePK(); 667 if(cmntdt_lang_languageid == null) 668 _ps.setNull(7, Types.BIGINT); 669 else 670 _ps.setLong(7, cmntdt_lang_languageid.getEntityId()); 671 672 String cmntdt_description = _value.getDescription(); 673 if(cmntdt_description == null) 674 _ps.setNull(8, Types.VARCHAR); 675 else 676 _ps.setString(8, cmntdt_description); 677 678 MimeTypePK cmntdt_mtyp_mimetypeid = _value.getMimeTypePK(); 679 if(cmntdt_mtyp_mimetypeid == null) 680 _ps.setNull(9, Types.BIGINT); 681 else 682 _ps.setLong(9, cmntdt_mtyp_mimetypeid.getEntityId()); 683 684 Long cmntdt_fromtime = _value.getFromTime(); 685 if(cmntdt_fromtime == null) 686 _ps.setNull(10, Types.BIGINT); 687 else 688 _ps.setLong(10, cmntdt_fromtime); 689 690 Long cmntdt_thrutime = _value.getThruTime(); 691 if(cmntdt_thrutime == null) 692 _ps.setNull(11, Types.BIGINT); 693 else 694 _ps.setLong(11, cmntdt_thrutime); 695 696 } 697 698 public CommentDetail create(CommentPK commentPK, String commentName, CommentTypePK commentTypePK, EntityInstancePK commentedEntityInstancePK, EntityInstancePK commentedByEntityInstancePK, LanguagePK languagePK, String description, MimeTypePK mimeTypePK, Long fromTime, Long thruTime) 699 throws PersistenceDatabaseException, PersistenceNotNullException { 700 CommentDetailPK _pk = getNextPK(); 701 CommentDetailValue _value = new CommentDetailValue(_pk, commentPK, commentName, commentTypePK, commentedEntityInstancePK, commentedByEntityInstancePK, languagePK, description, mimeTypePK, fromTime, thruTime); 702 703 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 704 705 try { 706 bindForCreate(_ps, _value); 707 708 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 709 int _count = _ps.executeUpdate(); 710 711 if(_count != 1) { 712 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 713 } 714 } else { 715 _ps.executeUpdate(); 716 } 717 718 session.getValueCache().put(_value); 719 } catch (SQLException se) { 720 throw new PersistenceDatabaseException(se); 721 } 722 723 CommentDetail _entity = new CommentDetail(_value, EntityPermission.READ_ONLY); 724 session.putReadOnlyEntity(_pk, _entity); 725 726 return _entity; 727 } 728 729 public void create(Collection<CommentDetailValue> _values) 730 throws PersistenceDatabaseException, PersistenceNotNullException { 731 int _size = _values.size(); 732 733 if(_size > 0) { 734 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 735 List<CommentDetailValue> _cacheValues = new ArrayList<>(_size); 736 737 try { 738 for(CommentDetailValue _value : _values) { 739 _value.setEntityId(entityIdGenerator.getNextEntityId()); 740 bindForCreate(_ps, _value); 741 742 _ps.addBatch(); 743 744 _cacheValues.add(_value); 745 } 746 747 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 748 int[] _counts = _ps.executeBatch(); 749 750 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 751 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 752 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 753 } 754 } 755 } else { 756 _ps.executeBatch(); 757 } 758 759 _ps.clearBatch(); 760 } catch (SQLException se) { 761 throw new PersistenceDatabaseException(se); 762 } 763 764 _cacheValues.forEach((_cacheValue) -> { 765 CommentDetail _cacheEntity = new CommentDetail(_cacheValue, EntityPermission.READ_ONLY); 766 767 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 768 }); 769 } 770 } 771 772 private boolean bindForStore(PreparedStatement _ps, CommentDetailValue _value) 773 throws SQLException { 774 boolean _hasBeenModified = _value.hasBeenModified(); 775 776 if(_hasBeenModified) { 777 CommentPK cmntdt_cmnt_commentid = _value.getCommentPK(); 778 if(cmntdt_cmnt_commentid == null) 779 _ps.setNull(1, Types.BIGINT); 780 else 781 _ps.setLong(1, cmntdt_cmnt_commentid.getEntityId()); 782 783 String cmntdt_commentname = _value.getCommentName(); 784 if(cmntdt_commentname == null) 785 _ps.setNull(2, Types.VARCHAR); 786 else 787 _ps.setString(2, cmntdt_commentname); 788 789 CommentTypePK cmntdt_cmnttyp_commenttypeid = _value.getCommentTypePK(); 790 if(cmntdt_cmnttyp_commenttypeid == null) 791 _ps.setNull(3, Types.BIGINT); 792 else 793 _ps.setLong(3, cmntdt_cmnttyp_commenttypeid.getEntityId()); 794 795 EntityInstancePK cmntdt_commentedentityinstanceid = _value.getCommentedEntityInstancePK(); 796 if(cmntdt_commentedentityinstanceid == null) 797 _ps.setNull(4, Types.BIGINT); 798 else 799 _ps.setLong(4, cmntdt_commentedentityinstanceid.getEntityId()); 800 801 EntityInstancePK cmntdt_commentedbyentityinstanceid = _value.getCommentedByEntityInstancePK(); 802 if(cmntdt_commentedbyentityinstanceid == null) 803 _ps.setNull(5, Types.BIGINT); 804 else 805 _ps.setLong(5, cmntdt_commentedbyentityinstanceid.getEntityId()); 806 807 LanguagePK cmntdt_lang_languageid = _value.getLanguagePK(); 808 if(cmntdt_lang_languageid == null) 809 _ps.setNull(6, Types.BIGINT); 810 else 811 _ps.setLong(6, cmntdt_lang_languageid.getEntityId()); 812 813 String cmntdt_description = _value.getDescription(); 814 if(cmntdt_description == null) 815 _ps.setNull(7, Types.VARCHAR); 816 else 817 _ps.setString(7, cmntdt_description); 818 819 MimeTypePK cmntdt_mtyp_mimetypeid = _value.getMimeTypePK(); 820 if(cmntdt_mtyp_mimetypeid == null) 821 _ps.setNull(8, Types.BIGINT); 822 else 823 _ps.setLong(8, cmntdt_mtyp_mimetypeid.getEntityId()); 824 825 Long cmntdt_fromtime = _value.getFromTime(); 826 if(cmntdt_fromtime == null) 827 _ps.setNull(9, Types.BIGINT); 828 else 829 _ps.setLong(9, cmntdt_fromtime); 830 831 Long cmntdt_thrutime = _value.getThruTime(); 832 if(cmntdt_thrutime == null) 833 _ps.setNull(10, Types.BIGINT); 834 else 835 _ps.setLong(10, cmntdt_thrutime); 836 837 _ps.setLong(11, _value.getPrimaryKey().getEntityId()); 838 839 _value.clearHasBeenModified(); 840 } 841 842 return _hasBeenModified; 843 } 844 845 @Override 846 public void store(CommentDetail entity) 847 throws PersistenceDatabaseException { 848 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 849 850 try { 851 CommentDetailValue _value = entity.getCommentDetailValue(); 852 853 if(bindForStore(_ps, _value)) { 854 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 855 int _count = _ps.executeUpdate(); 856 857 if(_count != 1) { 858 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 859 } 860 } else { 861 _ps.executeUpdate(); 862 } 863 864 session.getValueCache().put(_value); 865 } 866 } catch (SQLException se) { 867 throw new PersistenceDatabaseException(se); 868 } 869 } 870 871 @Override 872 public void store(Collection<CommentDetail> entities) 873 throws PersistenceDatabaseException { 874 if(entities.size() > 0) { 875 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 876 int _modifiedEntities = 0; 877 878 try { 879 for(CommentDetail entity : entities) { 880 if(bindForStore(_ps, entity.getCommentDetailValue())) { 881 _ps.addBatch(); 882 _modifiedEntities++; 883 } 884 } 885 886 if(_modifiedEntities != 0) { 887 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 888 int[] _counts = _ps.executeBatch(); 889 890 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 891 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 892 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 893 } 894 } 895 } else { 896 _ps.executeBatch(); 897 } 898 899 _ps.clearBatch(); 900 901 entities.forEach((entity) -> { 902 session.getValueCache().put(entity.getCommentDetailValue()); 903 }); 904 } 905 } catch (SQLException se) { 906 throw new PersistenceDatabaseException(se); 907 } 908 } 909 } 910 911 @Override 912 public void remove(CommentDetail entity) 913 throws PersistenceDatabaseException { 914 remove(entity.getPrimaryKey()); 915 } 916 917 @Override 918 public void remove(CommentDetailPK pk) 919 throws PersistenceDatabaseException { 920 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 921 long _entityId = pk.getEntityId(); 922 923 try { 924 _ps.setLong(1, _entityId); 925 926 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 927 int _count = _ps.executeUpdate(); 928 929 if(_count != 1) { 930 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 931 } 932 } else { 933 _ps.executeUpdate(); 934 } 935 936 session.getValueCache().remove(pk); 937 } catch (SQLException se) { 938 throw new PersistenceDatabaseException(se); 939 } 940 941 session.removed(pk, false); 942 } 943 944 @Override 945 public void remove(Collection<CommentDetailPK> pks) 946 throws PersistenceDatabaseException { 947 if(pks.size() > 0) { 948 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 949 int _modifiedEntities = 0; 950 951 try { 952 for(CommentDetailPK pk : pks) { 953 long _entityId = pk.getEntityId(); 954 955 _ps.setLong(1, _entityId); 956 957 _ps.addBatch(); 958 _modifiedEntities++; 959 } 960 961 if(_modifiedEntities != 0) { 962 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 963 int[] _counts = _ps.executeBatch(); 964 965 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 966 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 967 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 968 } 969 } 970 } else { 971 _ps.executeBatch(); 972 } 973 974 _ps.clearBatch(); 975 976 pks.forEach((pk) -> { 977 session.getValueCache().remove(pk); 978 }); 979 } 980 } catch (SQLException se) { 981 throw new PersistenceDatabaseException(se); 982 } 983 984 pks.forEach((pk) -> { 985 session.removed(pk, true); 986 }); 987 } 988 } 989 990 @Override 991 public boolean validPK(CommentDetailPK pk) 992 throws PersistenceDatabaseException { 993 boolean valid = false; 994 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 995 ResultSet _rs = null; 996 997 try { 998 _ps.setLong(1, pk.getEntityId()); 999 1000 _rs = _ps.executeQuery(); 1001 if(_rs.next()) { 1002 long _count = _rs.getLong(1); 1003 if(_rs.wasNull()) 1004 _count = 0; 1005 1006 if(_count == 1) 1007 valid = true; 1008 } 1009 } catch (SQLException se) { 1010 throw new PersistenceDatabaseException(se); 1011 } finally { 1012 if(_rs != null) { 1013 try { 1014 _rs.close(); 1015 } catch (SQLException se) { 1016 // do nothing 1017 } 1018 } 1019 } 1020 1021 return valid; 1022 } 1023 1024}