optimized lazy read

This commit is contained in:
jomu
2017-02-12 12:38:50 +00:00
parent 12f4d0c47b
commit 8f8dc3e5f9
5 changed files with 9 additions and 10 deletions

View File

@ -134,7 +134,7 @@ public class AccountControl {
if (account.getUsername().equals(currentUserName)) { if (account.getUsername().equals(currentUserName)) {
throw new AccountException("Cannot delete own account"); throw new AccountException("Cannot delete own account");
} else { } else {
account.setStatus(AccountStatus.DISABLED.name()); account.setStatus(AccountStatus.DISABLED.name());
account.setLastUpdatedBy(currentUserName); account.setLastUpdatedBy(currentUserName);
account.setLastUpdatedOn(now); account.setLastUpdatedOn(now);
em.merge(account); em.merge(account);
@ -164,7 +164,7 @@ public class AccountControl {
account.setPasswordResetOngoing(true); account.setPasswordResetOngoing(true);
account.setPasswordResetValidTo(validTo); account.setPasswordResetValidTo(validTo);
mailService.sendPasswortResetStartEmail(account,randomString); mailService.sendPasswortResetStartEmail(account, randomString);
em.merge(account); em.merge(account);
return true; return true;
@ -257,8 +257,8 @@ public class AccountControl {
int maxFailedLogins = configService.getMaxFailedLogins(); int maxFailedLogins = configService.getMaxFailedLogins();
if ((account.getFailureCount() >= maxFailedLogins) && (!account.getStatus().equals("LOCKED"))) { // TOD add status enum if ((account.getFailureCount() >= maxFailedLogins) && (!account.getStatus().equals("LOCKED"))) { // TOD add status enum
// max failed logins reached, disabling user // max failed logins reached, disabling user
LOGGER.info( "Locking account " + account.getUsername() + " due to " + account.getFailureCount() + " failed logins"); LOGGER.info("Locking account " + account.getUsername() + " due to " + account.getFailureCount() + " failed logins");
account.setStatus(AccountStatus.BLOCKED.name()); account.setStatus(AccountStatus.BLOCKED.name());
} }
// on a failed login request, disable password reset // on a failed login request, disable password reset

View File

@ -8,6 +8,7 @@ import javax.persistence.Basic;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
@ -136,9 +137,9 @@ public class AccountEntity implements Serializable, Account {
@JoinTable(name = "account_role", joinColumns = { @JoinTable(name = "account_role", joinColumns = {
@JoinColumn(name = "account", referencedColumnName = "id")}, inverseJoinColumns = { @JoinColumn(name = "account", referencedColumnName = "id")}, inverseJoinColumns = {
@JoinColumn(name = "account_role", referencedColumnName = "id")}) @JoinColumn(name = "account_role", referencedColumnName = "id")})
@ManyToMany @ManyToMany(fetch = FetchType.LAZY)
private List<ApplicationRoleEntity> applicationRoleList; private List<ApplicationRoleEntity> applicationRoleList;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "accountId") @OneToMany(cascade = CascadeType.ALL, mappedBy = "accountId", fetch = FetchType.LAZY)
private List<AccountHistoryEntity> accountHistoryList; private List<AccountHistoryEntity> accountHistoryList;
public AccountEntity() { public AccountEntity() {

View File

@ -7,7 +7,6 @@ import javax.persistence.Basic;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;

View File

@ -25,7 +25,8 @@ import javax.xml.bind.annotation.XmlRootElement;
@NamedQuery(name = "MailTemplateEntity.findByTemplateValue", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateValue = :templateValue")}) @NamedQuery(name = "MailTemplateEntity.findByTemplateValue", query = "SELECT m FROM MailTemplateEntity m WHERE m.templateValue = :templateValue")})
public class MailTemplateEntity implements Serializable { public class MailTemplateEntity implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 4527399247302581555L;
@Id @Id
@Basic(optional = false) @Basic(optional = false)
@NotNull @NotNull

View File

@ -49,9 +49,7 @@ public class LoginView implements Serializable {
// "Remember Me" built-in: // "Remember Me" built-in:
token.setRememberMe(rememberMe); token.setRememberMe(rememberMe);
Subject currentUser = SecurityUtils.getSubject(); Subject currentUser = SecurityUtils.getSubject();
LOGGER.info("Submitting login with username of " + username); LOGGER.info("Submitting login with username of " + username);
try { try {