diff --git a/config/alfresco/dao/dao-context.xml b/config/alfresco/dao/dao-context.xml
index ffb06d2eb0..9612d5ec20 100644
--- a/config/alfresco/dao/dao-context.xml
+++ b/config/alfresco/dao/dao-context.xml
@@ -85,7 +85,24 @@
-
+
+
+ nodeDAO.#bean.dialect#
+
+
+ org.alfresco.repo.domain.node.NodeDAO
+
+
+ org.hibernate.dialect.Dialect
+
+
+
+
+
+
+
+
+
@@ -104,6 +121,8 @@
+
+
diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-SubscriptionTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-SubscriptionTables.sql
index 650c7268ad..4f937c7ce4 100644
--- a/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-SubscriptionTables.sql
+++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-SubscriptionTables.sql
@@ -7,7 +7,8 @@
-- Please contact support@alfresco.com if you need assistance with the upgrade.
--
-CREATE TABLE alf_subscriptions (
+CREATE TABLE alf_subscriptions
+(
user_node_id BIGINT NOT NULL,
node_id BIGINT NOT NULL,
PRIMARY KEY (user_node_id, node_id),
diff --git a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-SubscriptionTables.sql b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-SubscriptionTables.sql
index f5a676feba..51adfd9209 100644
--- a/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-SubscriptionTables.sql
+++ b/config/alfresco/dbscripts/create/org.hibernate.dialect.PostgreSQLDialect/AlfrescoCreate-SubscriptionTables.sql
@@ -7,13 +7,15 @@
-- Please contact support@alfresco.com if you need assistance with the upgrade.
--
-CREATE TABLE alf_subscriptions (
+CREATE TABLE alf_subscriptions
+(
user_node_id INT8 NOT NULL,
node_id INT8 NOT NULL,
PRIMARY KEY (user_node_id, node_id),
CONSTRAINT fk_alf_sub_user FOREIGN KEY (user_node_id) REFERENCES alf_node(id) ON DELETE CASCADE,
CONSTRAINT fk_alf_sub_node FOREIGN KEY (node_id) REFERENCES alf_node(id) ON DELETE CASCADE
);
+CREATE INDEX fk_alf_sub_node ON alf_subscriptions (node_id);
--
-- Record script finish
diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml
index 6d4beedb45..a311997916 100644
--- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml
+++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/node-common-SqlMap.xml
@@ -539,6 +539,13 @@
+
+ delete from alf_subscriptions
+ where
+ user_node_id = #{idOne} or
+ node_id = #{idOne}
+
+
delete from alf_child_assoc
where
diff --git a/source/java/org/alfresco/repo/domain/node/AbstractNodeDAOImpl.java b/source/java/org/alfresco/repo/domain/node/AbstractNodeDAOImpl.java
index d813b0581d..838e627f23 100644
--- a/source/java/org/alfresco/repo/domain/node/AbstractNodeDAOImpl.java
+++ b/source/java/org/alfresco/repo/domain/node/AbstractNodeDAOImpl.java
@@ -1757,6 +1757,9 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
deleteNodeAssocsToAndFrom(nodeId);
deleteChildAssocsToAndFrom(nodeId);
+ // Remove subscriptions
+ deleteSubscriptions(nodeId);
+
int count = updateNode(nodeUpdate);
if (count != 1)
{
@@ -3891,6 +3894,8 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
QName assocTypeQName,
QName assocQName,
String childNodeName);
+
+ protected abstract void deleteSubscriptions(Long nodeId);
protected abstract Transaction selectLastTxnBeforeCommitTime(Long maxCommitTime);
protected abstract int selectTransactionCount();
diff --git a/source/java/org/alfresco/repo/domain/node/ibatis/NodeDAOImpl.java b/source/java/org/alfresco/repo/domain/node/ibatis/NodeDAOImpl.java
index 2ab3900368..b4ff691417 100644
--- a/source/java/org/alfresco/repo/domain/node/ibatis/NodeDAOImpl.java
+++ b/source/java/org/alfresco/repo/domain/node/ibatis/NodeDAOImpl.java
@@ -120,6 +120,7 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
"alfresco.node.select_ChildAssocsOfParentWithoutParentAssocsOfType";
private static final String SELECT_PARENT_ASSOCS_OF_CHILD = "alfresco.node.select_ParentAssocsOfChild";
private static final String UPDATE_PARENT_ASSOCS_OF_CHILD = "alfresco.node.update_ParentAssocsOfChild";
+ private static final String DELETE_SUBSCRIPTIONS = "alfresco.node.delete_Subscriptions";
private static final String SELECT_TXN_LAST = "alfresco.node.select_TxnLast";
private static final String SELECT_TXN_NODES = "alfresco.node.select_TxnNodes";
private static final String SELECT_TXNS = "alfresco.node.select_Txns";
@@ -134,7 +135,7 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
private SqlSessionTemplate template;
- public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
+ public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
{
this.template = sqlSessionTemplate;
}
@@ -1312,6 +1313,15 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
return template.update(UPDATE_PARENT_ASSOCS_OF_CHILD, assoc);
}
+ /**
+ * The default implementation relies on ON DELETE CASCADE and the
+ * subscriptions avoiding deleted nodes - NoOp.
+ */
+ @Override
+ protected void deleteSubscriptions(Long nodeId)
+ {
+ }
+
@SuppressWarnings("unchecked")
@Override
protected Transaction selectLastTxnBeforeCommitTime(Long maxCommitTime)
@@ -1471,4 +1481,30 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
resultsCallback.done();
}
}
+
+ /*
+ * DAO OVERRIDES
+ */
+
+ /**
+ * MSSQL requires some overrides to handle specific behaviour.
+ */
+ public static class MSSQL extends NodeDAOImpl
+ {
+ private SqlSessionTemplate template;
+
+ public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
+ {
+ this.template = sqlSessionTemplate;
+ }
+
+ /**
+ * Overrides the super class's NO-OP to cascade-delete subscriptions in code.
+ */
+ @Override
+ protected void deleteSubscriptions(Long nodeId)
+ {
+ template.delete(DELETE_SUBSCRIPTIONS, nodeId);
+ }
+ }
}
\ No newline at end of file