// try detect error by foreign key names
String umsg = errMessage.toLowerCase().toUpperCase();
if (umsg.indexOf(conn.JCR_FK_ITEM_PARENT) >= 0)
{
message.append("Parent not found. Item ").append(itemInfo);
throw new JCRInvalidItemStateException(message.toString(), item.getIdentifier(), ItemState.ADDED, e);
}
else if (umsg.indexOf(conn.JCR_PK_ITEM) >= 0)
{
message.append("Item already exists. Condition: ID. ").append(itemInfo);
// InvalidItemStateException ! - because it's impossible add new item with existed UUID
throw new JCRInvalidItemStateException(message.toString(), item.getIdentifier(), ItemState.ADDED, e);
}
else if (umsg.indexOf(conn.JCR_IDX_ITEM_PARENT_NAME) >= 0)
{
message.append("Item already exists. Condition: parent ID and ID. ").append(itemInfo);
throw new ItemExistsException(message.toString(), e);
}
else if (umsg.indexOf(conn.JCR_IDX_ITEM_PARENT_ID) >= 0)
{
message.append("Item already exists. Condition: parent ID and ID. ").append(itemInfo);
throw new ItemExistsException(message.toString(), e);
}
else if (umsg.indexOf(conn.JCR_IDX_ITEM_PARENT) >= 0)
{
message.append("Item already exists. Condition: parent ID, name, index. ").append(itemInfo);
throw new ItemExistsException(message.toString(), e);
}
else if (umsg.indexOf(conn.JCR_FK_VALUE_PROPERTY) >= 0)
{
message.append("Property is not exist but the value is being created. Condition: property ID. ").append(
itemInfo);
throw new RepositoryException(message.toString(), e);
}
else if (umsg.indexOf(conn.JCR_IDX_VALUE_PROPERTY) >= 0)
{
message.append("Property already exists. Condition: property ID, order number. ").append(itemInfo);
throw new RepositoryException(message.toString(), e);
}
else if (umsg.indexOf(conn.JCR_PK_VALUE) >= 0)
{
message
.append(
"[FATAL] Value already exists with the ValueID. Impossible state, check is ValueID is autoincremented. ")
.append(itemInfo);
throw new RepositoryException(message.toString(), e);
}
else if (umsg.indexOf(conn.JCR_PK_REF) >= 0)
{
message.append("Reference chain already exists. Condition: node ID, property ID, order number. ").append(
itemInfo);
throw new RepositoryException(message.toString(), e);
}
else if (umsg.indexOf(conn.JCR_IDX_REF_PROPERTY) >= 0)
{
message.append("Referenceable property value already exists. Condition: property ID, order number. ")
.append(itemInfo);
throw new RepositoryException(message.toString(), 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.append("Item already exists in storage: ").append(itemInfo);
ownException = new JCRItemExistsException(message.toString(), 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.append("Item already exists in storage: ").append(itemInfo);
ownException = new JCRItemExistsException(message.toString(), 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.append("Item already exists. Condition: ID. ").append(itemInfo);
throw new JCRInvalidItemStateException(message.toString(), item.getIdentifier(), ItemState.ADDED, e);
}
// DB2 violation
if (e.getClass().getName().indexOf("SqlIntegrityConstraintViolationException") >= 0
&& errMessage.indexOf("SQLCODE=-803") >= 0)
{
message.append("Item already exists.").append(itemInfo);
throw new JCRInvalidItemStateException(message.toString(), item.getIdentifier(), ItemState.ADDED, e);
}
message.append("Error of item add. ").append(itemInfo);
ownException = new RepositoryException(message.toString(), e);
throw ownException;
}
}
catch (Exception ep)
{
// no parent or error access it
if (ownException != null)
throw ownException;
}
message.append("Error of item add. ").append(itemInfo);
throw new JCRInvalidItemStateException(message.toString(), item.getIdentifier(), ItemState.ADDED, e);
}