Merged BRANCHES/V3.2 to HEAD:

19714: Added dialect-driven bean factory, HierarchicalBeanLoader
   19715: Test resource for HierarchicalBeanLoader
   19716: Added ControlDAO with PostgreSQL-specific override
   19717: Fix ALF-726 for PostgreSQL


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19720 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-04-01 01:23:31 +00:00
parent f27434f2c6
commit 56bf21e4c5
7 changed files with 341 additions and 0 deletions

View File

@@ -3,6 +3,32 @@
<beans> <beans>
<bean id="controlDAO" class="org.alfresco.util.bean.HierarchicalBeanLoader">
<property name="targetBeanName">
<value>controlDAO.#bean.dialect#</value>
</property>
<property name="targetClass">
<value>org.alfresco.repo.domain.control.ControlDAO</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="controlDAO.org.hibernate.dialect.Dialect"
class="org.alfresco.repo.domain.control.ibatis.ControlDAOImpl">
<property name="sqlMapClientTemplate" ref="avmSqlMapClientTemplate"/>
</bean>
<bean id="controlDAO.org.hibernate.dialect.PostgreSQLDialect"
class="org.alfresco.repo.domain.control.ibatis.ControlDAOImpl$PostgreSQL"
parent="controlDAO.org.hibernate.dialect.Dialect">
</bean>
<bean id="postDAO" class="org.alfresco.repo.domain.activities.ibatis.ActivityPostDAOImpl"> <bean id="postDAO" class="org.alfresco.repo.domain.activities.ibatis.ActivityPostDAOImpl">
<property name="sqlMapClient" ref="activitiesSqlMapClient"/> <property name="sqlMapClient" ref="activitiesSqlMapClient"/>
</bean> </bean>

View File

@@ -314,6 +314,7 @@ patch.thumbnailsAssocQName.description=Update the 'cm:thumbnails' association QN
patch.convertContentUrls.description=Converts pre-3.2 content URLs to use the alf_content_data table. The conversion work can also be done on a schedule; please contact Alfresco Support for further details. patch.convertContentUrls.description=Converts pre-3.2 content URLs to use the alf_content_data table. The conversion work can also be done on a schedule; please contact Alfresco Support for further details.
patch.convertContentUrls.bypassingPatch=Content URL conversion was NOT performed by this patch. Activate the scheduled job 'contentUrlConverterTrigger'. patch.convertContentUrls.bypassingPatch=Content URL conversion was NOT performed by this patch. Activate the scheduled job 'contentUrlConverterTrigger'.
patch.convertContentUrls.start=Content URL conversion progress: patch.convertContentUrls.start=Content URL conversion progress:
patch.convertContentUrls.error=Content URL conversion failed: {0}
patch.convertContentUrls.inProgress=Content URL conversion increment completed. Awaiting next scheduled call... patch.convertContentUrls.inProgress=Content URL conversion increment completed. Awaiting next scheduled call...
patch.convertContentUrls.done=Content URL conversion completed. patch.convertContentUrls.done=Content URL conversion completed.
patch.convertContentUrls.adm.start=\tProcessing ADM Content URLs. patch.convertContentUrls.adm.start=\tProcessing ADM Content URLs.

View File

@@ -2138,6 +2138,9 @@
<property name="patchDAO"> <property name="patchDAO">
<ref bean="patchDAO"/> <ref bean="patchDAO"/>
</property> </property>
<property name="controlDAO">
<ref bean="controlDAO"/>
</property>
<property name="contentDataDAO"> <property name="contentDataDAO">
<ref bean="contentDataDAO"/> <ref bean="contentDataDAO"/>
</property> </property>

View File

