From b111e47cc655d8ea190044efedf0e6c08edb6245 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Fri, 25 Jun 2010 15:02:56 +0000 Subject: [PATCH] SAIL-239 - Attributes DAO refactor (patches to migrate in-built attributes) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20822 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../patch-common-SqlMap.xml | 126 ++++++++++++++- .../messages/patch-service.properties | 18 ++- .../alfresco/patch/patch-services-context.xml | 86 +++++++++++ config/alfresco/version.properties | 2 +- .../patch/impl/MigrateAttrAVMLocksPatch.java | 122 +++++++++++++++ .../impl/MigrateAttrChainingURSPatch.java | 110 +++++++++++++ .../patch/impl/MigrateAttrDeletePatch.java | 70 +++++++++ .../impl/MigrateAttrPropBackedBeanPatch.java | 144 ++++++++++++++++++ .../patch/impl/MigrateAttrTenantsPatch.java | 119 +++++++++++++++ .../domain/patch/AbstractPatchDAOImpl.java | 56 ++++++- .../alfresco/repo/domain/patch/PatchDAO.java | 32 ++++ .../domain/patch/ibatis/PatchDAOImpl.java | 67 +++++++- .../ChainingUserRegistrySynchronizer.java | 2 +- .../repo/tenant/MultiTAdminServiceImpl.java | 6 +- 14 files changed, 943 insertions(+), 17 deletions(-) create mode 100644 source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrAVMLocksPatch.java create mode 100644 source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrChainingURSPatch.java create mode 100644 source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrDeletePatch.java create mode 100644 source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrPropBackedBeanPatch.java create mode 100644 source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrTenantsPatch.java diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/patch-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/patch-common-SqlMap.xml index 6ef08ee713..ae448d331c 100644 --- a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/patch-common-SqlMap.xml +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/patch-common-SqlMap.xml @@ -11,7 +11,7 @@ - + @@ -45,6 +45,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + @@ -169,7 +194,82 @@ np.qname_id = #propQNameId# and np.string_value like #namePattern# - + + + + + + + + + + + @@ -207,5 +307,25 @@ where id = ? - + + + + + + + delete from alf_list_attribute_entries + + + + delete from alf_map_attribute_entries + + + + delete from alf_global_attributes + + + + delete from alf_attributes + + \ No newline at end of file diff --git a/config/alfresco/messages/patch-service.properties b/config/alfresco/messages/patch-service.properties index 3ab8208ef5..94da4838ba 100644 --- a/config/alfresco/messages/patch-service.properties +++ b/config/alfresco/messages/patch-service.properties @@ -341,4 +341,20 @@ patch.fixAuthoritiesCrcValues.unableToChange=Failed to update the CRC32 value fo patch.updateMimetypes1.description=Fix mimetypes for Excel and Powerpoint. -patch.db-V3.2-AddFKIndexes.description=Fixes ALF-3189: Added missing FK indexes. Note: The script is empty for MySQL. \ No newline at end of file +patch.db-V3.2-AddFKIndexes.description=Fixes ALF-3189: Added missing FK indexes. Note: The script is empty for MySQL. + +patch.migrateAttrTenants.description=Migrate old Tenant attributes +patch.migrateAttrTenants.result=Processed {0} attributes + +patch.migrateAttrAVMLocks.description=Migrate old AVM Lock attributes +patch.migrateAttrAVMLocks.result=Processed {0} attributes + +patch.migrateAttrPropBackedBeans.description=Migrate old Property-Backed Bean component attributes +patch.migrateAttrPropBackedBeans.result=Processed {0} attributes ({1} properties) + +patch.migrateAttrChainingURS.description=Migrate old Chaining User Registry Synchronizer attributes +patch.migrateAttrChainingURS.result=Processed {0} attributes + +patch.migrateAttrDelete.description=Delete old attributes (if any) after they have been migrated +patch.migrateAttrDelete.result=Old attributes were deleted (if any) + diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index 129d224334..f150f21715 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -2263,5 +2263,91 @@ classpath:alfresco/dbscripts/upgrade/3.3/${db.script.dialect}/node-prop-serializable.sql + + + patch.migrateAttrTenants + patch.migrateAttrTenants.description + 0 + 4106 + 4107 + false + + + + + + + + + + + patch.migrateAttrAVMLocks + patch.migrateAttrAVMLocks.description + 0 + 4106 + 4107 + false + + + + + + + + + + + patch.migrateAttrPropBackedBeans + patch.migrateAttrPropBackedBeans.description + 0 + 4106 + 4107 + false + + + + + + + + + + + patch.migrateAttrChainingURS + patch.migrateAttrChainingURS.description + 0 + 4106 + 4107 + false + + + + + + + + + + + patch.migrateAttrDelete + patch.migrateAttrDelete.description + 0 + 4106 + 4107 + false + + + + + + + + + + + + + + \ No newline at end of file diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index 40f60eaeab..1ad3094ab6 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -19,4 +19,4 @@ version.build=@build-number@ # Schema number -version.schema=4106 +version.schema=4107 diff --git a/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrAVMLocksPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrAVMLocksPatch.java new file mode 100644 index 0000000000..115ab49ef7 --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrAVMLocksPatch.java @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.admin.patch.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.avm.locking.AVMLockingServiceImpl; +import org.alfresco.repo.domain.patch.PatchDAO; +import org.alfresco.service.cmr.attributes.AttributeService; +import org.alfresco.wcm.util.WCMUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.surf.util.I18NUtil; + +import com.ibatis.sqlmap.client.event.RowHandler; + +/** + * Migrate AVM lock attributes (from 'alf_*attribute*' to 'alf_prop_*') + * + * @author janv + * @since 3.4 + */ +public class MigrateAttrAVMLocksPatch extends AbstractPatch +{ + private Log logger = LogFactory.getLog(this.getClass()); + + private static final String MSG_SUCCESS = "patch.migrateAttrAVMLocks.result"; + + private AttributeService attributeService; + private PatchDAO patchDAO; + + public void setAttributeService(AttributeService attributeService) + { + this.attributeService = attributeService; + } + + public void setPatchDAO(PatchDAO patchDAO) + { + this.patchDAO = patchDAO; + } + + @Override + protected String applyInternal() throws Exception + { + long startTime = System.currentTimeMillis(); + + AVMLockRowHandler handler = new AVMLockRowHandler(); + patchDAO.migrateOldAttrAVMLocks(handler); + + if (handler.total > 0) + { + logger.info("Processed "+handler.total+" AVM Lock attrs in "+(System.currentTimeMillis()-startTime)/1000+" secs"); + } + + // build the result message + String msg = I18NUtil.getMessage(MSG_SUCCESS, handler.total); + // done + return msg; + } + + /** + * Row handler for migrating AVM Locks + */ + private class AVMLockRowHandler implements RowHandler + { + private int total = 0; + + private AVMLockRowHandler() + { + } + @SuppressWarnings("unchecked") + public void handleRow(Object valueObject) + { + Map result = (Map)valueObject; + + String wpStoreId = (String)result.get("wpStoreId"); + String relPath = (String)result.get("relPath"); + String avmStore = (String)result.get("avmStore"); + String lockOwner = (String)result.get("owner1"); + + relPath = AVMLockingServiceImpl.normalizePath(relPath); + + HashMap lockData = new HashMap(2); + lockData.put(AVMLockingServiceImpl.KEY_LOCK_OWNER, lockOwner); + lockData.put(WCMUtil.LOCK_KEY_STORE_NAME, avmStore); + + attributeService.createAttribute( + lockData, + AVMLockingServiceImpl.KEY_AVM_LOCKS, wpStoreId, relPath); + + if (logger.isTraceEnabled()) + { + logger.trace("Set AVM Lock attr [wpStoreId="+wpStoreId+", relPath="+relPath+", lockOwner="+lockOwner+", avmStore="+avmStore+"]"); + } + + total++; + + if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) + { + logger.debug(" Handled " + total + " AVM Lock attributes"); + } + } + } +} diff --git a/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrChainingURSPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrChainingURSPatch.java new file mode 100644 index 0000000000..28a97ded0e --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrChainingURSPatch.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.admin.patch.impl; + +import java.util.Map; + +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.domain.patch.PatchDAO; +import org.alfresco.repo.security.sync.ChainingUserRegistrySynchronizer; +import org.alfresco.service.cmr.attributes.AttributeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.surf.util.I18NUtil; + +import com.ibatis.sqlmap.client.event.RowHandler; + +/** + * Migrate Chaining User Registry Synchronizer attributes (from 'alf_*attribute*' to 'alf_prop_*') + * + * @author janv + * @since 3.4 + */ +public class MigrateAttrChainingURSPatch extends AbstractPatch +{ + private Log logger = LogFactory.getLog(this.getClass()); + + private static final String MSG_SUCCESS = "patch.migrateAttrChainingURS.result"; + + private AttributeService attributeService; + private PatchDAO patchDAO; + + public void setAttributeService(AttributeService attributeService) + { + this.attributeService = attributeService; + } + + public void setPatchDAO(PatchDAO patchDAO) + { + this.patchDAO = patchDAO; + } + + @Override + protected String applyInternal() throws Exception + { + long startTime = System.currentTimeMillis(); + + ChainingURSRowHandler handler = new ChainingURSRowHandler(); + patchDAO.migrateOldAttrChainingURS(handler); + + if (handler.total > 0) + { + logger.info("Processed "+handler.total+" Chaining URS attrs in "+(System.currentTimeMillis()-startTime)/1000+" secs"); + } + + // build the result message + String msg = I18NUtil.getMessage(MSG_SUCCESS, handler.total); + // done + return msg; + } + + private class ChainingURSRowHandler implements RowHandler + { + private int total = 0; + + private ChainingURSRowHandler() + { + } + @SuppressWarnings("unchecked") + public void handleRow(Object valueObject) + { + Map result = (Map)valueObject; + + String label = (String)result.get("label"); + String zoneId = (String)result.get("zoneId"); + Long lastModified = (Long)result.get("lastModified"); + + attributeService.setAttribute( + lastModified, + ChainingUserRegistrySynchronizer.ROOT_ATTRIBUTE_PATH, label, zoneId); + + if (logger.isTraceEnabled()) + { + logger.trace("Set Chaining URS attr [label="+label+", zoneId="+zoneId+", lastModified="+lastModified+"]"); + } + + total++; + + if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) + { + logger.debug(" Handled " + total + " Chaining URS attributes"); + } + } + } +} diff --git a/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrDeletePatch.java b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrDeletePatch.java new file mode 100644 index 0000000000..6d4534280a --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrDeletePatch.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.admin.patch.impl; + +import java.util.List; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.domain.patch.PatchDAO; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.surf.util.I18NUtil; + +/** + * Migrate attributes - check no custom attributes and then delete from 'alf_*attribute*' tables + * + * @author janv + * @since 3.4 + */ +public class MigrateAttrDeletePatch extends AbstractPatch +{ + private Log logger = LogFactory.getLog(this.getClass()); + + private static final String MSG_SUCCESS = "patch.migrateAttrDelete.result"; + + private PatchDAO patchDAO; + + public void setPatchDAO(PatchDAO patchDAO) + { + this.patchDAO = patchDAO; + } + + @Override + protected String applyInternal() throws Exception + { + List results = patchDAO.getOldAttrCustomNames(); + + if (results.size() > 0) + { + for (String custom : results) + { + logger.warn("Custom global attribute found: "+custom); + } + throw new AlfrescoRuntimeException("Custom attributes found - will require custom migration patch: "+results); + } + + patchDAO.deleteAllOldAttrs(); + + // build the result message + String msg = I18NUtil.getMessage(MSG_SUCCESS); + // done + return msg; + } +} diff --git a/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrPropBackedBeanPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrPropBackedBeanPatch.java new file mode 100644 index 0000000000..558dd486c3 --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrPropBackedBeanPatch.java @@ -0,0 +1,144 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.admin.patch.impl; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.domain.patch.PatchDAO; +import org.alfresco.service.cmr.attributes.AttributeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.surf.util.I18NUtil; + +import com.ibatis.sqlmap.client.event.RowHandler; + +/** + * Migrate Property-Backed Bean attributes (from 'alf_*attribute*' to 'alf_prop_*') + * + * @author janv + * @since 3.4 + */ +public class MigrateAttrPropBackedBeanPatch extends AbstractPatch +{ + private Log logger = LogFactory.getLog(this.getClass()); + + private static final String ROOT_KEY_PBB = ".PropertyBackedBeans"; // see also PropertyBackBeanAdapter.ROOT_ATTRIBUTE_PATH + + private static final String MSG_SUCCESS = "patch.migrateAttrPropBackedBeans.result"; + + private AttributeService attributeService; + private PatchDAO patchDAO; + + public void setAttributeService(AttributeService attributeService) + { + this.attributeService = attributeService; + } + + public void setPatchDAO(PatchDAO patchDAO) + { + this.patchDAO = patchDAO; + } + + @Override + protected String applyInternal() throws Exception + { + long startTime = System.currentTimeMillis(); + + PBBRowHandler handler = new PBBRowHandler(); + patchDAO.migrateOldAttrPropertyBackedBeans(handler); + handler.setComponent(handler.currentComponentName, handler.attributeMap); // set last component attribute (if any) + + if (handler.total > 0) + { + logger.info("Processed "+handler.total+" Property-Backed Component attrs ("+handler.totalProps+" props) in "+(System.currentTimeMillis()-startTime)/1000+" secs"); + } + + // build the result message + String msg = I18NUtil.getMessage(MSG_SUCCESS, handler.total, handler.totalProps); + // done + return msg; + } + + private class PBBRowHandler implements RowHandler + { + private int total = 0; + private int totalProps = 0; + + private Map attributeMap = new HashMap(10); + private String currentComponentName = ""; + + private PBBRowHandler() + { + } + @SuppressWarnings("unchecked") + public void handleRow(Object valueObject) + { + Map result = (Map)valueObject; + + String componentName = (String)result.get("componentName"); + String propName = (String)result.get("propName"); + String propValue = (String)result.get("propValue"); + + if (! currentComponentName.equals(componentName)) + { + // write out previous component - note: does nothing on 1st call + setComponent(currentComponentName, attributeMap); + + currentComponentName = componentName; + attributeMap.clear(); + } + + attributeMap.put(propName, propValue); + + totalProps++; + + if (logger.isTraceEnabled()) + { + logger.trace("Read PBB [componentName="+componentName+", propName="+propName+", propValue="+propValue+"]"); + } + } + + // note: args should not be null + public void setComponent(String componentName, Map attributeMap) + { + if (componentName.equals("") || attributeMap.size() == 0) + { + return; + } + attributeService.setAttribute( + (Serializable) attributeMap, + ROOT_KEY_PBB, componentName); + + if (logger.isTraceEnabled()) + { + logger.trace("Set PBB component attr [name="+componentName+", attributeMap="+attributeMap+"]"); + } + + total++; + + if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) + { + logger.debug(" Handled " + total + " Chaining URS attrs"); + } + } + } +} diff --git a/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrTenantsPatch.java b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrTenantsPatch.java new file mode 100644 index 0000000000..5746684a50 --- /dev/null +++ b/source/java/org/alfresco/repo/admin/patch/impl/MigrateAttrTenantsPatch.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ +package org.alfresco.repo.admin.patch.impl; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +import org.alfresco.repo.admin.patch.AbstractPatch; +import org.alfresco.repo.domain.patch.PatchDAO; +import org.alfresco.repo.tenant.MultiTAdminServiceImpl; +import org.alfresco.service.cmr.attributes.AttributeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.surf.util.I18NUtil; + +import com.ibatis.sqlmap.client.event.RowHandler; + +/** + * Migrate Tenant attributes (from 'alf_*attribute*' to 'alf_prop_*') + * + * @author janv + * @since 3.4 + */ +public class MigrateAttrTenantsPatch extends AbstractPatch +{ + private Log logger = LogFactory.getLog(this.getClass()); + + private static final String MSG_SUCCESS = "patch.migrateAttrTenants.result"; + + private AttributeService attributeService; + private PatchDAO patchDAO; + + public void setAttributeService(AttributeService attributeService) + { + this.attributeService = attributeService; + } + + public void setPatchDAO(PatchDAO patchDAO) + { + this.patchDAO = patchDAO; + } + + @Override + protected String applyInternal() throws Exception + { + long startTime = System.currentTimeMillis(); + + TenantRowHandler handler = new TenantRowHandler(); + patchDAO.migrateOldAttrTenants(handler); + + if (handler.total > 0) + { + logger.info("Processed "+handler.total+" Tenant attrs in "+(System.currentTimeMillis()-startTime)/1000+" secs"); + } + + // build the result message + String msg = I18NUtil.getMessage(MSG_SUCCESS, handler.total); + // done + return msg; + } + + /** + * Row handler for migrating tenants + */ + private class TenantRowHandler implements RowHandler + { + private int total = 0; + + private TenantRowHandler() + { + } + @SuppressWarnings("unchecked") + public void handleRow(Object valueObject) + { + Map result = (Map)valueObject; + + String tenantDomain = (String)result.get("tenantDomain"); + Boolean isEnabled = (Boolean)result.get("isEnabled"); + String rootDir = (String)result.get("rootDir"); + + Map tenantAttributes = new HashMap(7); + tenantAttributes.put(MultiTAdminServiceImpl.TENANT_ATTRIBUTE_ENABLED, isEnabled.booleanValue()); + tenantAttributes.put(MultiTAdminServiceImpl.TENANT_ATTRIBUTE_ROOT_CONTENT_STORE_DIR, rootDir); + + attributeService.setAttribute( + (Serializable) tenantAttributes, + MultiTAdminServiceImpl.TENANTS_ATTRIBUTE_PATH, tenantDomain); + + if (logger.isTraceEnabled()) + { + logger.trace("Set Tenant attr [tenantDomain="+tenantDomain+", isEnabled="+isEnabled+", rootDir="+rootDir+"]"); + } + + total++; + + if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) + { + logger.debug(" Handled " + total + " tenant attributes"); + } + } + } +} diff --git a/source/java/org/alfresco/repo/domain/patch/AbstractPatchDAOImpl.java b/source/java/org/alfresco/repo/domain/patch/AbstractPatchDAOImpl.java index 81cf8791a1..f5f08ec1cb 100644 --- a/source/java/org/alfresco/repo/domain/patch/AbstractPatchDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/patch/AbstractPatchDAOImpl.java @@ -27,6 +27,8 @@ import org.alfresco.repo.domain.contentdata.ContentDataDAO; import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.StoreRef; +import com.ibatis.sqlmap.client.event.RowHandler; + /** * Abstract implementation for Patch DAO. @@ -162,10 +164,10 @@ public abstract class AbstractPatchDAOImpl implements PatchDAO, BatchingDAO { String stringValue = (String) prop.get("stringValue"); - ContentData contentData = ContentData.createContentProperty(stringValue); - Long contentDataId = contentDataDAO.createContentData(contentData).getFirst(); - prop.put("contentDataId", contentDataId); - } + ContentData contentData = ContentData.createContentProperty(stringValue); + Long contentDataId = contentDataDAO.createContentData(contentData).getFirst(); + prop.put("contentDataId", contentDataId); + } // Now do the updates in the context of a batch try @@ -231,4 +233,50 @@ public abstract class AbstractPatchDAOImpl implements PatchDAO, BatchingDAO protected abstract int deleteDanglingAceEntities(); protected abstract int deleteAclEntities(List aclIds); protected abstract int deleteAclMemberEntitiesForAcls(List aclIds); + + // note: caller's row handler is expected to migrate the attrs + public void migrateOldAttrTenants(RowHandler rowHandler) + { + getOldAttrTenantsImpl(rowHandler); + } + + protected abstract void getOldAttrTenantsImpl(RowHandler rowHandler); + + // note: caller's row handler is expected to migrate the attrs + public void migrateOldAttrAVMLocks(RowHandler rowHandler) + { + getOldAttrAVMLocksImpl(rowHandler); + } + + protected abstract void getOldAttrAVMLocksImpl(RowHandler rowHandler); + + // note: caller's row handler is expected to migrate the attrs + public void migrateOldAttrPropertyBackedBeans(RowHandler rowHandler) + { + getOldAttrPropertyBackedBeansImpl(rowHandler); + } + + protected abstract void getOldAttrPropertyBackedBeansImpl(RowHandler rowHandler); + + // note: caller's row handler is expected to migrate the attrs + public void migrateOldAttrChainingURS(RowHandler rowHandler) + { + getOldAttrChainingURSImpl(rowHandler); + } + + protected abstract void getOldAttrChainingURSImpl(RowHandler rowHandler); + + public List getOldAttrCustomNames() + { + return getOldAttrCustomNamesImpl(); + } + + protected abstract List getOldAttrCustomNamesImpl(); + + public void deleteAllOldAttrs() + { + deleteAllOldAttrsImpl(); + } + + protected abstract void deleteAllOldAttrsImpl(); } diff --git a/source/java/org/alfresco/repo/domain/patch/PatchDAO.java b/source/java/org/alfresco/repo/domain/patch/PatchDAO.java index bc456d3842..7cf57839d9 100644 --- a/source/java/org/alfresco/repo/domain/patch/PatchDAO.java +++ b/source/java/org/alfresco/repo/domain/patch/PatchDAO.java @@ -29,6 +29,8 @@ import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; +import com.ibatis.sqlmap.client.event.RowHandler; + /** * Additional DAO services for patches * @@ -176,4 +178,34 @@ public interface PatchDAO * @return Returns the node ID and node name */ public List> getNodesOfTypeWithNamePattern(QName typeQName, String namePattern); + + /** + * Migrate old Tenant attributes (if any) + */ + public void migrateOldAttrTenants(RowHandler rowHandler); + + /** + * Migrate old AVM Lock attributes (if any) + */ + public void migrateOldAttrAVMLocks(RowHandler rowHandler); + + /** + * Migrate old Property-Backed Bean attributes (if any) + */ + public void migrateOldAttrPropertyBackedBeans(RowHandler rowHandler); + + /** + * Migrate old Chaining User Registry Synchronizer attributes (if any) + */ + public void migrateOldAttrChainingURS(RowHandler rowHandler); + + /** + * Get custom global attribute names (if any) + */ + public List getOldAttrCustomNames(); + + /** + * Delete all old attributes (from alf_*attribute* tables) + */ + public void deleteAllOldAttrs(); } diff --git a/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java b/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java index 88d0abf1b9..21621e8172 100644 --- a/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java @@ -85,6 +85,16 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl private static final String DELETE_PERMISSIONS_ACL_LIST = "alfresco.permissions.delete_AclList"; private static final String DELETE_PERMISSIONS_ACL_MEMBERS_FOR_ACL_LIST = "alfresco.permissions.delete_AclMembersForAclList"; + private static final String SELECT_OLD_ATTR_TENANTS = "alfresco.patch.select_oldAttrTenants"; + private static final String SELECT_OLD_ATTR_AVM_LOCKS= "alfresco.patch.select_oldAttrAVMLocks"; + private static final String SELECT_OLD_ATTR_PBBS = "alfresco.patch.select_oldAttrPropertyBackedBeans"; + private static final String SELECT_OLD_ATTR_CHAINING_URS = "alfresco.patch.select_oldAttrChainingURS"; + private static final String SELECT_OLD_ATTR_CUSTOM_NAMES = "alfresco.patch.select_oldAttrCustomNames"; + + private static final String DELETE_OLD_ATTR_LIST = "alfresco.patch.delete_oldAttrAlfListAttributeEntries"; + private static final String DELETE_OLD_ATTR_MAP = "alfresco.patch.delete_oldAttrAlfMapAttributeEntries"; + private static final String DELETE_OLD_ATTR_GLOBAL = "alfresco.patch.delete_oldAttrAlfGlobalAttributes"; + private static final String DELETE_OLD_ATTR = "alfresco.patch.delete_oldAttrAlfAttributes"; private SqlMapClientTemplate template; private QNameDAO qnameDAO; @@ -446,12 +456,12 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl // Done return results; } - + public int getChildAssocCount() { return (Integer) template.queryForObject(SELECT_CHILD_ASSOCS_COUNT); } - + @SuppressWarnings("unchecked") public List> getChildAssocsForCrcFix(Long minAssocId, int maxResults) { @@ -464,7 +474,7 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl // Done return results; } - + public int updateChildAssocCrc(Long assocId, Long childNodeNameCrc, Long qnameCrc) { Map params = new HashMap(); @@ -473,7 +483,7 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl params.put("qnameCrc", qnameCrc); return template.update(UPDATE_CHILD_ASSOC_CRC, params); } - + public List> getNodesOfTypeWithNamePattern(QName typeQName, String namePattern) { Pair typeQNamePair = qnameDAO.getQName(typeQName); @@ -515,4 +525,53 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl template.queryWithRowHandler(SELECT_NODES_BY_TYPE_AND_NAME_PATTERN, params, rowHandler); return results; } + + @Override + protected void getOldAttrTenantsImpl(RowHandler rowHandler) + { + template.queryWithRowHandler(SELECT_OLD_ATTR_TENANTS, rowHandler); + } + + @Override + protected void getOldAttrAVMLocksImpl(RowHandler rowHandler) + { + template.queryWithRowHandler(SELECT_OLD_ATTR_AVM_LOCKS, rowHandler); + } + + @Override + protected void getOldAttrPropertyBackedBeansImpl(RowHandler rowHandler) + { + template.queryWithRowHandler(SELECT_OLD_ATTR_PBBS, rowHandler); + } + + @Override + protected void getOldAttrChainingURSImpl(RowHandler rowHandler) + { + template.queryWithRowHandler(SELECT_OLD_ATTR_CHAINING_URS, rowHandler); + } + + @SuppressWarnings("unchecked") + @Override + protected List getOldAttrCustomNamesImpl() + { + return (List)template.queryForList(SELECT_OLD_ATTR_CUSTOM_NAMES); + } + + @Override + protected void deleteAllOldAttrsImpl() + { + int deleted = 0; + + deleted = template.delete(DELETE_OLD_ATTR_LIST); + logger.info("Deleted "+deleted+" rows from alf_list_attribute_entries"); + + deleted = template.delete(DELETE_OLD_ATTR_MAP); + logger.info("Deleted "+deleted+" rows from alf_map_attribute_entries"); + + deleted = template.delete(DELETE_OLD_ATTR_GLOBAL); + logger.info("Deleted "+deleted+" rows from alf_global_attributes"); + + deleted = template.delete(DELETE_OLD_ATTR); + logger.info("Deleted "+deleted+" rows from alf_attributes"); + } } diff --git a/source/java/org/alfresco/repo/security/sync/ChainingUserRegistrySynchronizer.java b/source/java/org/alfresco/repo/security/sync/ChainingUserRegistrySynchronizer.java index 21e566bf48..5221fc3a62 100644 --- a/source/java/org/alfresco/repo/security/sync/ChainingUserRegistrySynchronizer.java +++ b/source/java/org/alfresco/repo/security/sync/ChainingUserRegistrySynchronizer.java @@ -111,7 +111,7 @@ public class ChainingUserRegistrySynchronizer extends AbstractLifecycleBean impl private static final long LOCK_TTL = 1000 * 60 * 2; /** The path in the attribute service below which we persist attributes. */ - private static final String ROOT_ATTRIBUTE_PATH = ".ChainingUserRegistrySynchronizer"; + public static final String ROOT_ATTRIBUTE_PATH = ".ChainingUserRegistrySynchronizer"; /** The label under which the last group modification timestamp is stored for each zone. */ private static final String GROUP_LAST_MODIFIED_ATTRIBUTE = "GROUP"; diff --git a/source/java/org/alfresco/repo/tenant/MultiTAdminServiceImpl.java b/source/java/org/alfresco/repo/tenant/MultiTAdminServiceImpl.java index 0a095a86f2..6d47997bc6 100644 --- a/source/java/org/alfresco/repo/tenant/MultiTAdminServiceImpl.java +++ b/source/java/org/alfresco/repo/tenant/MultiTAdminServiceImpl.java @@ -218,9 +218,9 @@ public class MultiTAdminServiceImpl implements TenantAdminService, ApplicationCo public static final String STORE_BASE_ID_VERSION2 = "version2Store"; public static final String STORE_BASE_ID_SPACES = "SpacesStore"; - private static final String TENANTS_ATTRIBUTE_PATH = "alfresco-tenants"; - private static final String TENANT_ATTRIBUTE_ENABLED = "enabled"; - private static final String TENANT_ATTRIBUTE_ROOT_CONTENT_STORE_DIR = "rootContentStoreDir"; + public static final String TENANTS_ATTRIBUTE_PATH = "alfresco-tenants"; + public static final String TENANT_ATTRIBUTE_ENABLED = "enabled"; + public static final String TENANT_ATTRIBUTE_ROOT_CONTENT_STORE_DIR = "rootContentStoreDir"; private List tenantDeployers = new ArrayList();