HibernateIdentityObject hibernateObject = safeGet(ctx, identity);
for (String name : mappedAttributes.keySet())
{
IdentityObjectAttribute attribute = mappedAttributes.get(name);
IdentityObjectAttributeMetaData amd = mdMap.get(attribute.getName());
// Default to text
String type = amd != null ? amd.getType() : IdentityObjectAttributeMetaData.TEXT_TYPE;
HibernateIdentityObjectAttribute hibernateAttribute = null;
for (HibernateIdentityObjectAttribute storeAttribute : hibernateObject.getAttributes())
{
if (storeAttribute.getName().equals(name))
{
hibernateAttribute = storeAttribute;
break;
}
}
if (hibernateAttribute != null)
{
if (hibernateAttribute instanceof HibernateIdentityObjectTextAttribute)
{
if (!type.equals(IdentityObjectAttributeMetaData.TEXT_TYPE))
{
throw new IdentityException("Wrong attribute mapping. Attribute persisted as text is mapped with: "
+ type + ". Attribute name: " + name);
}
Set<String> mergedValues = new HashSet<String>(hibernateAttribute.getValues());
for (Object value : attribute.getValues())
{
mergedValues.add(value.toString());
}
((HibernateIdentityObjectTextAttribute)hibernateAttribute).setValues(mergedValues);
}
else if (hibernateAttribute instanceof HibernateIdentityObjectBinaryAttribute)
{
if (!type.equals(IdentityObjectAttributeMetaData.BINARY_TYPE))
{
throw new IdentityException("Wrong attribute mapping. Attribute persisted as binary is mapped with: "
+ type + ". Attribute name: " + name);
}
Set<byte[]> mergedValues = new HashSet<byte[]>(hibernateAttribute.getValues());
for (Object value : attribute.getValues())
{
mergedValues.add((byte[])value);
}
((HibernateIdentityObjectBinaryAttribute)hibernateAttribute).setValues(mergedValues);
}
else
{
throw new IdentityException("Internal identity store error");
}
break;
}
else
{
if (type.equals(IdentityObjectAttributeMetaData.TEXT_TYPE))
{
Set<String> values = new HashSet<String>();
for (Object value: attribute.getValues())
{
values.add(value.toString());
}
hibernateAttribute = new HibernateIdentityObjectTextAttribute(hibernateObject, name, values);
}
else if (type.equals(IdentityObjectAttributeMetaData.BINARY_TYPE))
{
Set<byte[]> values = new HashSet<byte[]>();
for (Object value: attribute.getValues())
{
values.add((byte[])value);
}
hibernateAttribute = new HibernateIdentityObjectBinaryAttribute(hibernateObject, name, values);
}