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