001// -------------------------------------------------------------------------------- 002// Copyright 2002-2025 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * 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 com.echothree.util.server.persistence.ThreadSession; 050import java.sql.PreparedStatement; 051import java.sql.ResultSet; 052import java.sql.SQLException; 053import java.sql.Types; 054import java.io.ByteArrayInputStream; 055import java.io.StringReader; 056import java.util.ArrayList; 057import java.util.Collection; 058import java.util.HashSet; 059import java.util.List; 060import java.util.Map; 061import java.util.Set; 062import javax.enterprise.context.ApplicationScoped; 063import javax.enterprise.inject.spi.CDI; 064import org.apache.commons.logging.Log; 065import org.apache.commons.logging.LogFactory; 066 067@ApplicationScoped 068public class CommentDetailFactory 069 implements BaseFactory<CommentDetailPK, CommentDetail> { 070 071 //final private static Log log = LogFactory.getLog(CommentDetailFactory.class); 072 073 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 = ?"; 074 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"; 075 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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 076 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 = ?"; 077 final private static String SQL_DELETE = "DELETE FROM commentdetails WHERE cmntdt_commentdetailid = ?"; 078 final private static String SQL_VALID = "SELECT COUNT(*) FROM commentdetails WHERE cmntdt_commentdetailid = ?"; 079 080 final private static String PK_COLUMN = "cmntdt_commentdetailid"; 081 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"; 082 final public static String TABLE_NAME = "commentdetails"; 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 getPKColumn() { 109 return PK_COLUMN; 110 } 111 112 @Override 113 public String getAllColumns() { 114 return ALL_COLUMNS; 115 } 116 117 @Override 118 public String getTableName() { 119 return TABLE_NAME; 120 } 121 122 @Override 123 public String getComponentVendorName() { 124 return CommentDetailConstants.COMPONENT_VENDOR_NAME; 125 } 126 127 @Override 128 public String getEntityTypeName() { 129 return CommentDetailConstants.ENTITY_TYPE_NAME; 130 } 131 132 public PreparedStatement prepareStatement(String query) { 133 return ThreadSession.currentSession().prepareStatement(CommentDetailFactory.class, query); 134 } 135 136 public CommentDetailPK getNextPK() { 137 return new CommentDetailPK(entityIdGenerator.getNextEntityId()); 138 } 139 140 public Set<CommentDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 141 throws PersistenceDatabaseException { 142 Set<CommentDetailPK> _result = new HashSet<>(); 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 java.util.List<CommentDetailPK> getPKsFromResultSetAsList(ResultSet rs) 156 throws PersistenceDatabaseException { 157 java.util.List<CommentDetailPK> _result = new ArrayList<>(); 158 159 try { 160 while(rs.next()) { 161 _result.add(getPKFromResultSet(rs)); 162 } 163 } catch (SQLException se) { 164 throw new PersistenceDatabaseException(se); 165 } 166 167 return _result; 168 } 169 170 public CommentDetailPK getPKFromResultSet(ResultSet rs) 171 throws PersistenceDatabaseException { 172 CommentDetailPK _result; 173 174 try { 175 long cmntdt_commentdetailid = rs.getLong(CMNTDT_COMMENTDETAILID); 176 Long _entityId = rs.wasNull() ? null : cmntdt_commentdetailid; 177 178 _result = new CommentDetailPK(_entityId); 179 } catch (SQLException se) { 180 throw new PersistenceDatabaseException(se); 181 } 182 183 return _result; 184 } 185 186 public java.util.List<CommentDetailValue> getValuesFromPKs(Session session, Collection<CommentDetailPK> pks) 187 throws PersistenceDatabaseException { 188 java.util.List<CommentDetailValue> _values = new ArrayList<>(pks.size()); 189 190 for(CommentDetailPK _pk: pks) { 191 _values.add(getValueFromPK(session, _pk)); 192 } 193 194 return _values; 195 } 196 197 public CommentDetailValue getValueFromPK(Session session, CommentDetailPK pk) 198 throws PersistenceDatabaseException { 199 CommentDetailValue _value; 200 201 // See if we already have the entity in the session cache 202 CommentDetail _entity = (CommentDetail)session.getEntity(pk); 203 if(_entity == null) 204 _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getCommentDetailValue(); 205 else 206 _value = _entity.getCommentDetailValue(); 207 208 return _value; 209 } 210 211 public java.util.List<CommentDetailValue> getValuesFromResultSet(Session session, ResultSet rs) 212 throws PersistenceDatabaseException { 213 java.util.List<CommentDetailValue> _result = new ArrayList<>(); 214 215 try { 216 while(rs.next()) { 217 _result.add(getValueFromResultSet(session, rs)); 218 } 219 } catch (SQLException se) { 220 throw new PersistenceDatabaseException(se); 221 } 222 223 return _result; 224 } 225 226 public CommentDetailValue getValueFromResultSet(Session session, ResultSet rs) 227 throws PersistenceDatabaseException { 228 CommentDetailValue _value; 229 230 try { 231 Long cmntdt_commentdetailid = rs.getLong(CMNTDT_COMMENTDETAILID); 232 CommentDetailPK _pk = new CommentDetailPK(cmntdt_commentdetailid); 233 234 // See if we already have the entity in the session cache 235 CommentDetail _entity = (CommentDetail)session.getEntity(_pk); 236 237 if(_entity == null) { 238 Long cmntdt_cmnt_commentid = rs.getLong(CMNTDT_CMNT_COMMENTID); 239 if(rs.wasNull()) 240 cmntdt_cmnt_commentid = null; 241 242 String cmntdt_commentname = rs.getString(CMNTDT_COMMENTNAME); 243 if(rs.wasNull()) 244 cmntdt_commentname = null; 245 246 Long cmntdt_cmnttyp_commenttypeid = rs.getLong(CMNTDT_CMNTTYP_COMMENTTYPEID); 247 if(rs.wasNull()) 248 cmntdt_cmnttyp_commenttypeid = null; 249 250 Long cmntdt_commentedentityinstanceid = rs.getLong(CMNTDT_COMMENTEDENTITYINSTANCEID); 251 if(rs.wasNull()) 252 cmntdt_commentedentityinstanceid = null; 253 254 Long cmntdt_commentedbyentityinstanceid = rs.getLong(CMNTDT_COMMENTEDBYENTITYINSTANCEID); 255 if(rs.wasNull()) 256 cmntdt_commentedbyentityinstanceid = null; 257 258 Long cmntdt_lang_languageid = rs.getLong(CMNTDT_LANG_LANGUAGEID); 259 if(rs.wasNull()) 260 cmntdt_lang_languageid = null; 261 262 String cmntdt_description = rs.getString(CMNTDT_DESCRIPTION); 263 if(rs.wasNull()) 264 cmntdt_description = null; 265 266 Long cmntdt_mtyp_mimetypeid = rs.getLong(CMNTDT_MTYP_MIMETYPEID); 267 if(rs.wasNull()) 268 cmntdt_mtyp_mimetypeid = null; 269 270 Long cmntdt_fromtime = rs.getLong(CMNTDT_FROMTIME); 271 if(rs.wasNull()) 272 cmntdt_fromtime = null; 273 274 Long cmntdt_thrutime = rs.getLong(CMNTDT_THRUTIME); 275 if(rs.wasNull()) 276 cmntdt_thrutime = null; 277 278 _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); 279 } else 280 _value = _entity.getCommentDetailValue(); 281 } catch (SQLException se) { 282 throw new PersistenceDatabaseException(se); 283 } 284 285 return _value; 286 } 287 288 public java.util.List<CommentDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<CommentDetailPK> pks) 289 throws PersistenceDatabaseException { 290 return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks); 291 } 292 293 public java.util.List<CommentDetail> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<CommentDetailPK> pks) 294 throws PersistenceDatabaseException { 295 java.util.List<CommentDetail> _entities = new ArrayList<>(pks.size()); 296 297 for(CommentDetailPK _pk: pks) { 298 _entities.add(getEntityFromPK(session, entityPermission, _pk)); 299 } 300 301 return _entities; 302 } 303 304 public CommentDetail getEntityFromValue(EntityPermission entityPermission, CommentDetailValue value) { 305 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey()); 306 } 307 308 public CommentDetail getEntityFromValue(Session session, EntityPermission entityPermission, CommentDetailValue value) { 309 return getEntityFromPK(session, entityPermission, value.getPrimaryKey()); 310 } 311 312 public CommentDetail getEntityFromPK(EntityPermission entityPermission, CommentDetailPK pk) 313 throws PersistenceDatabaseException { 314 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk); 315 } 316 317 public CommentDetail getEntityFromCache(Session session, CommentDetailPK pk) { 318 CommentDetailValue _value = (CommentDetailValue)session.getValueCache().get(pk); 319 320 return _value == null ? null : new CommentDetail(_value, EntityPermission.READ_ONLY); 321 } 322 323 public CommentDetail getEntityFromPK(Session session, EntityPermission entityPermission, CommentDetailPK pk) 324 throws PersistenceDatabaseException { 325 CommentDetail _entity; 326 327 // See if we already have the entity in the session cache 328 _entity = (CommentDetail)session.getEntity(pk); 329 if(_entity != null) { 330 // If the requested permission is READ_WRITE, and the cached permission is 331 // READ_ONLY, then pretend that the cached object wasn't found, and create 332 // a new entity that is READ_WRITE. 333 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 334 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 335 _entity = null; 336 } 337 } 338 339 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 340 _entity = getEntityFromCache(session, pk); 341 } 342 343 if(_entity == null) { 344 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 345 long _entityId = pk.getEntityId(); 346 ResultSet _rs = null; 347 348 try { 349 _ps.setLong(1, _entityId); 350 _rs = _ps.executeQuery(); 351 if(_rs.next()) { 352 _entity = getEntityFromResultSet(session, entityPermission, _rs); 353 } 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 367 return _entity; 368 } 369 370 public Set<CommentDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 371 throws PersistenceDatabaseException { 372 Set<CommentDetailPK> _pks; 373 ResultSet _rs = null; 374 375 try { 376 if(params.length != 0) { 377 Session.setQueryParams(ps, params); 378 } 379 380 _rs = ps.executeQuery(); 381 _pks = getPKsFromResultSetAsSet(_rs); 382 _rs.close(); 383 } catch (SQLException se) { 384 throw new PersistenceDatabaseException(se); 385 } finally { 386 if(_rs != null) { 387 try { 388 _rs.close(); 389 } catch (SQLException se) { 390 // do nothing 391 } 392 } 393 } 394 395 return _pks; 396 } 397 398 public java.util.List<CommentDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 399 throws PersistenceDatabaseException { 400 java.util.List<CommentDetailPK> _pks; 401 ResultSet _rs = null; 402 403 try { 404 if(params.length != 0) { 405 Session.setQueryParams(ps, params); 406 } 407 408 _rs = ps.executeQuery(); 409 _pks = getPKsFromResultSetAsList(_rs); 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 _pks; 424 } 425 426 public CommentDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 427 throws PersistenceDatabaseException { 428 CommentDetailPK _pk = null; 429 ResultSet _rs = null; 430 431 try { 432 if(params.length != 0) { 433 Session.setQueryParams(ps, params); 434 } 435 436 _rs = ps.executeQuery(); 437 if(_rs.next()) { 438 _pk = getPKFromResultSet(_rs); 439 } 440 _rs.close(); 441 } catch (SQLException se) { 442 throw new PersistenceDatabaseException(se); 443 } finally { 444 if(_rs != null) { 445 try { 446 _rs.close(); 447 } catch (SQLException se) { 448 // do nothing 449 } 450 } 451 } 452 453 return _pk; 454 } 455 456 public java.util.List<CommentDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 457 throws PersistenceDatabaseException { 458 PreparedStatement ps = session.prepareStatement(CommentDetailFactory.class, queryMap.get(entityPermission)); 459 460 return getEntitiesFromQuery(session, entityPermission, ps, params); 461 } 462 463 public java.util.List<CommentDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 464 throws PersistenceDatabaseException { 465 Session session = ThreadSession.currentSession(); 466 PreparedStatement ps = session.prepareStatement(CommentDetailFactory.class, queryMap.get(entityPermission)); 467 468 return getEntitiesFromQuery(session, entityPermission, ps, params); 469 } 470 471 public java.util.List<CommentDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 472 throws PersistenceDatabaseException { 473 PreparedStatement ps = session.prepareStatement(CommentDetailFactory.class, queryMap.get(entityPermission)); 474 475 return getEntitiesFromQuery(session, entityPermission, ps); 476 } 477 478 public java.util.List<CommentDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 479 throws PersistenceDatabaseException { 480 Session session = ThreadSession.currentSession(); 481 PreparedStatement ps = session.prepareStatement(CommentDetailFactory.class, queryMap.get(entityPermission)); 482 483 return getEntitiesFromQuery(session, entityPermission, ps); 484 } 485 486 public java.util.List<CommentDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps) 487 throws PersistenceDatabaseException { 488 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps); 489 } 490 491 public java.util.List<CommentDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 492 throws PersistenceDatabaseException { 493 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 494 } 495 496 public java.util.List<CommentDetail> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 497 throws PersistenceDatabaseException { 498 java.util.List<CommentDetail> _entities; 499 ResultSet _rs = null; 500 501 try { 502 if(params.length != 0) { 503 Session.setQueryParams(ps, params); 504 } 505 506 _rs = ps.executeQuery(); 507 _entities = getEntitiesFromResultSet(session, entityPermission, _rs); 508 _rs.close(); 509 } catch (SQLException se) { 510 throw new PersistenceDatabaseException(se); 511 } finally { 512 if(_rs != null) { 513 try { 514 _rs.close(); 515 } catch (SQLException se) { 516 // do nothing 517 } 518 } 519 } 520 521 return _entities; 522 } 523 524 public CommentDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 525 throws PersistenceDatabaseException { 526 PreparedStatement ps = session.prepareStatement(CommentDetailFactory.class, queryMap.get(entityPermission)); 527 528 return getEntityFromQuery(session, entityPermission, ps, params); 529 } 530 531 public CommentDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 532 throws PersistenceDatabaseException { 533 Session session = ThreadSession.currentSession(); 534 PreparedStatement ps = session.prepareStatement(CommentDetailFactory.class, queryMap.get(entityPermission)); 535 536 return getEntityFromQuery(session, entityPermission, ps, params); 537 } 538 539 public CommentDetail getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 540 throws PersistenceDatabaseException { 541 PreparedStatement ps = session.prepareStatement(CommentDetailFactory.class, queryMap.get(entityPermission)); 542 543 return getEntityFromQuery(session, entityPermission, ps); 544 } 545 546 public CommentDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 547 throws PersistenceDatabaseException { 548 Session session = ThreadSession.currentSession(); 549 PreparedStatement ps = session.prepareStatement(CommentDetailFactory.class, queryMap.get(entityPermission)); 550 551 return getEntityFromQuery(session, entityPermission, ps); 552 } 553 554 public CommentDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps) 555 throws PersistenceDatabaseException { 556 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps); 557 } 558 559 public CommentDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 560 throws PersistenceDatabaseException { 561 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 562 } 563 564 public CommentDetail getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 565 throws PersistenceDatabaseException { 566 CommentDetail _entity = null; 567 ResultSet _rs = null; 568 569 try { 570 if(params.length != 0) { 571 Session.setQueryParams(ps, params); 572 } 573 574 _rs = ps.executeQuery(); 575 if(_rs.next()) { 576 _entity = getEntityFromResultSet(session, entityPermission, _rs); 577 } 578 _rs.close(); 579 } catch (SQLException se) { 580 throw new PersistenceDatabaseException(se); 581 } finally { 582 if(_rs != null) { 583 try { 584 _rs.close(); 585 } catch (SQLException se) { 586 // do nothing 587 } 588 } 589 } 590 591 return _entity; 592 } 593 594 public java.util.List<CommentDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 595 throws PersistenceDatabaseException { 596 return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 597 } 598 599 public java.util.List<CommentDetail> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 600 throws PersistenceDatabaseException { 601 java.util.List<CommentDetail> _result = new ArrayList<>(); 602 603 try { 604 while(rs.next()) { 605 _result.add(getEntityFromResultSet(session, entityPermission, rs)); 606 } 607 } catch (SQLException se) { 608 throw new PersistenceDatabaseException(se); 609 } 610 611 return _result; 612 } 613 614 public CommentDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 615 throws PersistenceDatabaseException { 616 return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 617 } 618 619 public CommentDetail getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 620 throws PersistenceDatabaseException { 621 CommentDetail _entity; 622 623 try { 624 Long cmntdt_commentdetailid = rs.getLong(CMNTDT_COMMENTDETAILID); 625 CommentDetailPK _pk = new CommentDetailPK(cmntdt_commentdetailid); 626 627 // See if we already have the entity in the session cache 628 _entity = (CommentDetail)session.getEntity(_pk); 629 if(_entity != null) { 630 // If the requested permission is READ_WRITE, and the cached permission is 631 // READ_ONLY, then pretend that the cached object wasn't found, and create 632 // a new entity that is READ_WRITE. 633 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 634 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 635 _entity = null; 636 } 637 } 638 boolean foundInSessionCache = _entity != null; 639 640 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 641 _entity = getEntityFromCache(session, _pk); 642 } 643 644 if(_entity == null) { 645 Long cmntdt_cmnt_commentid = rs.getLong(CMNTDT_CMNT_COMMENTID); 646 if(rs.wasNull()) 647 cmntdt_cmnt_commentid = null; 648 649 String cmntdt_commentname = rs.getString(CMNTDT_COMMENTNAME); 650 if(rs.wasNull()) 651 cmntdt_commentname = null; 652 653 Long cmntdt_cmnttyp_commenttypeid = rs.getLong(CMNTDT_CMNTTYP_COMMENTTYPEID); 654 if(rs.wasNull()) 655 cmntdt_cmnttyp_commenttypeid = null; 656 657 Long cmntdt_commentedentityinstanceid = rs.getLong(CMNTDT_COMMENTEDENTITYINSTANCEID); 658 if(rs.wasNull()) 659 cmntdt_commentedentityinstanceid = null; 660 661 Long cmntdt_commentedbyentityinstanceid = rs.getLong(CMNTDT_COMMENTEDBYENTITYINSTANCEID); 662 if(rs.wasNull()) 663 cmntdt_commentedbyentityinstanceid = null; 664 665 Long cmntdt_lang_languageid = rs.getLong(CMNTDT_LANG_LANGUAGEID); 666 if(rs.wasNull()) 667 cmntdt_lang_languageid = null; 668 669 String cmntdt_description = rs.getString(CMNTDT_DESCRIPTION); 670 if(rs.wasNull()) 671 cmntdt_description = null; 672 673 Long cmntdt_mtyp_mimetypeid = rs.getLong(CMNTDT_MTYP_MIMETYPEID); 674 if(rs.wasNull()) 675 cmntdt_mtyp_mimetypeid = null; 676 677 Long cmntdt_fromtime = rs.getLong(CMNTDT_FROMTIME); 678 if(rs.wasNull()) 679 cmntdt_fromtime = null; 680 681 Long cmntdt_thrutime = rs.getLong(CMNTDT_THRUTIME); 682 if(rs.wasNull()) 683 cmntdt_thrutime = null; 684 685 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); 686 _entity = new CommentDetail(_value, entityPermission); 687 } 688 689 if(!foundInSessionCache) { 690 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 691 session.putReadOnlyEntity(_pk, _entity); 692 session.getValueCache().put(_entity.getCommentDetailValue()); 693 } else { 694 session.putReadWriteEntity(_pk, _entity); 695 } 696 } 697 } catch (SQLException se) { 698 throw new PersistenceDatabaseException(se); 699 } 700 701 return _entity; 702 } 703 704 public CommentDetail create(Session session, Comment comment, String commentName, CommentType commentType, EntityInstance commentedEntityInstance, EntityInstance commentedByEntityInstance, Language language, String description, MimeType mimeType, Long fromTime, Long thruTime) 705 throws PersistenceDatabaseException, PersistenceNotNullException { 706 return create(session, 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); 707 } 708 709 public CommentDetail create(Comment comment, String commentName, CommentType commentType, EntityInstance commentedEntityInstance, EntityInstance commentedByEntityInstance, Language language, String description, MimeType mimeType, Long fromTime, Long thruTime) 710 throws PersistenceDatabaseException, PersistenceNotNullException { 711 return create(ThreadSession.currentSession(), 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); 712 } 713 714 private void bindForCreate(PreparedStatement _ps, CommentDetailValue _value) 715 throws SQLException { 716 _ps.setLong(1, _value.getEntityId()); 717 718 CommentPK cmntdt_cmnt_commentid = _value.getCommentPK(); 719 if(cmntdt_cmnt_commentid == null) 720 _ps.setNull(2, Types.BIGINT); 721 else 722 _ps.setLong(2, cmntdt_cmnt_commentid.getEntityId()); 723 724 String cmntdt_commentname = _value.getCommentName(); 725 if(cmntdt_commentname == null) 726 _ps.setNull(3, Types.VARCHAR); 727 else 728 _ps.setString(3, cmntdt_commentname); 729 730 CommentTypePK cmntdt_cmnttyp_commenttypeid = _value.getCommentTypePK(); 731 if(cmntdt_cmnttyp_commenttypeid == null) 732 _ps.setNull(4, Types.BIGINT); 733 else 734 _ps.setLong(4, cmntdt_cmnttyp_commenttypeid.getEntityId()); 735 736 EntityInstancePK cmntdt_commentedentityinstanceid = _value.getCommentedEntityInstancePK(); 737 if(cmntdt_commentedentityinstanceid == null) 738 _ps.setNull(5, Types.BIGINT); 739 else 740 _ps.setLong(5, cmntdt_commentedentityinstanceid.getEntityId()); 741 742 EntityInstancePK cmntdt_commentedbyentityinstanceid = _value.getCommentedByEntityInstancePK(); 743 if(cmntdt_commentedbyentityinstanceid == null) 744 _ps.setNull(6, Types.BIGINT); 745 else 746 _ps.setLong(6, cmntdt_commentedbyentityinstanceid.getEntityId()); 747 748 LanguagePK cmntdt_lang_languageid = _value.getLanguagePK(); 749 if(cmntdt_lang_languageid == null) 750 _ps.setNull(7, Types.BIGINT); 751 else 752 _ps.setLong(7, cmntdt_lang_languageid.getEntityId()); 753 754 String cmntdt_description = _value.getDescription(); 755 if(cmntdt_description == null) 756 _ps.setNull(8, Types.VARCHAR); 757 else 758 _ps.setString(8, cmntdt_description); 759 760 MimeTypePK cmntdt_mtyp_mimetypeid = _value.getMimeTypePK(); 761 if(cmntdt_mtyp_mimetypeid == null) 762 _ps.setNull(9, Types.BIGINT); 763 else 764 _ps.setLong(9, cmntdt_mtyp_mimetypeid.getEntityId()); 765 766 Long cmntdt_fromtime = _value.getFromTime(); 767 if(cmntdt_fromtime == null) 768 _ps.setNull(10, Types.BIGINT); 769 else 770 _ps.setLong(10, cmntdt_fromtime); 771 772 Long cmntdt_thrutime = _value.getThruTime(); 773 if(cmntdt_thrutime == null) 774 _ps.setNull(11, Types.BIGINT); 775 else 776 _ps.setLong(11, cmntdt_thrutime); 777 778 } 779 780 public CommentDetail create(Session session, CommentPK commentPK, String commentName, CommentTypePK commentTypePK, EntityInstancePK commentedEntityInstancePK, EntityInstancePK commentedByEntityInstancePK, LanguagePK languagePK, String description, MimeTypePK mimeTypePK, Long fromTime, Long thruTime) 781 throws PersistenceDatabaseException, PersistenceNotNullException { 782 CommentDetailPK _pk = getNextPK(); 783 CommentDetailValue _value = new CommentDetailValue(_pk, commentPK, commentName, commentTypePK, commentedEntityInstancePK, commentedByEntityInstancePK, languagePK, description, mimeTypePK, fromTime, thruTime); 784 785 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 786 787 try { 788 bindForCreate(_ps, _value); 789 790 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 791 int _count = _ps.executeUpdate(); 792 793 if(_count != 1) { 794 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 795 } 796 } else { 797 _ps.executeUpdate(); 798 } 799 800 session.getValueCache().put(_value); 801 } catch (SQLException se) { 802 throw new PersistenceDatabaseException(se); 803 } 804 805 CommentDetail _entity = new CommentDetail(_value, EntityPermission.READ_ONLY); 806 session.putReadOnlyEntity(_pk, _entity); 807 808 return _entity; 809 } 810 811 public CommentDetail create(CommentPK commentPK, String commentName, CommentTypePK commentTypePK, EntityInstancePK commentedEntityInstancePK, EntityInstancePK commentedByEntityInstancePK, LanguagePK languagePK, String description, MimeTypePK mimeTypePK, Long fromTime, Long thruTime) 812 throws PersistenceDatabaseException, PersistenceNotNullException { 813 return create(ThreadSession.currentSession(), commentPK, commentName, commentTypePK, commentedEntityInstancePK, commentedByEntityInstancePK, languagePK, description, mimeTypePK, fromTime, thruTime); 814 } 815 816 public void create(Session session, Collection<CommentDetailValue> _values) 817 throws PersistenceDatabaseException, PersistenceNotNullException { 818 int _size = _values.size(); 819 820 if(_size > 0) { 821 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 822 List<CommentDetailValue> _cacheValues = new ArrayList<>(_size); 823 824 try { 825 for(CommentDetailValue _value : _values) { 826 _value.setEntityId(entityIdGenerator.getNextEntityId()); 827 bindForCreate(_ps, _value); 828 829 _ps.addBatch(); 830 831 _cacheValues.add(_value); 832 } 833 834 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 835 int[] _counts = _ps.executeBatch(); 836 837 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 838 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 839 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 840 } 841 } 842 } else { 843 _ps.executeBatch(); 844 } 845 846 _ps.clearBatch(); 847 } catch (SQLException se) { 848 throw new PersistenceDatabaseException(se); 849 } 850 851 _cacheValues.forEach((_cacheValue) -> { 852 CommentDetail _cacheEntity = new CommentDetail(_cacheValue, EntityPermission.READ_ONLY); 853 854 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 855 }); 856 } 857 } 858 859 public void create(Collection<CommentDetailValue> _values) 860 throws PersistenceDatabaseException, PersistenceNotNullException { 861 create(ThreadSession.currentSession(), _values); 862 } 863 864 private boolean bindForStore(PreparedStatement _ps, CommentDetailValue _value) 865 throws SQLException { 866 boolean _hasBeenModified = _value.hasBeenModified(); 867 868 if(_hasBeenModified) { 869 CommentPK cmntdt_cmnt_commentid = _value.getCommentPK(); 870 if(cmntdt_cmnt_commentid == null) 871 _ps.setNull(1, Types.BIGINT); 872 else 873 _ps.setLong(1, cmntdt_cmnt_commentid.getEntityId()); 874 875 String cmntdt_commentname = _value.getCommentName(); 876 if(cmntdt_commentname == null) 877 _ps.setNull(2, Types.VARCHAR); 878 else 879 _ps.setString(2, cmntdt_commentname); 880 881 CommentTypePK cmntdt_cmnttyp_commenttypeid = _value.getCommentTypePK(); 882 if(cmntdt_cmnttyp_commenttypeid == null) 883 _ps.setNull(3, Types.BIGINT); 884 else 885 _ps.setLong(3, cmntdt_cmnttyp_commenttypeid.getEntityId()); 886 887 EntityInstancePK cmntdt_commentedentityinstanceid = _value.getCommentedEntityInstancePK(); 888 if(cmntdt_commentedentityinstanceid == null) 889 _ps.setNull(4, Types.BIGINT); 890 else 891 _ps.setLong(4, cmntdt_commentedentityinstanceid.getEntityId()); 892 893 EntityInstancePK cmntdt_commentedbyentityinstanceid = _value.getCommentedByEntityInstancePK(); 894 if(cmntdt_commentedbyentityinstanceid == null) 895 _ps.setNull(5, Types.BIGINT); 896 else 897 _ps.setLong(5, cmntdt_commentedbyentityinstanceid.getEntityId()); 898 899 LanguagePK cmntdt_lang_languageid = _value.getLanguagePK(); 900 if(cmntdt_lang_languageid == null) 901 _ps.setNull(6, Types.BIGINT); 902 else 903 _ps.setLong(6, cmntdt_lang_languageid.getEntityId()); 904 905 String cmntdt_description = _value.getDescription(); 906 if(cmntdt_description == null) 907 _ps.setNull(7, Types.VARCHAR); 908 else 909 _ps.setString(7, cmntdt_description); 910 911 MimeTypePK cmntdt_mtyp_mimetypeid = _value.getMimeTypePK(); 912 if(cmntdt_mtyp_mimetypeid == null) 913 _ps.setNull(8, Types.BIGINT); 914 else 915 _ps.setLong(8, cmntdt_mtyp_mimetypeid.getEntityId()); 916 917 Long cmntdt_fromtime = _value.getFromTime(); 918 if(cmntdt_fromtime == null) 919 _ps.setNull(9, Types.BIGINT); 920 else 921 _ps.setLong(9, cmntdt_fromtime); 922 923 Long cmntdt_thrutime = _value.getThruTime(); 924 if(cmntdt_thrutime == null) 925 _ps.setNull(10, Types.BIGINT); 926 else 927 _ps.setLong(10, cmntdt_thrutime); 928 929 _ps.setLong(11, _value.getPrimaryKey().getEntityId()); 930 931 _value.clearHasBeenModified(); 932 } 933 934 return _hasBeenModified; 935 } 936 937 @Override 938 public void store(Session session, CommentDetail entity) 939 throws PersistenceDatabaseException { 940 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 941 942 try { 943 CommentDetailValue _value = entity.getCommentDetailValue(); 944 945 if(bindForStore(_ps, _value)) { 946 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 947 int _count = _ps.executeUpdate(); 948 949 if(_count != 1) { 950 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 951 } 952 } else { 953 _ps.executeUpdate(); 954 } 955 956 session.getValueCache().put(_value); 957 } 958 } catch (SQLException se) { 959 throw new PersistenceDatabaseException(se); 960 } 961 } 962 963 @Override 964 public void store(Session session, Collection<CommentDetail> entities) 965 throws PersistenceDatabaseException { 966 if(entities.size() > 0) { 967 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 968 int _modifiedEntities = 0; 969 970 try { 971 for(CommentDetail entity : entities) { 972 if(bindForStore(_ps, entity.getCommentDetailValue())) { 973 _ps.addBatch(); 974 _modifiedEntities++; 975 } 976 } 977 978 if(_modifiedEntities != 0) { 979 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 980 int[] _counts = _ps.executeBatch(); 981 982 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 983 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 984 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 985 } 986 } 987 } else { 988 _ps.executeBatch(); 989 } 990 991 _ps.clearBatch(); 992 993 entities.forEach((entity) -> { 994 session.getValueCache().put(entity.getCommentDetailValue()); 995 }); 996 } 997 } catch (SQLException se) { 998 throw new PersistenceDatabaseException(se); 999 } 1000 } 1001 } 1002 1003 @Override 1004 public void store(Collection<CommentDetail> entities) 1005 throws PersistenceDatabaseException { 1006 store(ThreadSession.currentSession(), entities); 1007 } 1008 1009 @Override 1010 public void remove(Session session, CommentDetail entity) 1011 throws PersistenceDatabaseException { 1012 remove(session, entity.getPrimaryKey()); 1013 } 1014 1015 @Override 1016 public void remove(Session session, CommentDetailPK pk) 1017 throws PersistenceDatabaseException { 1018 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1019 long _entityId = pk.getEntityId(); 1020 1021 try { 1022 _ps.setLong(1, _entityId); 1023 1024 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1025 int _count = _ps.executeUpdate(); 1026 1027 if(_count != 1) { 1028 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 1029 } 1030 } else { 1031 _ps.executeUpdate(); 1032 } 1033 1034 session.getValueCache().remove(pk); 1035 } catch (SQLException se) { 1036 throw new PersistenceDatabaseException(se); 1037 } 1038 1039 session.removed(pk, false); 1040 } 1041 1042 @Override 1043 public void remove(Session session, Collection<CommentDetailPK> pks) 1044 throws PersistenceDatabaseException { 1045 if(pks.size() > 0) { 1046 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1047 int _modifiedEntities = 0; 1048 1049 try { 1050 for(CommentDetailPK pk : pks) { 1051 long _entityId = pk.getEntityId(); 1052 1053 _ps.setLong(1, _entityId); 1054 1055 _ps.addBatch(); 1056 _modifiedEntities++; 1057 } 1058 1059 if(_modifiedEntities != 0) { 1060 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1061 int[] _counts = _ps.executeBatch(); 1062 1063 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1064 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1065 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1066 } 1067 } 1068 } else { 1069 _ps.executeBatch(); 1070 } 1071 1072 _ps.clearBatch(); 1073 1074 pks.forEach((pk) -> { 1075 session.getValueCache().remove(pk); 1076 }); 1077 } 1078 } catch (SQLException se) { 1079 throw new PersistenceDatabaseException(se); 1080 } 1081 1082 pks.forEach((pk) -> { 1083 session.removed(pk, true); 1084 }); 1085 } 1086 } 1087 1088 @Override 1089 public void remove(Collection<CommentDetailPK> pks) 1090 throws PersistenceDatabaseException { 1091 remove(ThreadSession.currentSession(), pks); 1092 } 1093 1094 @Override 1095 public boolean validPK(Session session, CommentDetailPK pk) 1096 throws PersistenceDatabaseException { 1097 boolean valid = false; 1098 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1099 ResultSet _rs = null; 1100 1101 try { 1102 _ps.setLong(1, pk.getEntityId()); 1103 1104 _rs = _ps.executeQuery(); 1105 if(_rs.next()) { 1106 long _count = _rs.getLong(1); 1107 if(_rs.wasNull()) 1108 _count = 0; 1109 1110 if(_count == 1) 1111 valid = true; 1112 } 1113 } catch (SQLException se) { 1114 throw new PersistenceDatabaseException(se); 1115 } finally { 1116 if(_rs != null) { 1117 try { 1118 _rs.close(); 1119 } catch (SQLException se) { 1120 // do nothing 1121 } 1122 } 1123 } 1124 1125 return valid; 1126 } 1127 1128}