private static bool SaveNodeDataTransactional(Node node, NodeSaveSettings settings, out IndexDocumentData indexDocument)
{
indexDocument = null;
var data = node.Data;
var isNewNode = data.Id == 0;
var isLocalTransaction = !TransactionScope.IsActive;
if (isLocalTransaction)
TransactionScope.Begin();
try
{
data.CreateSnapshotData();
var participant = new NodeDataParticipant { Data = data, Settings = settings, IsNewNode = isNewNode };
TransactionScope.Participate(participant);
int lastMajorVersionId, lastMinorVersionId;
DataProvider.Current.SaveNodeData(data, settings, out lastMajorVersionId, out lastMinorVersionId);
//-- here we re-create the node head to insert it into the cache and refresh the version info
if (lastMajorVersionId > 0 || lastMinorVersionId > 0)
{
var head = NodeHead.CreateFromNode(node, lastMinorVersionId, lastMajorVersionId);
if (MustCache(node.NodeType))
{
//-- participate cache items
var idKey = CreateNodeHeadIdCacheKey(head.Id);
var participant2 = new InsertCacheParticipant { CacheKey = idKey };
TransactionScope.Participate(participant2);
var pathKey = CreateNodeHeadPathCacheKey(head.Path);
var participant3 = new InsertCacheParticipant { CacheKey = pathKey };
TransactionScope.Participate(participant3);
CacheNodeHead(head, idKey, pathKey);
}
node.RefreshVersionInfo(head);
if (!settings.DeletableVersionIds.Contains(node.VersionId))
indexDocument = SaveIndexDocument(node);
}
if (isLocalTransaction)
TransactionScope.Commit();
}
catch (System.Data.Common.DbException dbe)
{
if (isLocalTransaction && IsDeadlockException(dbe))
return false;
throw SavingExceptionHelper(data, dbe);
}
catch (Exception e)
{
var ee = SavingExceptionHelper(data, e);
if (ee == e)
throw;
else
throw ee;
}
finally
{
if (isLocalTransaction && TransactionScope.IsActive)
TransactionScope.Rollback();
}
return true;
}
private static bool MustCache(NodeType nodeType)