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