@@ -18,6 +18,7 @@
*/ */
package org.alfresco.repo.admin.patch.impl; package org.alfresco.repo.admin.patch.impl;
import java.sql.Savepoint;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -34,6 +35,7 @@ import org.alfresco.repo.batch.BatchProcessor.BatchProcessWorkerAdaptor;
import org.alfresco.repo.content.ContentStore; import org.alfresco.repo.content.ContentStore;
import org.alfresco.repo.content.ContentStore.ContentUrlHandler; import org.alfresco.repo.content.ContentStore.ContentUrlHandler;
import org.alfresco.repo.domain.contentdata.ContentDataDAO; import org.alfresco.repo.domain.contentdata.ContentDataDAO;
import org.alfresco.repo.domain.control.ControlDAO;
import org.alfresco.repo.domain.patch.PatchDAO; import org.alfresco.repo.domain.patch.PatchDAO;
import org.alfresco.repo.lock.JobLockService; import org.alfresco.repo.lock.JobLockService;
import org.alfresco.repo.lock.LockAcquisitionException; import org.alfresco.repo.lock.LockAcquisitionException;
@@ -106,6 +108,7 @@ public class ContentUrlConverterPatch extends AbstractPatch
private JobLockService jobLockService; private JobLockService jobLockService;
private NodeDaoService nodeDaoService; private NodeDaoService nodeDaoService;
private PatchDAO patchDAO; private PatchDAO patchDAO;
private ControlDAO controlDAO;
private ContentStore contentStore; private ContentStore contentStore;
private ContentDataDAO contentDataDAO; private ContentDataDAO contentDataDAO;
private int threadCount; private int threadCount;
@@ -156,6 +159,14 @@ public class ContentUrlConverterPatch extends AbstractPatch
this.patchDAO = patchDAO; this.patchDAO = patchDAO;
} }
/**
* Component that provides low-level database-specific control to support the patch
*/
public void setControlDAO(ControlDAO controlDAO)
{
this.controlDAO = controlDAO;
}
/** /**
* Set the store containing the content URLs to lift for potential cleaning. * Set the store containing the content URLs to lift for potential cleaning.
* *
@@ -307,6 +318,13 @@ public class ContentUrlConverterPatch extends AbstractPatch
completed = admCompleted && avmCompleted && urlLiftingCompleted; completed = admCompleted && avmCompleted && urlLiftingCompleted;
} }
catch (RuntimeException e)
{
logger.error(
I18NUtil.getMessage("patch.convertContentUrls.error", e.getMessage()),
e);
return I18NUtil.getMessage("patch.convertContentUrls.error", e.getMessage());
}
finally finally
{ {
jobLockService.releaseLock(lockToken, LOCK); jobLockService.releaseLock(lockToken, LOCK);
@@ -606,14 +624,20 @@ public class ContentUrlConverterPatch extends AbstractPatch
return; return;
} }
currentSize.setValue(currentSize.longValue() + reader.getSize()); currentSize.setValue(currentSize.longValue() + reader.getSize());
// Create a savepoint
String savepointName = new Long(System.nanoTime()).toString();
Savepoint savepoint = controlDAO.createSavepoint(savepointName);
try try
{ {
contentDataDAO.createContentUrlOrphaned(contentUrl); contentDataDAO.createContentUrlOrphaned(contentUrl);
controlDAO.releaseSavepoint(savepoint);
count.setValue(count.intValue()+1); count.setValue(count.intValue()+1);
} }
catch (DataIntegrityViolationException e) catch (DataIntegrityViolationException e)
{ {
// That's OK, the URL was already managed // That's OK, the URL was already managed
controlDAO.rollbackToSavepoint(savepoint);
} }
allCount++; allCount++;
if (allCount % batchSize == 0) if (allCount % batchSize == 0)

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2005-2009 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.domain.control;
import java.sql.Savepoint;
/**
* Abstract implementation for connection controlling DAO.
* <p>
* Provides any basic logic.
*
* @author Derek Hulley
* @since 3.2SP1
*/
public abstract class AbstractControlDAOImpl implements ControlDAO
{
/**
* @return Returns <tt>null</tt> by default i.e. not supported
*/
public Savepoint createSavepoint(String savepoint)
{
return null;
}
/** No-op */
public void rollbackToSavepoint(Savepoint savepoint)
{
}
/** No-op */
public void releaseSavepoint(Savepoint savepoint)
{
}
}

View File

