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