ALF-9990: Schema auto-update fails on MS SQL Server

- Added missing index for FK
 - Added NodeDAO.deleteSubscriptions and only added implementation for MSSQL
 - Removed ON DELETE CASCADE for MSSQL from create scripts


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29968 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2011-08-22 17:40:23 +00:00
parent b459001ca1
commit 24fa893ac3
6 changed files with 74 additions and 4 deletions

View File

@@ -85,7 +85,24 @@
<property name="qnameCache" ref="immutableEntityCache"/> <property name="qnameCache" ref="immutableEntityCache"/>
</bean> </bean>
<bean id="nodeDAO" class="org.alfresco.repo.domain.node.ibatis.NodeDAOImpl" init-method="init"> <bean id="nodeDAO" class="org.alfresco.util.bean.HierarchicalBeanLoader">
<property name="targetBeanName">
<value>nodeDAO.#bean.dialect#</value>
</property>
<property name="targetClass">
<value>org.alfresco.repo.domain.node.NodeDAO</value>
</property>
<property name="dialectBaseClass">
<value>org.hibernate.dialect.Dialect</value>
</property>
<property name="dialectClass">
<bean class="org.springframework.beans.factory.config.PropertyPathFactoryBean">
<property name="targetBeanName" value="dialect" />
<property name="propertyPath" value="class.name" />
</bean>
</property>
</bean>
<bean id="nodeDAObase" abstract="true" init-method="init">
<property name="sqlSessionTemplate" ref="repoSqlSessionTemplate"/> <property name="sqlSessionTemplate" ref="repoSqlSessionTemplate"/>
<property name="enableTimestampPropagation" value="${system.enableTimestampPropagation}" /> <property name="enableTimestampPropagation" value="${system.enableTimestampPropagation}" />
<property name="transactionService" ref="transactionService" /> <property name="transactionService" ref="transactionService" />
@@ -104,6 +121,8 @@
<property name="propertiesCache" ref="node.propertiesCache"/> <property name="propertiesCache" ref="node.propertiesCache"/>
<property name="parentAssocsCache" ref="node.parentAssocsCache"/> <property name="parentAssocsCache" ref="node.parentAssocsCache"/>
</bean> </bean>
<bean id="nodeDAO.org.hibernate.dialect.Dialect" class="org.alfresco.repo.domain.node.ibatis.NodeDAOImpl" parent="nodeDAObase" />
<bean id="nodeDAO.org.alfresco.repo.domain.hibernate.dialect.AlfrescoSQLServerDialect" class="org.alfresco.repo.domain.node.ibatis.NodeDAOImpl$MSSQL" parent="nodeDAO.org.hibernate.dialect.Dialect" />
<bean id="lockDAO" class="org.alfresco.repo.domain.locks.ibatis.LockDAOImpl"> <bean id="lockDAO" class="org.alfresco.repo.domain.locks.ibatis.LockDAOImpl">
<property name="sqlSessionTemplate" ref="locksSqlSessionTemplate"/> <property name="sqlSessionTemplate" ref="locksSqlSessionTemplate"/>

View File

@@ -7,7 +7,8 @@
-- Please contact support@alfresco.com if you need assistance with the upgrade. -- 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, user_node_id BIGINT NOT NULL,
node_id BIGINT NOT NULL, node_id BIGINT NOT NULL,
PRIMARY KEY (user_node_id, node_id), PRIMARY KEY (user_node_id, node_id),

View File

@@ -7,13 +7,15 @@
-- Please contact support@alfresco.com if you need assistance with the upgrade. -- 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, user_node_id INT8 NOT NULL,
node_id INT8 NOT NULL, node_id INT8 NOT NULL,
PRIMARY KEY (user_node_id, node_id), 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_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 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 -- Record script finish

View File

@@ -539,6 +539,13 @@
</foreach> </foreach>
</delete> </delete>
<delete id="delete_NodeSubscriptions" parameterType="java.lang.Long">
delete from alf_subscriptions
where
user_node_id = #{idOne} or
node_id = #{idOne}
</delete>
<delete id="delete_ChildAssocById" parameterType="ChildAssoc"> <delete id="delete_ChildAssocById" parameterType="ChildAssoc">
delete from alf_child_assoc delete from alf_child_assoc
where where

View File

@@ -1757,6 +1757,9 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
deleteNodeAssocsToAndFrom(nodeId); deleteNodeAssocsToAndFrom(nodeId);
deleteChildAssocsToAndFrom(nodeId); deleteChildAssocsToAndFrom(nodeId);
// Remove subscriptions
deleteSubscriptions(nodeId);
int count = updateNode(nodeUpdate); int count = updateNode(nodeUpdate);
if (count != 1) if (count != 1)
{ {
@@ -3891,6 +3894,8 @@ public abstract class AbstractNodeDAOImpl implements NodeDAO, BatchingDAO
QName assocTypeQName, QName assocTypeQName,
QName assocQName, QName assocQName,
String childNodeName); String childNodeName);
protected abstract void deleteSubscriptions(Long nodeId);
protected abstract Transaction selectLastTxnBeforeCommitTime(Long maxCommitTime); protected abstract Transaction selectLastTxnBeforeCommitTime(Long maxCommitTime);
protected abstract int selectTransactionCount(); protected abstract int selectTransactionCount();

View File

@@ -120,6 +120,7 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
"alfresco.node.select_ChildAssocsOfParentWithoutParentAssocsOfType"; "alfresco.node.select_ChildAssocsOfParentWithoutParentAssocsOfType";
private static final String SELECT_PARENT_ASSOCS_OF_CHILD = "alfresco.node.select_ParentAssocsOfChild"; 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 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_LAST = "alfresco.node.select_TxnLast";
private static final String SELECT_TXN_NODES = "alfresco.node.select_TxnNodes"; private static final String SELECT_TXN_NODES = "alfresco.node.select_TxnNodes";
private static final String SELECT_TXNS = "alfresco.node.select_Txns"; private static final String SELECT_TXNS = "alfresco.node.select_Txns";
@@ -134,7 +135,7 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
private SqlSessionTemplate template; private SqlSessionTemplate template;
public final void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate)
{ {
this.template = sqlSessionTemplate; this.template = sqlSessionTemplate;
} }
@@ -1312,6 +1313,15 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
return template.update(UPDATE_PARENT_ASSOCS_OF_CHILD, assoc); return template.update(UPDATE_PARENT_ASSOCS_OF_CHILD, assoc);
} }
/**
* The default implementation relies on <b>ON DELETE CASCADE</b> and the
* subscriptions avoiding deleted nodes - NoOp.
*/
@Override
protected void deleteSubscriptions(Long nodeId)
{
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected Transaction selectLastTxnBeforeCommitTime(Long maxCommitTime) protected Transaction selectLastTxnBeforeCommitTime(Long maxCommitTime)
@@ -1471,4 +1481,30 @@ public class NodeDAOImpl extends AbstractNodeDAOImpl
resultsCallback.done(); 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);
}
}
} }