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