Skip to content
Snippets Groups Projects
Commit 1e46d584 authored by Brendan Le Ny's avatar Brendan Le Ny Committed by Alex Morel
Browse files

Type "type" column in Hibernate

parent 3009edf1
No related branches found
No related tags found
1 merge request!3Sonar refactoring
...@@ -9,6 +9,7 @@ import jakarta.persistence.NamedQuery; ...@@ -9,6 +9,7 @@ import jakarta.persistence.NamedQuery;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import sh.libre.scim.core.EntityOnRemoteScimId; import sh.libre.scim.core.EntityOnRemoteScimId;
import sh.libre.scim.core.KeycloakId; import sh.libre.scim.core.KeycloakId;
import sh.libre.scim.core.ScimResourceType;
@Entity @Entity
@IdClass(ScimResourceId.class) @IdClass(ScimResourceId.class)
...@@ -33,7 +34,7 @@ public class ScimResource { ...@@ -33,7 +34,7 @@ public class ScimResource {
@Id @Id
@Column(name = "TYPE", nullable = false) @Column(name = "TYPE", nullable = false)
private String type; private ScimResourceType type;
@Id @Id
@Column(name = "EXTERNAL_ID", nullable = false) @Column(name = "EXTERNAL_ID", nullable = false)
...@@ -71,11 +72,11 @@ public class ScimResource { ...@@ -71,11 +72,11 @@ public class ScimResource {
this.externalId = externalId; this.externalId = externalId;
} }
public String getType() { public ScimResourceType getType() {
return type; return type;
} }
public void setType(String type) { public void setType(ScimResourceType type) {
this.type = type; this.type = type;
} }
......
...@@ -45,7 +45,7 @@ public class ScimResourceDao { ...@@ -45,7 +45,7 @@ public class ScimResourceDao {
public void create(KeycloakId id, EntityOnRemoteScimId externalId, ScimResourceType type) { public void create(KeycloakId id, EntityOnRemoteScimId externalId, ScimResourceType type) {
ScimResource entity = new ScimResource(); ScimResource entity = new ScimResource();
entity.setType(type.name()); entity.setType(type);
entity.setExternalId(externalId.asString()); entity.setExternalId(externalId.asString());
entity.setComponentId(componentId); entity.setComponentId(componentId);
entity.setRealmId(realmId); entity.setRealmId(realmId);
...@@ -56,7 +56,7 @@ public class ScimResourceDao { ...@@ -56,7 +56,7 @@ public class ScimResourceDao {
private TypedQuery<ScimResource> getScimResourceTypedQuery(String queryName, String id, ScimResourceType type) { private TypedQuery<ScimResource> getScimResourceTypedQuery(String queryName, String id, ScimResourceType type) {
return getEntityManager() return getEntityManager()
.createNamedQuery(queryName, ScimResource.class) .createNamedQuery(queryName, ScimResource.class)
.setParameter("type", type.name()) .setParameter("type", type)
.setParameter("realmId", getRealmId()) .setParameter("realmId", getRealmId())
.setParameter("componentId", getComponentId()) .setParameter("componentId", getComponentId())
.setParameter("id", id); .setParameter("id", id);
......
package sh.libre.scim.jpa; package sh.libre.scim.jpa;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import sh.libre.scim.core.ScimResourceType;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
...@@ -9,13 +10,13 @@ public class ScimResourceId implements Serializable { ...@@ -9,13 +10,13 @@ public class ScimResourceId implements Serializable {
private String id; private String id;
private String realmId; private String realmId;
private String componentId; private String componentId;
private String type; private ScimResourceType type;
private String externalId; private String externalId;
public ScimResourceId() { public ScimResourceId() {
} }
public ScimResourceId(String id, String realmId, String componentId, String type, String externalId) { public ScimResourceId(String id, String realmId, String componentId, ScimResourceType type, String externalId) {
this.setId(id); this.setId(id);
this.setRealmId(realmId); this.setRealmId(realmId);
this.setComponentId(componentId); this.setComponentId(componentId);
...@@ -47,11 +48,11 @@ public class ScimResourceId implements Serializable { ...@@ -47,11 +48,11 @@ public class ScimResourceId implements Serializable {
this.componentId = componentId; this.componentId = componentId;
} }
public String getType() { public ScimResourceType getType() {
return type; return type;
} }
public void setType(String type) { public void setType(ScimResourceType type) {
this.type = type; this.type = type;
} }
...@@ -74,7 +75,7 @@ public class ScimResourceId implements Serializable { ...@@ -74,7 +75,7 @@ public class ScimResourceId implements Serializable {
return (StringUtils.equals(o.id, id) && return (StringUtils.equals(o.id, id) &&
StringUtils.equals(o.realmId, realmId) && StringUtils.equals(o.realmId, realmId) &&
StringUtils.equals(o.componentId, componentId) && StringUtils.equals(o.componentId, componentId) &&
StringUtils.equals(o.type, type) && Objects.equals(o.type, type) &&
StringUtils.equals(o.externalId, externalId)); StringUtils.equals(o.externalId, externalId));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment