public IdentityObject findIdentityObjectByUniqueAttribute(IdentityStoreInvocationContext invocationCtx, IdentityObjectType identityObjectType, IdentityObjectAttribute attribute) throws IdentityException
{
if (attribute == null)
{
throw new IllegalArgumentException("attribute is null");
}
checkIOType(identityObjectType);
String attrMappedName = resolveAttributeStoreMapping(identityObjectType, attribute.getName());
HibernateIdentityObjectType hiot = getHibernateIdentityObjectType(invocationCtx, identityObjectType);
Session session = getHibernateSession(invocationCtx);
Query q = session.createQuery("select a from HibernateIdentityObjectTextAttribute a where a.identityObject.identityType = :identityType " +
"and a.name like :attributeName and :value = any elements(a.values)");
Set attrValues = new HashSet();
attrValues.addAll(attribute.getValues());
List<HibernateIdentityObjectAttribute> attrs = (List<HibernateIdentityObjectAttribute>)
q.setParameter("identityType", hiot)
.setParameter("attributeName", attrMappedName)
.setParameter("value", attribute.getValue()).list();
if (attrs.size() == 0)
{
return null;
}
if (attrs.size() > 1)
{
throw new IdentityException("Illegal state - more than one IdentityObject with the same unique attribute value: " + attribute);
}
return attrs.get(0).getIdentityObject();
}