{
throw new ReferentialIntegrityException("There are Reference property pointed to this Version "
+ refs.get(0).getQPath().getAsString());
}
PlainChangesLog changes = new PlainChangesLogImpl(session.getId());
// remove labels first
try
{
for (PropertyData vlabel : getData().getVersionLabels())
{
String versionUuid = new String(vlabel.getValues().get(0).getAsByteArray());
if (versionUuid.equals(version.getInternalIdentifier()))
{
changes.add(ItemState.createDeletedState(vlabel));
}
}
}
catch (IOException e)
{
throw new RepositoryException("Get version " + version.getPath() + " labels error " + e, e);
}
// remove this version from successor anf predecessor list
// and point successor to predecessor directly
PropertyData successorsData =
(PropertyData)dataManager.getItemData((NodeData)version.getData(),
new QPathEntry(Constants.JCR_SUCCESSORS, 0), ItemType.PROPERTY);
// jcr:predecessors
PropertyData predecessorsData =
(PropertyData)dataManager.getItemData((NodeData)version.getData(), new QPathEntry(Constants.JCR_PREDECESSORS,
0), ItemType.PROPERTY);
try
{
for (ValueData pvalue : predecessorsData.getValues())
{
String pidentifier = new String(pvalue.getAsByteArray());
VersionImpl predecessor = (VersionImpl)dataManager.getItemByIdentifier(pidentifier, false);
// actually predecessor is V2's successor
if (predecessor != null)
{// V2's successor
if (successorsData != null)
{// to redirect V2's successor
// case of VH graph merge
for (ValueData svalue : successorsData.getValues())
{
predecessor.removeAddSuccessor(version.getInternalIdentifier(),
new String(svalue.getAsByteArray()), changes);
}
}
else
{
// case of VH last version remove
predecessor.removeSuccessor(version.getInternalIdentifier(), changes);
}
}
else
{
throw new RepositoryException("A predecessor (" + pidentifier + ") of the version " + version.getPath()
+ " is not found.");
}
}
}
catch (IOException e)
{
throw new RepositoryException("Get predecessor " + version.getPath() + " error " + e, e);
}
try
{
if (successorsData != null)
{
for (ValueData svalue : successorsData.getValues())
{
String sidentifier = new String(svalue.getAsByteArray());
VersionImpl successor = (VersionImpl)dataManager.getItemByIdentifier(sidentifier, false);
if (successor != null)
{
// case of VH graph merge
for (ValueData pvalue : predecessorsData.getValues())
{
successor.removeAddPredecessor(version.getInternalIdentifier(),
new String(pvalue.getAsByteArray()), changes);
}
}
else
{
throw new RepositoryException("A successor (" + sidentifier + ") of the version " + version.getPath()
+ " is not found.");
}
}
}
}
catch (IOException e)
{
throw new RepositoryException("Get successor " + version.getPath() + " error " + e, e);
}
ItemDataRemoveVisitor removeVisitor = new ItemDataRemoveVisitor(dataManager.getTransactManager(), null);
version.getData().accept(removeVisitor);
changes.addAll(removeVisitor.getRemovedStates());
dataManager.getTransactManager().save(changes);
version.invalidate();
}