mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String, Object> result = (Map<String, Object>)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<String, String> lockData = new HashMap<String, String>(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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String, Object> result = (Map<String, Object>)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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String> 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;
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String, String> attributeMap = new HashMap<String, String>(10);
|
||||
private String currentComponentName = "";
|
||||
|
||||
private PBBRowHandler()
|
||||
{
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
public void handleRow(Object valueObject)
|
||||
{
|
||||
Map<String, Object> result = (Map<String, Object>)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<String, String> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<String, Object> result = (Map<String, Object>)valueObject;
|
||||
|
||||
String tenantDomain = (String)result.get("tenantDomain");
|
||||
Boolean isEnabled = (Boolean)result.get("isEnabled");
|
||||
String rootDir = (String)result.get("rootDir");
|
||||
|
||||
Map<String, Serializable> tenantAttributes = new HashMap<String, Serializable>(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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user