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