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