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