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