@@ -0,0 +1,83 @@
/*
* Copyright (C) 2005-2009 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.domain.control;
import java.sql.Savepoint;
/**
* DAO services for database control statements. It is sometimes necessary to
* issue control statements on a database connection; these are not usually
* supported in the ANSI SQL standard.
*
* @author Derek Hulley
* @since 3.2SP1
*/
public interface ControlDAO
{
/**
* Begin batching prepared statements for later execution.
*
* @see #executeBatch()
*/
public void startBatch();
/**
* Execute statements that were queued for batching.
*
* @see #startBatch()
*/
public void executeBatch();
/**
* Create a "Save Point" in the current transaction, for later selective rollback.
* Creation should be accompanied by a matching {@link #rollbackToSavepoint(String)}
* or {@link #releaseSavepoint(String)} using the same name.
*
* @param savepoint the name of the save point
* @return Returns the handle to the savepoint or <tt>null</tt> if the
* implementation does not support it
*/
public Savepoint createSavepoint(String savepoint);
/**
* Roll back to a previously-created "Save Point", discarding any intervening
* changes to the current transaction.
*
* @param savepoint a previously-created savepoint
*
* @see #createSavepoint(String)
*/
public void rollbackToSavepoint(Savepoint savepoint);
/**
* Remove a previously-created "Save Point", writing any intervening updates
* into the current transaction.
*
* @param savepoint the name of the save point
*
* @see #createSavepoint(String)
*/
public void releaseSavepoint(Savepoint savepoint);
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (C) 2005-2009 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.domain.control.ibatis;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Savepoint;
import org.alfresco.repo.domain.control.AbstractControlDAOImpl;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.ibatis.sqlmap.client.SqlMapClient;
/**
* iBatis-specific, DB-agnostic implementation for connection controlling DAO.
*
* @author Derek Hulley
* @since 3.2SP1
*/
public class ControlDAOImpl extends AbstractControlDAOImpl
{
/**
* The iBatis-specific template for convenient statement execution.
*/
protected SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
public void startBatch()
{
/*
* The 'transactions' here are just iBatis internal markers and
* don't have any effect other than to let iBatis know that a batch
* is possible.
*/
SqlMapClient sqlMapClient = template.getSqlMapClient();
try
{
sqlMapClient.startTransaction();
sqlMapClient.startBatch();
}
catch (SQLException e)
{
throw new RuntimeException("Failed to start DAO batch.", e);
}
}
public void executeBatch()
{
/*
* The 'transactions' here are just iBatis internal markers and
* don't have any effect other than to let iBatis know that a batch
* is possible.
*/
SqlMapClient sqlMapClient = template.getSqlMapClient();
try
{
sqlMapClient.executeBatch();
sqlMapClient.commitTransaction();
sqlMapClient.endTransaction();
}
catch (SQLException e)
{
throw new RuntimeException("Failed to start DAO batch.", e);
}
}
/**
* PostgreSQL-specific implementation for control DAO.
*
* @author Derek Hulley
* @since 3.2SP1
*/
public static class PostgreSQL extends ControlDAOImpl
{
/**
* Calls through to the {@link Connection#setSavepoint(String) current connection}.
*/
@Override
public Savepoint createSavepoint(final String savepoint)
{
try
{
Connection connection = DataSourceUtils.getConnection(template.getDataSource());
return connection.setSavepoint(savepoint);
}
catch (SQLException e)
{
throw new RuntimeException("Failed to create SAVEPOINT: " + savepoint, e);
}
}
/**
* Calls through to the {@link Connection#setSavepoint(String) current connection}.
*/
@Override
public void rollbackToSavepoint(Savepoint savepoint)
{
try
{
Connection connection = DataSourceUtils.getConnection(template.getDataSource());
connection.rollback(savepoint);
}
catch (SQLException e)
{
throw new RuntimeException("Failed to create SAVEPOINT: " + savepoint, e);
}
}
@Override
public void releaseSavepoint(Savepoint savepoint)
{
try
{
Connection connection = DataSourceUtils.getConnection(template.getDataSource());
connection.releaseSavepoint(savepoint);
}
catch (SQLException e)
{
throw new RuntimeException("Failed to create SAVEPOINT: " + savepoint, e);
}
}
}
}