use long for primary key

This commit is contained in:
Bill Burke 2014-07-16 17:11:59 -04:00
parent 7437af0131
commit 1963e94e33
9 changed files with 48 additions and 54 deletions

View file

@ -8,6 +8,7 @@ import org.keycloak.models.SocialLinkModel;
import org.keycloak.models.UserCredentialModel;
import org.keycloak.models.UserModel;
import org.keycloak.models.UserProvider;
import org.keycloak.models.jpa.entities.CredentialEntity;
import org.keycloak.models.jpa.entities.RealmEntity;
import org.keycloak.models.jpa.entities.RoleEntity;
import org.keycloak.models.jpa.entities.SocialLinkEntity;
@ -124,9 +125,14 @@ public class JpaUserProvider implements UserProvider {
@Override
public void preRemove(RealmModel realm) {
RealmEntity realmEntity = em.getReference(RealmEntity.class, realm.getId());
for (UserEntity u : em.createQuery("from UserEntity u where u.realm = :realm", UserEntity.class).setParameter("realm", realmEntity).getResultList()) {
removeUser(realm, u.getUsername());
}
int num = em.createQuery("delete from " + UserRoleMappingEntity.class.getSimpleName() + " mapping where mapping.user IN (select u from UserEntity u where realm=:realm)")
.setParameter("realm", realmEntity).executeUpdate();
num = em.createQuery("delete from " + SocialLinkEntity.class.getSimpleName() + " socialLink where socialLink.user IN (select u from UserEntity u where realm=:realm)")
.setParameter("realm", realmEntity).executeUpdate();
num = em.createQuery("delete from " + CredentialEntity.class.getSimpleName() + " mapping where mapping.user IN (select u from UserEntity u where realm=:realm)")
.setParameter("realm", realmEntity).executeUpdate();
num = em.createQuery("delete from UserEntity u where u.realm = :realm")
.setParameter("realm", realmEntity).executeUpdate();
}
@Override

View file

@ -14,19 +14,17 @@ import org.hibernate.annotations.GenericGenerator;
public class AuthenticationLinkEntity {
@Id
@Column(length = 36)
@GenericGenerator(name="keycloak_generator", strategy="org.keycloak.models.jpa.utils.JpaIdGenerator")
@GeneratedValue(generator = "keycloak_generator")
private String id;
@GeneratedValue
protected long id;
protected String authProvider;
protected String authUserId;
public String getId() {
public long getId() {
return id;
}
public void setId(String id) {
public void setId(long id) {
this.id = id;
}

View file

@ -21,10 +21,8 @@ import java.util.Map;
public class AuthenticationProviderEntity {
@Id
@Column(length = 36)
@GenericGenerator(name="keycloak_generator", strategy="org.keycloak.models.jpa.utils.JpaIdGenerator")
@GeneratedValue(generator = "keycloak_generator")
protected String id;
@GeneratedValue
protected long id;
private String providerName;
private boolean passwordUpdateSupported;
@ -38,11 +36,11 @@ public class AuthenticationProviderEntity {
})
private Map<String, String> config;
public String getId() {
public long getId() {
return id;
}
public void setId(String id) {
public void setId(long id) {
this.id = id;
}

View file

@ -5,6 +5,7 @@ import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
@ -21,10 +22,8 @@ import org.hibernate.annotations.GenericGenerator;
@Entity
public class CredentialEntity {
@Id
@Column(length = 36)
@GenericGenerator(name="keycloak_generator", strategy="org.keycloak.models.jpa.utils.JpaIdGenerator")
@GeneratedValue(generator = "keycloak_generator")
protected String id;
@GeneratedValue
protected long id;
protected String type;
protected String value;
@ -33,10 +32,16 @@ public class CredentialEntity {
protected int hashIterations;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="userId")
protected UserEntity user;
@ManyToOne(fetch = FetchType.LAZY)
protected RealmEntity realm;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getValue() {
return value;
@ -54,14 +59,6 @@ public class CredentialEntity {
this.type = type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDevice() {
return device;
}

View file

@ -14,21 +14,19 @@ import org.hibernate.annotations.GenericGenerator;
@Entity
public class RequiredCredentialEntity {
@Id
@Column(length = 36)
@GenericGenerator(name="keycloak_generator", strategy="org.keycloak.models.jpa.utils.JpaIdGenerator")
@GeneratedValue(generator = "keycloak_generator")
protected String id;
@GeneratedValue
protected long id;
protected String type;
protected boolean input;
protected boolean secret;
protected String formLabel;
public String getId() {
public long getId() {
return id;
}
public void setId(String id) {
public void setId(long id) {
this.id = id;
}

View file

@ -24,10 +24,9 @@ import javax.persistence.NamedQuery;
@Entity
public class ScopeMappingEntity {
@Id
@Column(length = 36)
@GenericGenerator(name="keycloak_generator", strategy="org.keycloak.models.jpa.utils.JpaIdGenerator")
@GeneratedValue(generator = "keycloak_generator")
protected String id;
@GeneratedValue
protected long id;
@ManyToOne(fetch= FetchType.LAZY)
protected ClientEntity client;
@ -35,11 +34,11 @@ public class ScopeMappingEntity {
@JoinColumn(name="roleId")
protected RoleEntity role;
public String getId() {
public long getId() {
return id;
}
public void setId(String id) {
public void setId(long id) {
this.id = id;
}

View file

@ -23,10 +23,8 @@ import org.hibernate.annotations.GenericGenerator;
@Entity
public class SocialLinkEntity {
@Id
@Column(length = 36)
@GenericGenerator(name="keycloak_generator", strategy="org.keycloak.models.jpa.utils.JpaIdGenerator")
@GeneratedValue(generator = "keycloak_generator")
private String id;
@GeneratedValue
protected long id;
@ManyToOne(fetch = FetchType.LAZY)
private UserEntity user;
@ -38,11 +36,11 @@ public class SocialLinkEntity {
protected String socialUserId;
protected String socialUsername;
public String getId() {
public long getId() {
return id;
}
public void setId(String id) {
public void setId(long id) {
this.id = id;
}

View file

@ -72,7 +72,7 @@ public class UserEntity {
@CollectionTable
protected Set<UserModel.RequiredAction> requiredActions = new HashSet<UserModel.RequiredAction>();
@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true)
@OneToMany(cascade = CascadeType.REMOVE, orphanRemoval = true, mappedBy="user")
protected Collection<CredentialEntity> credentials = new ArrayList<CredentialEntity>();
@OneToOne(cascade = CascadeType.REMOVE, orphanRemoval = true)

View file

@ -24,22 +24,22 @@ import org.hibernate.annotations.GenericGenerator;
@Entity
public class UserRoleMappingEntity {
@Id
@Column(length = 36)
@GenericGenerator(name="keycloak_generator", strategy="org.keycloak.models.jpa.utils.JpaIdGenerator")
@GeneratedValue(generator = "keycloak_generator")
protected String id;
@GeneratedValue
protected long id;
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="userId")
protected UserEntity user;
@ManyToOne(fetch= FetchType.LAZY)
@JoinColumn(name="roleId")
protected RoleEntity role;
public String getId() {
public long getId() {
return id;
}
public void setId(String id) {
public void setId(long id) {
this.id = id;
}