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