diff --git a/config/alfresco/messages/patch-service.properties b/config/alfresco/messages/patch-service.properties index ba961fc99f..da17475e2d 100644 --- a/config/alfresco/messages/patch-service.properties +++ b/config/alfresco/messages/patch-service.properties @@ -143,4 +143,7 @@ patch.groupNamesAsIdentifiers.result=Reindex usr:authorityContainer gids as iden patch.invalidUserPersonAndGroup.description=Fix up invalid uids for people and users; and invalid gids for groups patch.invalidUserPersonAndGroup.result=Fixed ''{0}'' invalid user nodes, ''{1}'' invalid person nodes and ''{2}'' invalid authority nodes. +patch.AVMGuidPatch.description=Set GUIDs on AVM nodes. +patch.AVMGuidPatch.result=AVM GUIDS set. + patch.webscripts.description=Adds Web Scripts to Data Dictionary. diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 9cf1d622e6..1c2d7b2b80 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -703,6 +703,17 @@ + + patch.AVMGuidPatch + patch.AVMGuidPatch.description + 0 + 40 + 41 + + + + + patch.webscripts patch.webscripts.description diff --git a/source/java/org/alfresco/repo/admin/patch/impl/AVMGuidPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/AVMGuidPatch.java new file mode 100644 index 0000000000..a331c98c0c --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/AVMGuidPatch.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing + */ + +package org.alfresco.repo.admin.patch.impl; + +import java.util.List; + +import org.alfresco.i18n.I18NUtil; +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.avm.AVMNode; +import org.alfresco.repo.avm.AVMNodeDAO; +import org.alfresco.util.GUID; + +/** + * This makes sure that all GUIDs in AVM nodes are set. + * @author britt + */ +public class AVMGuidPatch extends AbstractPatch +{ + private AVMNodeDAO fAVMNodeDAO; + + private static final String MSG_SUCCESS = "patch.AVMGuidPatch.result"; + + public AVMGuidPatch() + { + } + + public void setAvmNodeDao(AVMNodeDAO dao) + { + fAVMNodeDAO = dao; + } + + /* (non-Javadoc) + * @see org.alfresco.repo.admin.patch.AbstractPatch#applyInternal() + */ + @Override + protected String applyInternal() throws Exception + { + while (true) + { + List batch = fAVMNodeDAO.getEmptyGUIDS(200); + for (AVMNode node : batch) + { + node.setGuid(GUID.generate()); + } + if (batch.size() == 0) + { + break; + } + fAVMNodeDAO.flush(); + } + + return I18NUtil.getMessage(MSG_SUCCESS); + } +} diff --git a/source/java/org/alfresco/repo/avm/AVMNodeDAO.java b/source/java/org/alfresco/repo/avm/AVMNodeDAO.java index 6d0ecf579c..31b5a59fed 100644 --- a/source/java/org/alfresco/repo/avm/AVMNodeDAO.java +++ b/source/java/org/alfresco/repo/avm/AVMNodeDAO.java @@ -22,6 +22,7 @@ * http://www.alfresco.com/legal/licensing" */ package org.alfresco.repo.avm; +import java.util.Iterator; import java.util.List; /** @@ -99,4 +100,10 @@ public interface AVMNodeDAO * Inappropriate hack to get Hibernate to play nice. */ public void flush(); + + /** + * Get a batch + * @return An iterator over all nodes. + */ + List getEmptyGUIDS(int count); } diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml index 35dc1d15a7..ca8da6c1f3 100644 --- a/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml +++ b/source/java/org/alfresco/repo/avm/hibernate/AVM.hbm.xml @@ -32,7 +32,7 @@ won't cause violations in the db during saves. --> - + diff --git a/source/java/org/alfresco/repo/avm/hibernate/AVMNodeDAOHibernate.java b/source/java/org/alfresco/repo/avm/hibernate/AVMNodeDAOHibernate.java index c5c6581fd3..6b27ccd25f 100644 --- a/source/java/org/alfresco/repo/avm/hibernate/AVMNodeDAOHibernate.java +++ b/source/java/org/alfresco/repo/avm/hibernate/AVMNodeDAOHibernate.java @@ -172,4 +172,15 @@ class AVMNodeDAOHibernate extends HibernateDaoSupport implements { getSession().flush(); } + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.AVMNodeDAO#getEmptyGUIDS(int) + */ + @SuppressWarnings("unchecked") + public List getEmptyGUIDS(int count) + { + Query query = getSession().createQuery("from AVMNodeImpl an where an.guid is null"); + query.setMaxResults(count); + return (List)query.list(); + } }