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