Skip to content

Commit

Permalink
Showing 4 changed files with 54 additions and 28 deletions.
@@ -1,16 +1,12 @@
package edu.internet2.tier.shibboleth.admin.ui.domain;

import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
import org.hibernate.envers.NotAudited;
import org.opensaml.core.xml.AttributeExtensibleXMLObject;
import org.opensaml.core.xml.util.AttributeMap;

import javax.annotation.Nonnull;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.MapKeyColumn;
import javax.persistence.MappedSuperclass;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
@@ -4,10 +4,8 @@
import org.opensaml.core.xml.util.AttributeMap;

import javax.annotation.Nonnull;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.MapKeyColumn;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.Transient;
@@ -13,7 +13,6 @@
*/
@Entity
@RevisionEntity(PrincipalEnhancingRevisionListener.class)
@Table(name = "REVINFO")
@Getter
@Setter
public class PrincipalAwareRevisionEntity extends DefaultTrackingModifiedEntitiesRevisionEntity {
@@ -1,5 +1,6 @@
package edu.internet2.tier.shibboleth.admin.ui.hibernate;

import net.shibboleth.utilities.java.support.xml.QNameSupport;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.usertype.UserType;
@@ -11,9 +12,13 @@
import java.sql.SQLException;
import java.sql.Types;

/**
* Hibernate custom UserType needed to properly persist QName objects.
* Base implementation is taken from {@link https://github.com/tomsontom/emf-databinding-example/blob/0ae7faa67697a84171846852a5c5b0492d9a8f7d/org.eclipse.emf.teneo.hibernate/src/org/eclipse/emf/teneo/hibernate/mapping/QNameUserType.java}
*/
public class QNameUserType implements UserType {

private static final int[] SQL_TYPES = new int[] { Types.VARCHAR };
private static final int[] SQL_TYPES = new int[]{Types.VARCHAR};

/*
* (non-Javadoc)
@@ -42,25 +47,14 @@ public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}

/** Compares the int values of the enumerates */
public boolean equals(Object x, Object y) throws HibernateException {
// todo: check compare on null values
if (x == null && y == null) {
if (x == y) {
return true;
}

if (x == null || y == null) {
return false;
}

if (x.getClass() != y.getClass()) {
} else if (x == null || y == null) {
return false;
} else {
return x.equals(y);
}

final QName q1 = (QName) x;
final QName q2 = (QName) y;

return q1.toString().compareTo(q2.toString()) == 0;
}

/*
@@ -69,14 +63,49 @@ public boolean equals(Object x, Object y) throws HibernateException {
* @see org.hibernate.usertype.UserType#hashCode(java.lang.Object)
*/
public int hashCode(Object x) throws HibernateException {
return x.toString().hashCode();
return x.hashCode();
}

/** Not mutable */
/**
* Not mutable
*/
public boolean isMutable() {
return false;
}

/*
* (non-Javadoc)
*
* @see org.hibernate.usertype.UserType#nullSafeGet(java.sql.ResultSet, java.lang.String[],
* java.lang.Object)
*/
/*public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor sessionContractImplementor, Object owner) throws HibernateException, SQLException {
final String namespaceURI = rs.getString(names[0]);
if (rs.wasNull()) {
return null;
}
final String localPart = rs.getString(names[1]);
final String prefix = rs.getString(names[2]);
return QNameSupport.constructQName(namespaceURI, localPart, prefix);
}*/

/*
* (non-Javadoc)
*
* @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement,
* java.lang.Object, int)
*/
/*public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor sessionContractImplementor) throws HibernateException, SQLException {
if (value == null) {
st.setNull(index, Types.VARCHAR);
} else {
QName qName = (QName) value;
st.setString(index, qName.getNamespaceURI());
st.setString(index + 1, qName.getLocalPart());
st.setString(index + 2, qName.getPrefix());
}
}*/

/*
* (non-Javadoc)
*
@@ -115,12 +144,16 @@ public Object replace(Object original, Object target, Object owner) throws Hiber
return original;
}

/** Returns the parameterizezd enumType */
/**
* Returns the parameterizezd enumType
*/
public Class<?> returnedClass() {
return QName.class;
}

/** An enum is stored in one varchar */
/**
* An enum is stored in one varchar
*/
public int[] sqlTypes() {
return SQL_TYPES;
}
@@ -145,6 +178,6 @@ protected QName convertFromString(String str) {
final String ns = str.substring(1, endIndexNS);
final String prefix = str.substring(endIndexNS + 1, prefixIndex);
final String localPart = str.substring(prefixIndex + 1);
return new QName(ns, localPart, prefix);
return QNameSupport.constructQName(ns, localPart, prefix);
}
}

0 comments on commit f5e32da

Please sign in to comment.