Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)

103438: Working towards a fix for ACE-3948: BM-0004: Factor out select on alf_content_url table during file creation
    - Complement the 'getOrCreate' EntityCache calls with 'createOrGet'
    - Cleanup of ContentDataDAOImpl code before further changes: tabs, @Override, unused code, etc


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@103622 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-05-02 07:44:01 +00:00
parent 93ba7015d1
commit 2758df8308
3 changed files with 143 additions and 54 deletions

View File

@@ -19,12 +19,14 @@
package org.alfresco.repo.cache.lookup;
import java.io.Serializable;
import java.sql.Savepoint;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.domain.control.ControlDAO;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.util.Pair;
import org.springframework.extensions.surf.util.ParameterCheck;
import org.springframework.dao.ConcurrencyFailureException;
import org.springframework.extensions.surf.util.ParameterCheck;
/**
* A cache for two-way lookups of database entities. These are characterized by having a unique
@@ -412,6 +414,48 @@ public class EntityLookupCache<K extends Serializable, V extends Object, VK exte
return entityPair;
}
/**
* Attempt to create the entity and, failing that, look it up.<br/>
* This method takes the opposite approach to {@link #getOrCreateByValue(Object)}, which assumes the entity's
* existence: in this case the entity is assumed to NOT exist.
* The {@link EntityLookupCallbackDAO#createValue(Object)} and {@link EntityLookupCallbackDAO#findByValue(Object)}
* will be used if necessary.<br/>
* <p/>
* Use this method when the data involved is seldom reused.
*
* @param value The entity value (<tt>null</tt> is allowed)
* @param controlDAO an essential DAO required in order to ensure a transactionally-safe attempt at data creation
* @return Returns the key-value pair (new or existing and never <tt>null</tt>)
*/
public Pair<K, V> createOrGetByValue(V value, ControlDAO controlDAO)
{
if (controlDAO == null)
{
throw new IllegalArgumentException("The ControlDAO is required in order to perform a safe attempted insert.");
}
Savepoint savepoint = controlDAO.createSavepoint("EntityLookupCache.createOrGetByValue");
try
{
Pair<K, V> entityPair = entityLookup.createValue(value);
controlDAO.releaseSavepoint(savepoint);
// Cache it
if (cache != null)
{
cache.put(
new CacheRegionKey(cacheRegion, entityPair.getFirst()),
(entityPair.getSecond() == null ? VALUE_NULL : entityPair.getSecond()));
}
// It's been created and cached
return entityPair;
}
catch (Exception e)
{
controlDAO.rollbackToSavepoint(savepoint);
// Fall through to the usual way, which should find it if the failure cause was a duplicate key
return getOrCreateByValue(value);
}
}
/**
* Find the entity associated with the given value and create it if it doesn't exist.
* The {@link EntityLookupCallbackDAO#findByValue(Object)} and {@link EntityLookupCallbackDAO#createValue(Object)}