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 * FreeOnBoardDetailFactory.java 021 */ 022 023package com.echothree.model.data.shipment.server.factory; 024 025import com.echothree.model.data.shipment.common.pk.FreeOnBoardPK; 026 027import com.echothree.model.data.shipment.server.entity.FreeOnBoard; 028 029import com.echothree.model.data.shipment.common.FreeOnBoardDetailConstants; 030import com.echothree.model.data.shipment.common.pk.FreeOnBoardDetailPK; 031import com.echothree.model.data.shipment.server.value.FreeOnBoardDetailValue; 032import com.echothree.model.data.shipment.server.entity.FreeOnBoardDetail; 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 FreeOnBoardDetailFactory 062 implements BaseFactory<FreeOnBoardDetailPK, FreeOnBoardDetail> { 063 064 @Inject 065 Session session; 066 067 //private static final Logger log = LoggerFactory.getLogger(FreeOnBoardDetailFactory.class); 068 069 final private static String SQL_SELECT_READ_ONLY = "SELECT fobdt_freeonboarddetailid, fobdt_fob_freeonboardid, fobdt_freeonboardname, fobdt_isdefault, fobdt_sortorder, fobdt_fromtime, fobdt_thrutime FROM freeonboarddetails WHERE fobdt_freeonboarddetailid = ?"; 070 final private static String SQL_SELECT_READ_WRITE = "SELECT fobdt_freeonboarddetailid, fobdt_fob_freeonboardid, fobdt_freeonboardname, fobdt_isdefault, fobdt_sortorder, fobdt_fromtime, fobdt_thrutime FROM freeonboarddetails WHERE fobdt_freeonboarddetailid = ? FOR UPDATE"; 071 final private static String SQL_INSERT = "INSERT INTO freeonboarddetails (fobdt_freeonboarddetailid, fobdt_fob_freeonboardid, fobdt_freeonboardname, fobdt_isdefault, fobdt_sortorder, fobdt_fromtime, fobdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?)"; 072 final private static String SQL_UPDATE = "UPDATE freeonboarddetails SET fobdt_fob_freeonboardid = ?, fobdt_freeonboardname = ?, fobdt_isdefault = ?, fobdt_sortorder = ?, fobdt_fromtime = ?, fobdt_thrutime = ? WHERE fobdt_freeonboarddetailid = ?"; 073 final private static String SQL_DELETE = "DELETE FROM freeonboarddetails WHERE fobdt_freeonboarddetailid = ?"; 074 final private static String SQL_VALID = "SELECT COUNT(*) FROM freeonboarddetails WHERE fobdt_freeonboarddetailid = ?"; 075 076 final public static String FOBDT_FREEONBOARDDETAILID = "fobdt_freeonboarddetailid"; 077 final public static String FOBDT_FOB_FREEONBOARDID = "fobdt_fob_freeonboardid"; 078 final public static String FOBDT_FREEONBOARDNAME = "fobdt_freeonboardname"; 079 final public static String FOBDT_ISDEFAULT = "fobdt_isdefault"; 080 final public static String FOBDT_SORTORDER = "fobdt_sortorder"; 081 final public static String FOBDT_FROMTIME = "fobdt_fromtime"; 082 final public static String FOBDT_THRUTIME = "fobdt_thrutime"; 083 084 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(FreeOnBoardDetailConstants.COMPONENT_VENDOR_NAME, FreeOnBoardDetailConstants.ENTITY_TYPE_NAME); 085 086 /** Creates a new instance of FreeOnBoardDetailFactory */ 087 protected FreeOnBoardDetailFactory() { 088 super(); 089 } 090 091 public static FreeOnBoardDetailFactory getInstance() { 092 return CDI.current().select(FreeOnBoardDetailFactory.class).get(); 093 } 094 095 @Override 096 public String getComponentVendorName() { 097 return FreeOnBoardDetailConstants.COMPONENT_VENDOR_NAME; 098 } 099 100 @Override 101 public String getEntityTypeName() { 102 return FreeOnBoardDetailConstants.ENTITY_TYPE_NAME; 103 } 104 105 public PreparedStatement prepareStatement(String query) { 106 return session.prepareStatement(query); 107 } 108 109 public FreeOnBoardDetailPK getNextPK() { 110 return new FreeOnBoardDetailPK(entityIdGenerator.getNextEntityId()); 111 } 112 113 public Set<FreeOnBoardDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 114 throws PersistenceDatabaseException { 115 Set<FreeOnBoardDetailPK> _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<FreeOnBoardDetailPK> getPKsFromResultSetAsList(ResultSet rs) 129 throws PersistenceDatabaseException { 130 java.util.List<FreeOnBoardDetailPK> _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 FreeOnBoardDetailPK getPKFromResultSet(ResultSet rs) 144 throws PersistenceDatabaseException { 145 FreeOnBoardDetailPK _result; 146 147 try { 148 long fobdt_freeonboarddetailid = rs.getLong(FOBDT_FREEONBOARDDETAILID); 149 Long _entityId = rs.wasNull() ? null : fobdt_freeonboarddetailid; 150 151 _result = new FreeOnBoardDetailPK(_entityId); 152 } catch (SQLException se) { 153 throw new PersistenceDatabaseException(se); 154 } 155 156 return _result; 157 } 158 159 public java.util.List<FreeOnBoardDetailValue> getValuesFromPKs(Collection<FreeOnBoardDetailPK> pks) 160 throws PersistenceDatabaseException { 161 java.util.List<FreeOnBoardDetailValue> _values = new ArrayList<>(pks.size()); 162 163 for(FreeOnBoardDetailPK _pk: pks) { 164 _values.add(getValueFromPK(_pk)); 165 } 166 167 return _values; 168 } 169 170 public FreeOnBoardDetailValue getValueFromPK(FreeOnBoardDetailPK pk) 171 throws PersistenceDatabaseException { 172 FreeOnBoardDetailValue _value; 173 174 // See if we already have the entity in the session cache 175 FreeOnBoardDetail _entity = (FreeOnBoardDetail)session.getEntity(pk); 176 if(_entity == null) 177 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getFreeOnBoardDetailValue(); 178 else 179 _value = _entity.getFreeOnBoardDetailValue(); 180 181 return _value; 182 } 183 184 public java.util.List<FreeOnBoardDetailValue> getValuesFromResultSet(ResultSet rs) 185 throws PersistenceDatabaseException { 186 java.util.List<FreeOnBoardDetailValue> _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 FreeOnBoardDetailValue getValueFromResultSet(ResultSet rs) 200 throws PersistenceDatabaseException { 201 FreeOnBoardDetailValue _value; 202 203 try { 204 Long fobdt_freeonboarddetailid = rs.getLong(FOBDT_FREEONBOARDDETAILID); 205 FreeOnBoardDetailPK _pk = new FreeOnBoardDetailPK(fobdt_freeonboarddetailid); 206 207 // See if we already have the entity in the session cache 208 FreeOnBoardDetail _entity = (FreeOnBoardDetail)session.getEntity(_pk); 209 210 if(_entity == null) { 211 Long fobdt_fob_freeonboardid = rs.getLong(FOBDT_FOB_FREEONBOARDID); 212 if(rs.wasNull()) 213 fobdt_fob_freeonboardid = null; 214 215 String fobdt_freeonboardname = rs.getString(FOBDT_FREEONBOARDNAME); 216 if(rs.wasNull()) 217 fobdt_freeonboardname = null; 218 219 Boolean fobdt_isdefault = rs.getInt(FOBDT_ISDEFAULT) == 1; 220 if(rs.wasNull()) 221 fobdt_isdefault = null; 222 223 Integer fobdt_sortorder = rs.getInt(FOBDT_SORTORDER); 224 if(rs.wasNull()) 225 fobdt_sortorder = null; 226 227 Long fobdt_fromtime = rs.getLong(FOBDT_FROMTIME); 228 if(rs.wasNull()) 229 fobdt_fromtime = null; 230 231 Long fobdt_thrutime = rs.getLong(FOBDT_THRUTIME); 232 if(rs.wasNull()) 233 fobdt_thrutime = null; 234 235 _value = new FreeOnBoardDetailValue(_pk, new FreeOnBoardPK(fobdt_fob_freeonboardid), fobdt_freeonboardname, fobdt_isdefault, fobdt_sortorder, fobdt_fromtime, fobdt_thrutime); 236 } else 237 _value = _entity.getFreeOnBoardDetailValue(); 238 } catch (SQLException se) { 239 throw new PersistenceDatabaseException(se); 240 } 241 242 return _value; 243 } 244 245 public java.util.List<FreeOnBoardDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<FreeOnBoardDetailPK> pks) 246 throws PersistenceDatabaseException { 247 java.util.List<FreeOnBoardDetail> _entities = new ArrayList<>(pks.size()); 248 249 for(FreeOnBoardDetailPK _pk: pks) { 250 _entities.add(getEntityFromPK(entityPermission, _pk)); 251 } 252 253 return _entities; 254 } 255 256 public FreeOnBoardDetail getEntityFromValue(EntityPermission entityPermission, FreeOnBoardDetailValue value) { 257 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 258 } 259 260 public FreeOnBoardDetail getEntityFromCache(FreeOnBoardDetailPK pk) { 261 FreeOnBoardDetailValue _value = (FreeOnBoardDetailValue)session.getValueCache().get(pk); 262 263 return _value == null ? null : new FreeOnBoardDetail(_value, EntityPermission.READ_ONLY); 264 } 265 266 public FreeOnBoardDetail getEntityFromPK(EntityPermission entityPermission, FreeOnBoardDetailPK pk) 267 throws PersistenceDatabaseException { 268 FreeOnBoardDetail _entity; 269 270 // See if we already have the entity in the session cache 271 _entity = (FreeOnBoardDetail)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<FreeOnBoardDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 314 throws PersistenceDatabaseException { 315 Set<FreeOnBoardDetailPK> _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<FreeOnBoardDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 342 throws PersistenceDatabaseException { 343 java.util.List<FreeOnBoardDetailPK> _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 FreeOnBoardDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 370 throws PersistenceDatabaseException { 371 FreeOnBoardDetailPK _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<FreeOnBoardDetail> 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<FreeOnBoardDetail> 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<FreeOnBoardDetail> 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<FreeOnBoardDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 421 throws PersistenceDatabaseException { 422 java.util.List<FreeOnBoardDetail> _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 FreeOnBoardDetail 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 FreeOnBoardDetail 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 FreeOnBoardDetail 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 FreeOnBoardDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 470 throws PersistenceDatabaseException { 471 FreeOnBoardDetail _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<FreeOnBoardDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 500 throws PersistenceDatabaseException { 501 java.util.List<FreeOnBoardDetail> _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 FreeOnBoardDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 515 throws PersistenceDatabaseException { 516 FreeOnBoardDetail _entity; 517 518 try { 519 Long fobdt_freeonboarddetailid = rs.getLong(FOBDT_FREEONBOARDDETAILID); 520 FreeOnBoardDetailPK _pk = new FreeOnBoardDetailPK(fobdt_freeonboarddetailid); 521 522 // See if we already have the entity in the session cache 523 _entity = (FreeOnBoardDetail)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 fobdt_fob_freeonboardid = rs.getLong(FOBDT_FOB_FREEONBOARDID); 541 if(rs.wasNull()) 542 fobdt_fob_freeonboardid = null; 543 544 String fobdt_freeonboardname = rs.getString(FOBDT_FREEONBOARDNAME); 545 if(rs.wasNull()) 546 fobdt_freeonboardname = null; 547 548 Boolean fobdt_isdefault = rs.getInt(FOBDT_ISDEFAULT) == 1; 549 if(rs.wasNull()) 550 fobdt_isdefault = null; 551 552 Integer fobdt_sortorder = rs.getInt(FOBDT_SORTORDER); 553 if(rs.wasNull()) 554 fobdt_sortorder = null; 555 556 Long fobdt_fromtime = rs.getLong(FOBDT_FROMTIME); 557 if(rs.wasNull()) 558 fobdt_fromtime = null; 559 560 Long fobdt_thrutime = rs.getLong(FOBDT_THRUTIME); 561 if(rs.wasNull()) 562 fobdt_thrutime = null; 563 564 FreeOnBoardDetailValue _value = new FreeOnBoardDetailValue(_pk, fobdt_fob_freeonboardid == null? null: new FreeOnBoardPK(fobdt_fob_freeonboardid), fobdt_freeonboardname, fobdt_isdefault, fobdt_sortorder, fobdt_fromtime, fobdt_thrutime); 565 _entity = new FreeOnBoardDetail(_value, entityPermission); 566 } 567 568 if(!foundInSessionCache) { 569 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 570 session.putReadOnlyEntity(_pk, _entity); 571 session.getValueCache().put(_entity.getFreeOnBoardDetailValue()); 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 FreeOnBoardDetail create(FreeOnBoard freeOnBoard, String freeOnBoardName, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 584 throws PersistenceDatabaseException, PersistenceNotNullException { 585 return create(freeOnBoard == null ? null : freeOnBoard.getPrimaryKey(), freeOnBoardName, isDefault, sortOrder, fromTime, thruTime); 586 } 587 588 private void bindForCreate(PreparedStatement _ps, FreeOnBoardDetailValue _value) 589 throws SQLException { 590 _ps.setLong(1, _value.getEntityId()); 591 592 FreeOnBoardPK fobdt_fob_freeonboardid = _value.getFreeOnBoardPK(); 593 if(fobdt_fob_freeonboardid == null) 594 _ps.setNull(2, Types.BIGINT); 595 else 596 _ps.setLong(2, fobdt_fob_freeonboardid.getEntityId()); 597 598 String fobdt_freeonboardname = _value.getFreeOnBoardName(); 599 if(fobdt_freeonboardname == null) 600 _ps.setNull(3, Types.VARCHAR); 601 else 602 _ps.setString(3, fobdt_freeonboardname); 603 604 Boolean fobdt_isdefault = _value.getIsDefault(); 605 if(fobdt_isdefault == null) 606 _ps.setNull(4, Types.BIT); 607 else 608 _ps.setInt(4, fobdt_isdefault? 1: 0); 609 610 Integer fobdt_sortorder = _value.getSortOrder(); 611 if(fobdt_sortorder == null) 612 _ps.setNull(5, Types.INTEGER); 613 else 614 _ps.setInt(5, fobdt_sortorder); 615 616 Long fobdt_fromtime = _value.getFromTime(); 617 if(fobdt_fromtime == null) 618 _ps.setNull(6, Types.BIGINT); 619 else 620 _ps.setLong(6, fobdt_fromtime); 621 622 Long fobdt_thrutime = _value.getThruTime(); 623 if(fobdt_thrutime == null) 624 _ps.setNull(7, Types.BIGINT); 625 else 626 _ps.setLong(7, fobdt_thrutime); 627 628 } 629 630 public FreeOnBoardDetail create(FreeOnBoardPK freeOnBoardPK, String freeOnBoardName, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 631 throws PersistenceDatabaseException, PersistenceNotNullException { 632 FreeOnBoardDetailPK _pk = getNextPK(); 633 FreeOnBoardDetailValue _value = new FreeOnBoardDetailValue(_pk, freeOnBoardPK, freeOnBoardName, 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 FreeOnBoardDetail _entity = new FreeOnBoardDetail(_value, EntityPermission.READ_ONLY); 656 session.putReadOnlyEntity(_pk, _entity); 657 658 return _entity; 659 } 660 661 public void create(Collection<FreeOnBoardDetailValue> _values) 662 throws PersistenceDatabaseException, PersistenceNotNullException { 663 int _size = _values.size(); 664 665 if(_size > 0) { 666 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 667 List<FreeOnBoardDetailValue> _cacheValues = new ArrayList<>(_size); 668 669 try { 670 for(FreeOnBoardDetailValue _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 FreeOnBoardDetail _cacheEntity = new FreeOnBoardDetail(_cacheValue, EntityPermission.READ_ONLY); 698 699 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 700 }); 701 } 702 } 703 704 private boolean bindForStore(PreparedStatement _ps, FreeOnBoardDetailValue _value) 705 throws SQLException { 706 boolean _hasBeenModified = _value.hasBeenModified(); 707 708 if(_hasBeenModified) { 709 FreeOnBoardPK fobdt_fob_freeonboardid = _value.getFreeOnBoardPK(); 710 if(fobdt_fob_freeonboardid == null) 711 _ps.setNull(1, Types.BIGINT); 712 else 713 _ps.setLong(1, fobdt_fob_freeonboardid.getEntityId()); 714 715 String fobdt_freeonboardname = _value.getFreeOnBoardName(); 716 if(fobdt_freeonboardname == null) 717 _ps.setNull(2, Types.VARCHAR); 718 else 719 _ps.setString(2, fobdt_freeonboardname); 720 721 Boolean fobdt_isdefault = _value.getIsDefault(); 722 if(fobdt_isdefault == null) 723 _ps.setNull(3, Types.BIT); 724 else 725 _ps.setInt(3, fobdt_isdefault? 1: 0); 726 727 Integer fobdt_sortorder = _value.getSortOrder(); 728 if(fobdt_sortorder == null) 729 _ps.setNull(4, Types.INTEGER); 730 else 731 _ps.setInt(4, fobdt_sortorder); 732 733 Long fobdt_fromtime = _value.getFromTime(); 734 if(fobdt_fromtime == null) 735 _ps.setNull(5, Types.BIGINT); 736 else 737 _ps.setLong(5, fobdt_fromtime); 738 739 Long fobdt_thrutime = _value.getThruTime(); 740 if(fobdt_thrutime == null) 741 _ps.setNull(6, Types.BIGINT); 742 else 743 _ps.setLong(6, fobdt_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(FreeOnBoardDetail entity) 755 throws PersistenceDatabaseException { 756 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 757 758 try { 759 FreeOnBoardDetailValue _value = entity.getFreeOnBoardDetailValue(); 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<FreeOnBoardDetail> 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(FreeOnBoardDetail entity : entities) { 788 if(bindForStore(_ps, entity.getFreeOnBoardDetailValue())) { 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.getFreeOnBoardDetailValue()); 811 }); 812 } 813 } catch (SQLException se) { 814 throw new PersistenceDatabaseException(se); 815 } 816 } 817 } 818 819 @Override 820 public void remove(FreeOnBoardDetail entity) 821 throws PersistenceDatabaseException { 822 remove(entity.getPrimaryKey()); 823 } 824 825 @Override 826 public void remove(FreeOnBoardDetailPK 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<FreeOnBoardDetailPK> 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(FreeOnBoardDetailPK 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(FreeOnBoardDetailPK 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}