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