// try detect error by foreign key names
String umsg = errMessage.toLowerCase().toUpperCase();
if (umsg.indexOf(conn.JCR_FK_ITEM_PARENT) >= 0)
{
message += "Parent not found. Item " + itemInfo;
throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
}
else if (umsg.indexOf(conn.JCR_PK_ITEM) >= 0)
{
message += "Item already exists. Condition: ID. " + itemInfo;
// InvalidItemStateException ! - because it's impossible add new item with existed UUID
throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
}
else if (umsg.indexOf(conn.JCR_IDX_ITEM_PARENT) >= 0 || umsg.indexOf(conn.JCR_IDX_ITEM_PARENT_NAME) >= 0)
{
message += "Item already exists. Condition: parent ID, name, index. " + itemInfo;
throw new ItemExistsException(message, e);
}
else if (umsg.indexOf(conn.JCR_IDX_ITEM_PARENT_ID) >= 0)
{
message += "Item already exists. Condition: parent ID and ID. " + itemInfo;
throw new ItemExistsException(message, e);
}
else if (umsg.indexOf(conn.JCR_FK_VALUE_PROPERTY) >= 0)
{
message += "Property is not exist but the value is being created. Condition: property ID. " + itemInfo;
throw new RepositoryException(message, e);
}
else if (umsg.indexOf(conn.JCR_IDX_VALUE_PROPERTY) >= 0)
{
message += "Property already exists. Condition: property ID, order number. " + itemInfo;
throw new RepositoryException(message, e);
}
else if (umsg.indexOf(conn.JCR_PK_VALUE) >= 0)
{
message +=
"[FATAL] Value already exists with the ValueID. Impossible state, check is ValueID is autoincremented. "
+ itemInfo;
throw new RepositoryException(message, e);
}
else if (umsg.indexOf(conn.JCR_PK_REF) >= 0)
{
message += "Reference chain already exists. Condition: node ID, property ID, order number. " + itemInfo;
throw new RepositoryException(message, e);
}
else if (umsg.indexOf(conn.JCR_IDX_REF_PROPERTY) >= 0)
{
message += "Referenceable property value already exists. Condition: property ID, order number. " + itemInfo;
throw new RepositoryException(message, e);
}
}
// try detect integrity violation
RepositoryException ownException = null;
try
{
NodeData parent = (NodeData)conn.getItemData(item.getParentIdentifier());
if (parent != null)
{
// have a parent
try
{
ItemData me = conn.getItemData(item.getIdentifier());
if (me != null)
{
// item already exists
message += "Item already exists in storage: " + itemInfo;
ownException = new JCRItemExistsException(message, me.getIdentifier(), ItemState.ADDED, e);
throw ownException;
}
me =
conn.getItemData(parent, new QPathEntry(item.getQPath().getName(), item.getQPath().getIndex()),
ItemType.getItemType(item));
if (me != null)
{
message += "Item already exists in storage: " + itemInfo;
ownException = new JCRItemExistsException(message, me.getIdentifier(), ItemState.ADDED, e);
throw ownException;
}
}
catch (Exception ep)
{
// item not found or other things but error of item reading
if (ownException != null)
throw ownException;
}
// MySQL violation
if (e.getClass().getName().indexOf("MySQLIntegrityConstraintViolationException") >= 0
&& errMessage.indexOf(item.getIdentifier()) >= 0)
{
// it's JCR_PK_ITEM violation
message += "Item already exists. Condition: ID. " + itemInfo;
throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
}
message += "Error of item add. " + itemInfo;
ownException = new RepositoryException(message, e);
throw ownException;
}
}
catch (Exception ep)
{
// no parent or error access it
if (ownException != null)
throw ownException;
}
message += "Error of item add. " + itemInfo;
throw new JCRInvalidItemStateException(message, item.getIdentifier(), ItemState.ADDED, e);
}