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