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